Changeset 6689 for trunk/src


Ignore:
Timestamp:
Sep 9, 2001, 10:45:20 PM (24 years ago)
Author:
sandervl
Message:

wine typelib update

Location:
trunk/src/oleaut32
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/oleaut32/connpt.c

    r6648 r6689  
    1 /* $Id: connpt.c,v 1.2 2001-09-05 13:18:59 bird Exp $ */
    21/*
    32 * Implementation of a generic ConnectionPoint object.
  • trunk/src/oleaut32/dispatch.c

    r6648 r6689  
    1 /* $Id: dispatch.c,v 1.2 2001-09-05 13:19:00 bird Exp $ */
    21/**
    32 * Dispatch API functions
  • trunk/src/oleaut32/initterm.cpp

    r6648 r6689  
    1 /* $Id: initterm.cpp,v 1.10 2001-09-05 13:19:00 bird Exp $ */
    21/*
    32 * DLL entry point
  • trunk/src/oleaut32/ole2disp.c

    r6648 r6689  
    1 /* $Id: ole2disp.c,v 1.2 2001-09-05 13:19:00 bird Exp $ */
    21/*
    32 *  OLE2DISP library
  • trunk/src/oleaut32/oleaut.c

    r6648 r6689  
    1 /* $Id: oleaut.c,v 1.2 2001-09-05 13:19:00 bird Exp $ */
    21/*
    32 *  OLEAUT32
  • trunk/src/oleaut32/olefont.c

    r6648 r6689  
    1 /* $Id: olefont.c,v 1.3 2001-09-05 13:19:00 bird Exp $ */
    21/*
    32 * OLE Font encapsulation implementation
  • trunk/src/oleaut32/olepicture.c

    r6648 r6689  
    1 /* $Id: olepicture.c,v 1.5 2001-09-05 13:19:01 bird Exp $ */
    21/*
    32 * OLE Picture object
  • trunk/src/oleaut32/parsedt.c

    r6648 r6689  
    1 /* $Id: parsedt.c,v 1.2 2001-09-05 13:19:01 bird Exp $ */
    21/*
    32PostgreSQL Data Base Management System (formerly known as Postgres, then
  • trunk/src/oleaut32/safearray.c

    r6648 r6689  
    1 /* $Id: safearray.c,v 1.3 2001-09-05 13:19:01 bird Exp $ */
    21/*************************************************************************
    32 * OLE Automation
  • trunk/src/oleaut32/typelib.c

    r6648 r6689  
    1 /* $Id: typelib.c,v 1.6 2001-09-05 13:19:01 bird Exp $ */
    21/*
    3  *  TYPELIB
    4  *
    5  *  Copyright 1997  Marcus Meissner
    6  *            1999  Rein Klazes
    7  *            2000  Francois Jacques
     2 *      TYPELIB
     3 *
     4 *      Copyright 1997  Marcus Meissner
     5 *                    1999  Rein Klazes
     6 *                    2000  Francois Jacques
     7 *                    2001  Huw D M Davies for CodeWeavers
     8 *                   
    89 * --------------------------------------------------------------------------------------
    910 * Known problems (2000, Francois Jacques)
    1011 *
    1112 * - Tested using OLEVIEW (Platform SDK tool) only.
    12  *
    13  * - dual interface dispinterfaces. vtable-interface ITypeInfo instances are
    14  *   creating by doing a straight copy of the dispinterface instance and just changing
     13 *   
     14 * - dual interface dispinterfaces. vtable-interface ITypeInfo instances are 
     15 *   creating by doing a straight copy of the dispinterface instance and just changing 
    1516 *   its typekind. Pointed structures aren't copied - only the address of the pointers.
    1617 *   So when you release the dispinterface, you delete the vtable-interface structures
    1718 *   as well... fortunately, clean up of structures is not implemented.
    18  *
     19 * 
    1920 * - locale stuff is partially implemented but hasn't been tested.
    2021 *
    21  * - imported typelib should be stored together in a linked list instead of having
    22  *   independant TLBImpLib structures in each ITypeInfo. This way, imported libraries
    23  *   are just imported once (major optimization)
    24  *
    25  * - typelib file is still read it's in entirety, but it is released now.
    26  * - some garbage is read from function names on some very rare occasion
     22 * - typelib file is still read in its entirety, but it is released now.
     23 * - some garbage is read from function names on some very rare occasions.
    2724 *
    2825 * --------------------------------------------------------------------------------------
    2926 *  Known problems left from previous implementation (1999, Rein Klazes) :
    3027 *
    31  * -. Only one format of typelibs is supported
    3228 * -. Data structures are straightforward, but slow for look-ups.
    3329 * -. (related) nothing is hashed
     
    4036 * -. some methods just return pointers to internal data structures, this is
    4137 *      partly laziness, partly I want to check how windows does it.
    42  *
     38 * 
    4339 */
    4440#ifdef __WIN32OS2__
     
    4642#define WINE_LARGE_INTEGER
    4743#include "oleaut32.h"
    48 
    4944#endif
    5045
     
    8580#ifndef __WIN32OS2__
    8681/****************************************************************************
    87  *      QueryPathOfRegTypeLib   [TYPELIB.14]
     82 *              QueryPathOfRegTypeLib   [TYPELIB.14]
    8883 *
    8984 * the path is "Classes\Typelib\<guid>\<major>.<minor>\<lcid>\win16\"
    9085 * RETURNS
    91  *  path of typelib
     86 *      path of typelib
    9287 */
    9388HRESULT WINAPI
    94 QueryPathOfRegTypeLib16(
    95     REFGUID guid,   /* [in] referenced guid */
    96     WORD wMaj,  /* [in] major version */
    97     WORD wMin,  /* [in] minor version */
    98     LCID lcid,  /* [in] locale id */
    99     LPBSTR16 path   /* [out] path of typelib */
     89QueryPathOfRegTypeLib16(       
     90        REFGUID guid,   /* [in] referenced guid */
     91        WORD wMaj,      /* [in] major version */
     92        WORD wMin,      /* [in] minor version */
     93        LCID lcid,      /* [in] locale id */
     94        LPBSTR16 path   /* [out] path of typelib */
    10095) {
    101     char    xguid[80];
    102     char    typelibkey[100],pathname[260];
    103     DWORD   plen;
    104 
    105         TRACE("\n");
    106 
    107     if (HIWORD(guid)) {
     96        char    xguid[80];
     97        char    typelibkey[100],pathname[260];
     98        DWORD   plen;
     99
     100        TRACE("\n");
     101
     102        if (HIWORD(guid)) {
    108103            sprintf( typelibkey, "SOFTWARE\\Classes\\Typelib\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\%d.%d\\%lx\\win16",
    109104                     guid->Data1, guid->Data2, guid->Data3,
     
    111106                     guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7],
    112107                     wMaj,wMin,lcid);
    113     } else {
    114         sprintf(xguid,"<guid 0x%08lx>",(DWORD)guid);
    115         FIXME("(%s,%d,%d,0x%04lx,%p),can't handle non-string guids.\n",xguid,wMaj,wMin,(DWORD)lcid,path);
    116         return E_FAIL;
    117     }
    118     plen = sizeof(pathname);
    119     if (RegQueryValueA(HKEY_LOCAL_MACHINE,typelibkey,pathname,&plen)) {
    120         /* try again without lang specific id */
    121         if (SUBLANGID(lcid))
    122             return QueryPathOfRegTypeLib16(guid,wMaj,wMin,PRIMARYLANGID(lcid),path);
    123         FIXME("key %s not found\n",typelibkey);
    124         return E_FAIL;
    125     }
    126     *path = SysAllocString16(pathname);
    127     return S_OK;
     108        } else {
     109                sprintf(xguid,"<guid 0x%08lx>",(DWORD)guid);
     110                FIXME("(%s,%d,%d,0x%04lx,%p),can't handle non-string guids.\n",xguid,wMaj,wMin,(DWORD)lcid,path);
     111                return E_FAIL;
     112        }
     113        plen = sizeof(pathname);
     114        if (RegQueryValueA(HKEY_LOCAL_MACHINE,typelibkey,pathname,&plen)) {
     115                /* try again without lang specific id */
     116                if (SUBLANGID(lcid))
     117                        return QueryPathOfRegTypeLib16(guid,wMaj,wMin,PRIMARYLANGID(lcid),path);
     118                FIXME("key %s not found\n",typelibkey);
     119                return E_FAIL;
     120        }
     121        *path = SysAllocString16(pathname);
     122        return S_OK;
    128123}
    129124#endif
    130 
     125 
    131126/****************************************************************************
    132  *      QueryPathOfRegTypeLib   [OLEAUT32.164]
     127 *              QueryPathOfRegTypeLib   [OLEAUT32.164]
    133128 * RETURNS
    134  *  path of typelib
     129 *      path of typelib
    135130 */
    136131HRESULT WINAPI
    137 QueryPathOfRegTypeLib(
    138     REFGUID guid,   /* [in] referenced guid */
    139     WORD wMaj,  /* [in] major version */
    140     WORD wMin,  /* [in] minor version */
    141     LCID lcid,  /* [in] locale id */
    142     LPBSTR path )   /* [out] path of typelib */
     132QueryPathOfRegTypeLib( 
     133        REFGUID guid,   /* [in] referenced guid */
     134        WORD wMaj,      /* [in] major version */
     135        WORD wMin,      /* [in] minor version */
     136        LCID lcid,      /* [in] locale id */
     137        LPBSTR path )   /* [out] path of typelib */
    143138{
    144139    /* don't need to ZeroMemory those arrays since sprintf and RegQueryValue add
     
    157152    char    szPath[dwPathLen];
    158153#endif
     154
    159155    if ( !HIWORD(guid) )
    160156    {
     
    172168            "SOFTWARE\\Classes\\Typelib\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\%d.%d\\%lx\\win32",
    173169            guid->Data1,    guid->Data2,    guid->Data3,
    174             guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
     170            guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3], 
    175171            guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7],
    176172            wMaj,
     
    212208        }
    213209    }
    214 
     210       
    215211    if (hr != S_OK)
    216         TRACE_(typelib)("%s not found\n", szTypeLibKey);
    217 
     212                TRACE_(typelib)("%s not found\n", szTypeLibKey);
     213       
    218214    return hr;
    219215}
     
    227223 */
    228224HRESULT WINAPI CreateTypeLib(
    229     SYSKIND syskind, LPCOLESTR szFile, ICreateTypeLib** ppctlib
     225        SYSKIND syskind, LPCOLESTR szFile, ICreateTypeLib** ppctlib
    230226) {
    231227    FIXME("(%d,%s,%p), stub!\n",syskind,debugstr_w(szFile),ppctlib);
     
    257253
    258254/******************************************************************************
    259  *      LoadTypeLib [OLEAUT32.161]
     255 *              LoadTypeLib     [OLEAUT32.161]
    260256 * Loads and registers a type library
    261257 * NOTES
     
    278274
    279275/******************************************************************************
    280  *      LoadTypeLibEx   [OLEAUT32.183]
     276 *              LoadTypeLibEx   [OLEAUT32.183]
    281277 * Loads and optionally registers a type library
    282278 *
     
    290286    ITypeLib **pptLib) /* [out] Pointer to pointer to loaded type library */
    291287{
    292     LPSTR p;
     288    LPSTR p=NULL;
     289    WCHAR szPath[MAX_PATH+1];
    293290    HRESULT res;
    294291    TRACE("(%s,%d,%p)\n",debugstr_w(szFile), regkind, pptLib);
    295 
    296     p=HEAP_strdupWtoA(GetProcessHeap(),0,szFile);
    297 
    298     res= TLB_ReadTypeLib(p, (ITypeLib2**)pptLib);
    299 
     292   
     293    if(!SearchPathW(NULL,szFile,NULL,sizeof(szPath)/sizeof(WCHAR),szPath,NULL))
     294      res = TYPE_E_CANTLOADLIBRARY;
     295    else {
     296      p=HEAP_strdupWtoA(GetProcessHeap(),0,szPath);
     297      res= TLB_ReadTypeLib(p, (ITypeLib2**)pptLib);
     298    }
    300299    if (SUCCEEDED(res))
    301300        switch(regkind)
     
    303302            case REGKIND_DEFAULT:
    304303                /* FIXME: is this correct? */
    305                 if (!p || !p[0] || (p[0] != '\\' && p[0] != '/' && p[1] != ':'))
     304                if (!szFile || !szFile[0] ||
     305                   (szFile[0] != '\\' && szFile[0] != '/' && szFile[1] != ':'))
    306306                    break;
    307307                /* else fall-through */
     
    318318        }
    319319
    320     HeapFree(GetProcessHeap(),0,p);
     320    if(p) HeapFree(GetProcessHeap(),0,p);
    321321    TRACE(" returns %08lx\n",res);
    322322    return res;
     
    324324
    325325/******************************************************************************
    326  *      LoadRegTypeLib  [OLEAUT32.162]
    327  */
    328 HRESULT WINAPI LoadRegTypeLib(
    329     REFGUID rguid,      /* [in] referenced guid */
    330     WORD wVerMajor,     /* [in] major version */
    331     WORD wVerMinor,     /* [in] minor version */
    332     LCID lcid,      /* [in] locale id */
    333     ITypeLib **ppTLib)  /* [out] path of typelib */
     326 *              LoadRegTypeLib  [OLEAUT32.162]
     327 */
     328HRESULT WINAPI LoadRegTypeLib( 
     329        REFGUID rguid,          /* [in] referenced guid */
     330        WORD wVerMajor,         /* [in] major version */
     331        WORD wVerMinor,         /* [in] minor version */
     332        LCID lcid,              /* [in] locale id */
     333        ITypeLib **ppTLib)      /* [out] path of typelib */
    334334{
    335335    BSTR bstr=NULL;
     
    345345
    346346    return res;
    347 }
     347}       
    348348
    349349
    350350/******************************************************************************
    351  *      RegisterTypeLib [OLEAUT32.163]
    352  * Adds information about a type library to the System Registry
     351 *              RegisterTypeLib [OLEAUT32.163]
     352 * Adds information about a type library to the System Registry           
    353353 * NOTES
    354354 *    Docs: ITypeLib FAR * ptlib
     
    364364     OLECHAR * szFullPath, /* [in] full Path of the library*/
    365365     OLECHAR * szHelpDir)  /* [in] dir to the helpfile for the library,
    366                             may be NULL*/
     366                                                        may be NULL*/
    367367{
    368368    HRESULT res;
     
    445445
    446446/******************************************************************************
    447  *  UnRegisterTypeLib   [OLEAUT32.186]
    448  * Removes information about a type library from the System Registry
     447 *      UnRegisterTypeLib       [OLEAUT32.186]
     448 * Removes information about a type library from the System Registry           
    449449 * NOTES
    450450 *
     
    454454 */
    455455HRESULT WINAPI UnRegisterTypeLib(
    456     REFGUID libid,  /* [in] Guid of the library */
    457     WORD wVerMajor, /* [in] major version */
    458     WORD wVerMinor, /* [in] minor version */
    459     LCID lcid,  /* [in] locale id */
    460     SYSKIND syskind)
    461 {
     456    REFGUID libid,      /* [in] Guid of the library */
     457        WORD wVerMajor, /* [in] major version */
     458        WORD wVerMinor, /* [in] minor version */
     459        LCID lcid,      /* [in] locale id */
     460        SYSKIND syskind)
     461{   
    462462    TRACE("(IID: %s): stub\n",debugstr_guid(libid));
    463     return S_OK;    /* FIXME: pretend everything is OK */
     463    return S_OK;        /* FIXME: pretend everything is OK */
    464464}
    465465
    466466#ifndef __WIN32OS2__
    467467/****************************************************************************
    468  *  OaBuildVersion              (TYPELIB.15)
     468 *      OaBuildVersion                          (TYPELIB.15)
    469469 *
    470470 * known TYPELIB.DLL versions:
    471471 *
    472  * OLE 2.01 no OaBuildVersion() avail   1993    --  ---
    473  * OLE 2.02             1993-94 02     3002
    474  * OLE 2.03                 23  730
    475  * OLE 2.03                 03     3025
    476  * OLE 2.03 W98 SE orig. file !!    1993-95 10     3024
    477  * OLE 2.1   NT             1993-95 ??  ???
    478  * OLE 2.3.1 W95                23  700
    479  * OLE2 4.0  NT4SP6         1993-98 40     4277
     472 * OLE 2.01 no OaBuildVersion() avail   1993    --      ---
     473 * OLE 2.02                             1993-94 02     3002
     474 * OLE 2.03                                     23      730
     475 * OLE 2.03                                     03     3025
     476 * OLE 2.03 W98 SE orig. file !!        1993-95 10     3024
     477 * OLE 2.1   NT                         1993-95 ??      ???
     478 * OLE 2.3.1 W95                                23      700
     479 * OLE2 4.0  NT4SP6                     1993-98 40     4277
    480480 */
    481481DWORD WINAPI OaBuildVersion16(void)
     
    489489    {
    490490    case 0x80000a03:  /* WIN31 */
    491         return MAKELONG(3027, 3); /* WfW 3.11 */
     491                return MAKELONG(3027, 3); /* WfW 3.11 */
    492492    case 0x80000004:  /* WIN95 */
    493         return MAKELONG(700, 23); /* Win95A */
     493                return MAKELONG(700, 23); /* Win95A */
    494494    case 0x80000a04:  /* WIN98 */
    495         return MAKELONG(3024, 10); /* W98 SE */
     495                return MAKELONG(3024, 10); /* W98 SE */
    496496    case 0x00000004:  /* NT4 */
    497         return MAKELONG(4277, 40); /* NT4 SP6 */
     497                return MAKELONG(4277, 40); /* NT4 SP6 */
    498498    default:
    499     FIXME("Version value not known yet. Please investigate it!\n");
    500         return 0;
     499        FIXME("Version value not known yet. Please investigate it!\n");
     500                return 0;
    501501    }
    502502}
    503503#endif
    504 
    505504/* for better debugging info leave the static out for the time being */
    506505#define static
     
    508507/*======================= ITypeLib implementation =======================*/
    509508
    510 typedef struct tagTLBCustData
     509typedef struct tagTLBCustData 
    511510{
    512511    GUID guid;
     
    518517typedef struct tagTLBImpLib
    519518{
    520     int offset;                 /* offset in the file */
     519    int offset;                 /* offset in the file (MSFT)
     520                                   offset in nametable (SLTG)
     521                                   just used to identify library while reading
     522                                   data from file */
    521523    GUID guid;                  /* libid */
    522     BSTR name;                  /* name; */
     524    BSTR name;                  /* name */
    523525
    524526    LCID lcid;                  /* lcid of imported typelib */
     
    527529    WORD wVersionMinor;         /* minor version number */
    528530
    529     struct tagITypeLibImpl *pImpTypeLib; /* pointer to loaded typelib */
     531    struct tagITypeLibImpl *pImpTypeLib; /* pointer to loaded typelib, or
     532                                            NULL if not yet loaded */
    530533    struct tagTLBImpLib * next;
    531534} TLBImpLib;
     
    537540    UINT ref;
    538541    TLIBATTR LibAttr;            /* guid,lcid,syskind,version,flags */
    539 
     542   
    540543    /* strings can be stored in tlb as multibyte strings BUT they are *always*
    541544     * exported to the application as a UNICODE string.
     
    549552    struct tagITypeInfoImpl *pTypeInfo;   /* linked list of type info data */
    550553    int ctCustData;             /* number of items in cust data list */
    551     TLBCustData * pCustData;    /* linked list to cust data; */
     554    TLBCustData * pCustData;    /* linked list to cust data */
    552555    TLBImpLib   * pImpLibs;     /* linked list to all imported typelibs */
    553     TYPEDESC * pTypeDesc;       /* array of TypeDescriptions found in the libary */
     556    TYPEDESC * pTypeDesc;       /* array of TypeDescriptions found in the
     557                                   libary. Only used while read MSFT
     558                                   typelibs */
    554559} ITypeLibImpl;
    555560
     
    557562
    558563/* ITypeLib methods */
    559 static ITypeLib2* ITypeLib2_Constructor(LPVOID pLib, DWORD dwTLBLength);
     564static ITypeLib2* ITypeLib2_Constructor_MSFT(LPVOID pLib, DWORD dwTLBLength);
     565static ITypeLib2* ITypeLib2_Constructor_SLTG(LPVOID pLib, DWORD dwTLBLength);
    560566
    561567/*======================= ITypeInfo implementation =======================*/
    562568
    563 /* data for refernced types in a coclass, or an inherited interface */
     569/* data for refernced types */
    564570typedef struct tagTLBRefType
    565571{
     572    INT index;              /* Type index for internal ref or for external ref
     573                               it the format is SLTG.  -2 indicates to
     574                               use guid */
     575
    566576    GUID guid;              /* guid of the referenced type */
    567                             /* (important if its a imported type) */
    568     HREFTYPE reference;
    569     int flags;
    570     int ctCustData;
    571     TLBCustData * pCustData;/* linked list to custom data; */
    572     TLBImpLib *pImpTLInfo;
     577                            /* if index == TLB_REF_USE_GUID */
     578
     579    HREFTYPE reference;     /* The href of this ref */
     580    TLBImpLib *pImpTLInfo;  /* If ref is external ptr to library data
     581                               TLB_REF_INTERNAL for internal refs
     582                               TLB_REF_NOT_FOUND for broken refs */
     583 
    573584    struct tagTLBRefType * next;
    574585} TLBRefType;
    575586
     587#define TLB_REF_USE_GUID -2
     588
     589#define TLB_REF_INTERNAL (void*)-2
     590#define TLB_REF_NOT_FOUND (void*)-1
     591
    576592/* internal Parameter data */
    577593typedef struct tagTLBParDesc
     
    579595    BSTR Name;
    580596    int ctCustData;
    581     TLBCustData * pCustData;        /* linked list to cust data; */
    582     TLBRefType * pRefType;          /* linked list to referenced types */
     597    TLBCustData * pCustData;        /* linked list to cust data */
    583598} TLBParDesc;
    584599
     
    588603    FUNCDESC funcdesc;      /* lots of info on the function and its attributes. */
    589604    BSTR Name;             /* the name of this function */
    590     TLBParDesc *pParamDesc; /* array with name and custom data */
     605    TLBParDesc *pParamDesc; /* array with param names and custom data */
    591606    int helpcontext;
    592607    int HelpStringContext;
     
    595610    int ctCustData;
    596611    TLBCustData * pCustData;        /* linked list to cust data; */
    597     struct tagTLBFuncDesc * next;
     612    struct tagTLBFuncDesc * next; 
    598613} TLBFuncDesc;
    599614
     
    608623    int ctCustData;
    609624    TLBCustData * pCustData;/* linked list to cust data; */
    610     struct tagTLBVarDesc * next;
     625    struct tagTLBVarDesc * next; 
    611626} TLBVarDesc;
     627
     628/* internal implemented interface data */
     629typedef struct tagTLBImplType
     630{
     631    HREFTYPE hRef;          /* hRef of interface */
     632    int implflags;          /* IMPLFLAG_*s */
     633    int ctCustData;
     634    TLBCustData * pCustData;/* linked list to custom data; */
     635    struct tagTLBImplType *next;
     636} TLBImplType;
    612637
    613638/* internal TypeInfo data */
     
    619644    ITypeLibImpl * pTypeLib;        /* back pointer to typelib */
    620645    int index;                  /* index in this typelib; */
    621     /* type libs seem to store the doc strings in ascii
     646    /* type libs seem to store the doc strings in ascii 
    622647     * so why should we do it in unicode?
    623648     */
     
    634659
    635660    /* Implemented Interfaces  */
    636     TLBRefType * impltypelist;
     661    TLBImplType * impltypelist;
     662
     663    TLBRefType * reflist;
    637664    int ctCustData;
    638665    TLBCustData * pCustData;        /* linked list to cust data; */
     
    646673typedef struct tagTLBContext
    647674{
    648     unsigned int oStart;  /* start of TLB in file */
    649     unsigned int pos;     /* current pos */
    650     unsigned int length;  /* total length */
    651     void *mapping;        /* memory mapping */
    652     TLBSegDir * pTblDir;
    653     ITypeLibImpl* pLibInfo;
     675        unsigned int oStart;  /* start of TLB in file */
     676        unsigned int pos;     /* current pos */
     677        unsigned int length;  /* total length */
     678        void *mapping;        /* memory mapping */
     679        MSFT_SegDir * pTblDir;
     680        ITypeLibImpl* pLibInfo;
    654681} TLBContext;
    655682
    656683
    657 static void TLB_DoRefType(TLBContext *pcx, int offset, TLBRefType ** pprtd);
     684static void MSFT_DoRefType(TLBContext *pcx, ITypeInfoImpl *pTI, int offset);
    658685
    659686//#define TYPELIBDEBUG
     
    680707    case VT_DISPATCH: sprintf(szVarType, "VT_DISPATCH"); break;
    681708    case VT_ARRAY: sprintf(szVarType, "VT_ARRAY"); break;
    682     case VT_I1: sprintf(szVarType, "VT_I2"); break;
     709    case VT_I1: sprintf(szVarType, "VT_I1"); break;
    683710    case VT_UI2: sprintf(szVarType, "VT_UI2"); break;
    684711    case VT_UI4: sprintf(szVarType, "VT_UI4"); break;
    685712    case VT_INT: sprintf(szVarType, "VT_INT"); break;
    686713    case VT_UINT: sprintf(szVarType, "VT_UINT"); break;
     714    case VT_USERDEFINED: sprintf(szVarType, "VT_USERDEFINED\n"); break;
    687715    default: sprintf(szVarType, "unknown");break;
    688716    }
    689717}
     718
     719static void dump_TypeDesc(TYPEDESC *pTD,char *szVarType) {
     720    switch(pTD->vt) {
     721    case VT_UI1: sprintf(szVarType, "VT_UI1"); break;
     722    case VT_I2: sprintf(szVarType, "VT_I2"); break;
     723    case VT_I4: sprintf(szVarType, "VT_I4"); break;
     724    case VT_R4: sprintf(szVarType, "VT_R4"); break;
     725    case VT_R8: sprintf(szVarType, "VT_R8"); break;
     726    case VT_BOOL: sprintf(szVarType, "VT_BOOL"); break;
     727    case VT_ERROR: sprintf(szVarType, "VT_ERROR"); break;
     728    case VT_CY: sprintf(szVarType, "VT_CY"); break;
     729    case VT_DATE: sprintf(szVarType, "VT_DATE"); break;
     730    case VT_BSTR: sprintf(szVarType, "VT_BSTR"); break;
     731    case VT_BYREF: case VT_UNKNOWN: sprintf(szVarType, "VT_BYREF"); break;
     732    case VT_DISPATCH: sprintf(szVarType, "VT_DISPATCH"); break;
     733    case VT_ARRAY: sprintf(szVarType, "VT_ARRAY"); break;
     734    case VT_I1: sprintf(szVarType, "VT_I1"); break;
     735    case VT_UI2: sprintf(szVarType, "VT_UI2"); break;
     736    case VT_UI4: sprintf(szVarType, "VT_UI4"); break;
     737    case VT_INT: sprintf(szVarType, "VT_INT"); break;
     738    case VT_UINT: sprintf(szVarType, "VT_UINT"); break;
     739    case VT_VARIANT: sprintf(szVarType, "VT_VARIANT"); break;
     740    case VT_VOID: sprintf(szVarType, "VT_VOID"); break;
     741    case VT_USERDEFINED: sprintf(szVarType, "VT_USERDEFINED ref = %lx",
     742                                 pTD->u.hreftype); break;
     743    case VT_PTR: sprintf(szVarType, "ptr to ");
     744      dump_TypeDesc(pTD->u.lptdesc, szVarType + 7);
     745      break;
     746    case VT_SAFEARRAY: sprintf(szVarType, "safearray of ");
     747      dump_TypeDesc(pTD->u.lptdesc, szVarType + 13);
     748      break;
     749    case VT_CARRAY: sprintf(szVarType, "%d dim array of ",
     750                            pTD->u.lpadesc->cDims); /* FIXME print out sizes */
     751      dump_TypeDesc(&pTD->u.lpadesc->tdescElem, szVarType + strlen(szVarType));
     752      break;
     753
     754    default: sprintf(szVarType, "unknown");break;
     755    }
     756}
     757
    690758static void dump_ELEMDESC(ELEMDESC *edesc) {
    691759  char buf[200];
    692   dump_VarType(edesc->tdesc.vt,buf);
     760  dump_TypeDesc(&edesc->tdesc,buf);
    693761  MESSAGE("\t\ttdesc.vartype %d (%s)\n",edesc->tdesc.vt,buf);
    694762  MESSAGE("\t\tu.parmadesc.flags %x\n",edesc->u.paramdesc.wParamFlags);
     
    697765static void dump_FUNCDESC(FUNCDESC *funcdesc) {
    698766  int i;
    699   MESSAGE("memid is %d\n",(int)funcdesc->memid);
    700   for (i=0;i<funcdesc->cParams;i++)
    701       MESSAGE("Param %d:\n",i);dump_ELEMDESC(funcdesc->lprgelemdescParam+i);
     767  MESSAGE("memid is %08lx\n",funcdesc->memid);
     768  for (i=0;i<funcdesc->cParams;i++) {
     769      MESSAGE("Param %d:\n",i);
     770      dump_ELEMDESC(funcdesc->lprgelemdescParam+i);
     771  }
    702772  MESSAGE("\tfunckind: %d (",funcdesc->funckind);
    703773  switch (funcdesc->funckind) {
     
    745815static void dump_TLBFuncDesc(TLBFuncDesc * pfd)
    746816{
    747     while (pfd)
    748     {
    749       dump_TLBFuncDescOne(pfd);
    750       pfd = pfd->next;
    751     };
     817        while (pfd)
     818        {
     819          dump_TLBFuncDescOne(pfd);
     820          pfd = pfd->next;
     821        };
    752822}
    753823static void dump_TLBVarDesc(TLBVarDesc * pvd)
    754824{
    755     while (pvd)
    756     {
    757       TRACE_(typelib)("%s\n", debugstr_w(pvd->Name));
    758       pvd = pvd->next;
    759     };
    760 }
     825        while (pvd)
     826        {
     827          TRACE_(typelib)("%s\n", debugstr_w(pvd->Name));
     828          pvd = pvd->next;
     829        };
     830}
     831
     832static void dump_TLBImpLib(TLBImpLib *import)
     833{
     834    TRACE_(typelib)("%s %s\n", debugstr_guid(&(import->guid)),
     835                    debugstr_w(import->name));
     836    TRACE_(typelib)("v%d.%d lcid=%lx offset=%x\n", import->wVersionMajor,
     837                    import->wVersionMinor, import->lcid, import->offset);
     838}
     839
    761840static void dump_TLBRefType(TLBRefType * prt)
    762841{
    763     while (prt)
    764     {
    765       TRACE_(typelib)("%s\n", debugstr_guid(&(prt->guid)));
    766       TRACE_(typelib)("  href:0x%08lx\n", prt->reference);
    767       prt = prt->next;
    768     };
    769 }
    770 
     842        while (prt)
     843        {
     844          TRACE_(typelib)("href:0x%08lx\n", prt->reference);
     845          if(prt->index == -1)
     846            TRACE_(typelib)("%s\n", debugstr_guid(&(prt->guid)));
     847          else
     848            TRACE_(typelib)("type no: %d\n", prt->index);
     849
     850          if(prt->pImpTLInfo != TLB_REF_INTERNAL &&
     851             prt->pImpTLInfo != TLB_REF_NOT_FOUND) {
     852              TRACE_(typelib)("in lib\n");
     853              dump_TLBImpLib(prt->pImpTLInfo);
     854          }
     855          prt = prt->next;
     856        };
     857}
     858
     859static void dump_TLBImplType(TLBImplType * impl)
     860{
     861    while (impl) {
     862        TRACE_(typelib)(
     863                "implementing/inheriting interface hRef = %lx implflags %x\n",
     864                impl->hRef, impl->implflags);
     865        impl = impl->next;
     866    }
     867}
     868     
    771869static void dump_Variant(VARIANT * pvar)
    772870{
    773871    char szVarType[15];
    774 
     872   
    775873    TRACE("(%p)\n", pvar);
    776 
     874 
    777875    if (!pvar)  return;
    778 
     876 
    779877    ZeroMemory(szVarType, sizeof(szVarType));
    780 
     878               
    781879    /* FIXME : we could have better trace here, depending on the VARTYPE
    782880     * of the variant
     
    785883
    786884    TRACE("VARTYPE: %s\n", szVarType);
    787 
     885   
    788886    switch (V_VT(pvar))
    789887    {
     
    791889            TRACE("%3.3e\n", V_UNION(pvar, fltVal));
    792890            break;
    793 
     891           
    794892        case VT_R8:
    795893            TRACE("%3.3e\n", V_UNION(pvar, dblVal));
    796894            break;
    797 
     895           
    798896        default:
    799897            TRACE("%ld\n", V_UNION(pvar, lVal));
    800898            break;
    801     }
     899    }       
    802900
    803901    if (V_VT(pvar) & VT_BYREF)
     
    808906{
    809907    int index = 0;
    810 
     908   
    811909    TRACE("args=%u named args=%u\n", pdp->cArgs, pdp->cNamedArgs);
    812910
     
    820918static char * typekind_desc[] =
    821919{
    822     "TKIND_ENUM",
    823     "TKIND_RECORD",
    824     "TKIND_MODULE",
    825     "TKIND_INTERFACE",
    826     "TKIND_DISPATCH",
    827     "TKIND_COCLASS",
    828     "TKIND_ALIAS",
    829     "TKIND_UNION",
    830     "TKIND_MAX"
     920        "TKIND_ENUM",
     921        "TKIND_RECORD",
     922        "TKIND_MODULE",
     923        "TKIND_INTERFACE",
     924        "TKIND_DISPATCH",
     925        "TKIND_COCLASS",
     926        "TKIND_ALIAS",
     927        "TKIND_UNION",
     928        "TKIND_MAX"
    831929};
    832930
     
    842940    dump_TLBFuncDesc(pty->funclist);
    843941    dump_TLBVarDesc(pty->varlist);
    844     dump_TLBRefType(pty->impltypelist);
     942    dump_TLBImplType(pty->impltypelist);
    845943}
    846944#else
    847945static char * typekind_desc[] =
    848946{
    849     "TKIND_ENUM",
    850     "TKIND_RECORD",
    851     "TKIND_MODULE",
    852     "TKIND_INTERFACE",
    853     "TKIND_DISPATCH",
    854     "TKIND_COCLASS",
    855     "TKIND_ALIAS",
    856     "TKIND_UNION",
    857     "TKIND_MAX"
     947        "TKIND_ENUM",
     948        "TKIND_RECORD",
     949        "TKIND_MODULE",
     950        "TKIND_INTERFACE",
     951        "TKIND_DISPATCH",
     952        "TKIND_COCLASS",
     953        "TKIND_ALIAS",
     954        "TKIND_UNION",
     955        "TKIND_MAX"
    858956};
    859957#define  dump_TypeInfo(a)
     
    861959#define  dump_TLBFuncDescOne(a)
    862960#define  dump_TLBVarDesc(a)
     961#define  dump_TLBRefType(a)
     962#define  dump_TLBFuncDesc(a)
     963#define  dump_TypeDesc(a,b)
    863964#endif
    864965
     
    894995    HeapFree(GetProcessHeap(), 0, ptr);
    895996}
     997
     998
     999/**********************************************************************
     1000 *
     1001 *  Functions for reading MSFT typelibs (those created by CreateTypeLib2)
     1002 */
    8961003/* read function */
    897 DWORD TLB_Read(void *buffer,  DWORD count, TLBContext *pcx, long where )
     1004DWORD MSFT_Read(void *buffer,  DWORD count, TLBContext *pcx, long where )
    8981005{
    8991006    TRACE_(typelib)("pos=0x%08x len=0x%08lx 0x%08x 0x%08x 0x%08lx\n",
     
    9171024}
    9181025
    919 static void TLB_ReadGuid( GUID *pGuid, int offset, TLBContext *pcx)
     1026static void MSFT_ReadGuid( GUID *pGuid, int offset, TLBContext *pcx)
    9201027{
    9211028    TRACE_(typelib)("%s\n", debugstr_guid(pGuid));
     
    9251032        return;
    9261033    }
    927     TLB_Read(pGuid, sizeof(GUID), pcx, pcx->pTblDir->pGuidTab.offset+offset );
    928 }
    929 
    930 BSTR TLB_ReadName( TLBContext *pcx, int offset)
     1034    MSFT_Read(pGuid, sizeof(GUID), pcx, pcx->pTblDir->pGuidTab.offset+offset );
     1035}
     1036
     1037BSTR MSFT_ReadName( TLBContext *pcx, int offset)
    9311038{
    9321039    char * name;
    933     TLBNameIntro niName;
     1040    MSFT_NameIntro niName;
    9341041    int lengthInChars;
    9351042    WCHAR* pwstring = NULL;
    9361043    BSTR bstrName = NULL;
    9371044
    938     TLB_Read(&niName, sizeof(niName), pcx,
    939                 pcx->pTblDir->pNametab.offset+offset);
     1045    MSFT_Read(&niName, sizeof(niName), pcx,
     1046                                pcx->pTblDir->pNametab.offset+offset);
    9401047    niName.namelen &= 0xFF; /* FIXME: correct ? */
    9411048    name=TLB_Alloc((niName.namelen & 0xff) +1);
    942     TLB_Read(name, (niName.namelen & 0xff), pcx, DO_NOT_SEEK);
     1049    MSFT_Read(name, (niName.namelen & 0xff), pcx, DO_NOT_SEEK);
    9431050    name[niName.namelen & 0xff]='\0';
    9441051
     
    9631070}
    9641071
    965 BSTR TLB_ReadString( TLBContext *pcx, int offset)
     1072BSTR MSFT_ReadString( TLBContext *pcx, int offset)
    9661073{
    9671074    char * string;
     
    9711078
    9721079    if(offset<0) return NULL;
    973     TLB_Read(&length, sizeof(INT16), pcx, pcx->pTblDir->pStringtab.offset+offset);
     1080    MSFT_Read(&length, sizeof(INT16), pcx, pcx->pTblDir->pStringtab.offset+offset);
    9741081    if(length <= 0) return 0;
    9751082    string=TLB_Alloc(length +1);
    976     TLB_Read(string, length, pcx, DO_NOT_SEEK);
     1083    MSFT_Read(string, length, pcx, DO_NOT_SEEK);
    9771084    string[length]='\0';
    9781085
     
    9971104}
    9981105/*
    999  * read a value and fill a VARIANT structure
    1000  */
    1001 static void TLB_ReadValue( VARIANT * pVar, int offset, TLBContext *pcx )
     1106 * read a value and fill a VARIANT structure 
     1107 */
     1108static void MSFT_ReadValue( VARIANT * pVar, int offset, TLBContext *pcx )
    10021109{
    10031110    int size;
     
    10051112    TRACE_(typelib)("\n");
    10061113
    1007     if(offset <0) { /* data is packed in here */
     1114    if(offset <0) { /* data are packed in here */
    10081115        V_VT(pVar) = (offset & 0x7c000000 )>> 26;
    10091116        V_UNION(pVar, iVal) = offset & 0xffff;
    10101117        return;
    10111118    }
    1012     TLB_Read(&(V_VT(pVar)), sizeof(VARTYPE), pcx,
     1119    MSFT_Read(&(V_VT(pVar)), sizeof(VARTYPE), pcx,
    10131120        pcx->pTblDir->pCustData.offset + offset );
    10141121    TRACE_(typelib)("Vartype = %x\n", V_VT(pVar));
     
    10191126        case VT_I4  :
    10201127        case VT_R4  :
    1021         case VT_ERROR   :
    1022         case VT_BOOL    :
    1023         case VT_I1  :
    1024         case VT_UI1 :
    1025         case VT_UI2 :
    1026         case VT_UI4 :
    1027         case VT_INT :
    1028         case VT_UINT    :
     1128        case VT_ERROR   : 
     1129        case VT_BOOL    : 
     1130        case VT_I1  : 
     1131        case VT_UI1 : 
     1132        case VT_UI2 : 
     1133        case VT_UI4 : 
     1134        case VT_INT : 
     1135        case VT_UINT    : 
    10291136        case VT_VOID    : /* FIXME: is this right? */
    1030         case VT_HRESULT :
     1137        case VT_HRESULT : 
    10311138            size=4; break;
    10321139        case VT_R8  :
    10331140        case VT_CY  :
    1034         case VT_DATE    :
    1035         case VT_I8  :
    1036         case VT_UI8 :
     1141        case VT_DATE    : 
     1142        case VT_I8  : 
     1143        case VT_UI8 : 
    10371144        case VT_DECIMAL :  /* FIXME: is this right? */
    10381145        case VT_FILETIME :
     
    10411148        case VT_BSTR    :{
    10421149            char * ptr;
    1043             TLB_Read(&size, sizeof(INT), pcx, DO_NOT_SEEK );
    1044         if(size <= 0) {
    1045             FIXME("BSTR length = %d?\n", size);
    1046         } else {
     1150            MSFT_Read(&size, sizeof(INT), pcx, DO_NOT_SEEK );
     1151            if(size <= 0) {
     1152                FIXME("BSTR length = %d?\n", size);
     1153            } else {
    10471154                ptr=TLB_Alloc(size);/* allocate temp buffer */
    1048         TLB_Read(ptr, size, pcx, DO_NOT_SEEK); /* read string (ANSI) */
    1049         V_UNION(pVar, bstrVal)=SysAllocStringLen(NULL,size);
    1050         /* FIXME: do we need a AtoW conversion here? */
    1051         V_UNION(pVar, bstrVal[size])=L'\0';
    1052         while(size--) V_UNION(pVar, bstrVal[size])=ptr[size];
    1053         TLB_Free(ptr);
    1054         }
    1055     }
    1056     size=-4; break;
     1155                MSFT_Read(ptr, size, pcx, DO_NOT_SEEK);/* read string (ANSI) */
     1156                V_UNION(pVar, bstrVal)=SysAllocStringLen(NULL,size);
     1157                /* FIXME: do we need a AtoW conversion here? */
     1158                V_UNION(pVar, bstrVal[size])=L'\0';
     1159                while(size--) V_UNION(pVar, bstrVal[size])=ptr[size];
     1160                TLB_Free(ptr);
     1161            }
     1162        }
     1163        size=-4; break;
    10571164    /* FIXME: this will not work AT ALL when the variant contains a pointer */
    10581165        case VT_DISPATCH :
    1059         case VT_VARIANT :
    1060         case VT_UNKNOWN :
    1061         case VT_PTR :
     1166        case VT_VARIANT : 
     1167        case VT_UNKNOWN : 
     1168        case VT_PTR : 
    10621169        case VT_SAFEARRAY :
    1063         case VT_CARRAY  :
    1064         case VT_USERDEFINED :
    1065         case VT_LPSTR   :
    1066         case VT_LPWSTR  :
    1067         case VT_BLOB    :
    1068         case VT_STREAM  :
    1069         case VT_STORAGE :
    1070         case VT_STREAMED_OBJECT :
    1071         case VT_STORED_OBJECT   :
    1072         case VT_BLOB_OBJECT :
    1073         case VT_CF  :
    1074         case VT_CLSID   :
    1075         default:
    1076             size=0;
     1170        case VT_CARRAY  : 
     1171        case VT_USERDEFINED : 
     1172        case VT_LPSTR   : 
     1173        case VT_LPWSTR  : 
     1174        case VT_BLOB    : 
     1175        case VT_STREAM  : 
     1176        case VT_STORAGE : 
     1177        case VT_STREAMED_OBJECT : 
     1178        case VT_STORED_OBJECT   : 
     1179        case VT_BLOB_OBJECT : 
     1180        case VT_CF  : 
     1181        case VT_CLSID   : 
     1182        default: 
     1183            size=0; 
    10771184            FIXME("VARTYPE %d is not supported, setting pointer to NULL\n",
    10781185                V_VT(pVar));
     
    10801187
    10811188    if(size>0) /* (big|small) endian correct? */
    1082         TLB_Read(&(V_UNION(pVar, iVal)), size, pcx, DO_NOT_SEEK );
     1189        MSFT_Read(&(V_UNION(pVar, iVal)), size, pcx, DO_NOT_SEEK );
    10831190    return;
    10841191}
     
    10861193 * create a linked list with custom data
    10871194 */
    1088 static int TLB_CustData( TLBContext *pcx, int offset, TLBCustData** ppCustData )
    1089 {
    1090     TLBCDGuid entry;
     1195static int MSFT_CustData( TLBContext *pcx, int offset, TLBCustData** ppCustData )
     1196{
     1197    MSFT_CDGuid entry;
    10911198    TLBCustData* pNew;
    10921199    int count=0;
     
    10971204        count++;
    10981205        pNew=TLB_Alloc(sizeof(TLBCustData));
    1099         TLB_Read(&entry, sizeof(entry), pcx,
     1206        MSFT_Read(&entry, sizeof(entry), pcx,
    11001207            pcx->pTblDir->pCDGuids.offset+offset);
    1101         TLB_ReadGuid(&(pNew->guid), entry.GuidOffset , pcx);
    1102         TLB_ReadValue(&(pNew->data), entry.DataOffset, pcx);
     1208        MSFT_ReadGuid(&(pNew->guid), entry.GuidOffset , pcx);
     1209        MSFT_ReadValue(&(pNew->data), entry.DataOffset, pcx);
    11031210        /* add new custom data at head of the list */
    11041211        pNew->next=*ppCustData;
     
    11091216}
    11101217
    1111 static void TLB_GetTdesc(TLBContext *pcx, INT type,TYPEDESC * pTd )
     1218static void MSFT_GetTdesc(TLBContext *pcx, INT type, TYPEDESC *pTd,
     1219                          ITypeInfoImpl *pTI)
    11121220{
    11131221    if(type <0)
     
    11161224        *pTd=pcx->pLibInfo->pTypeDesc[type/(2*sizeof(INT))];
    11171225
     1226    if(pTd->vt == VT_USERDEFINED)
     1227      MSFT_DoRefType(pcx, pTI, pTd->u.hreftype);
     1228
    11181229    TRACE_(typelib)("vt type = %X\n", pTd->vt);
    11191230}
    11201231
    1121 static void
    1122 TLB_DoFuncs(TLBContext*     pcx,
    1123             int             cFuncs,
     1232static void
     1233MSFT_DoFuncs(TLBContext*     pcx,
     1234            ITypeInfoImpl*  pTI,
     1235            int             cFuncs,
    11241236            int             cVars,
    1125             int             offset,
     1237            int             offset, 
    11261238            TLBFuncDesc**   pptfd)
    11271239{
    1128     /*
     1240    /* 
    11291241     * member information is stored in a data structure at offset
    11301242     * indicated by the memoffset field of the typeinfo structure
    11311243     * There are several distinctive parts.
    1132      * the first part starts with a field that holds the total length
     1244     * the first part starts with a field that holds the total length 
    11331245     * of this (first) part excluding this field. Then follow the records,
    11341246     * for each member there is one record.
    11351247     *
    11361248     * First entry is always the length of the record (excluding this
    1137      * length word).
    1138      * Rest of the record depends on the type of the member. If there is
     1249     * length word). 
     1250     * Rest of the record depends on the type of the member. If there is 
    11391251     * a field indicating the member type (function variable intereface etc)
    11401252     * I have not found it yet. At this time we depend on the information
     
    11431255     * Second follows an array sized nrMEM*sizeof(INT) with a memeber id
    11441256     * for each member;
    1145      *
    1146      * Third is a equal sized array with file offsets to the name entry
     1257     * 
     1258     * Third is a equal sized array with file offsets to the name entry 
    11471259     * of each member.
    1148      *
     1260     * 
    11491261     * Forth and last (?) part is an array with offsets to the records in the
    11501262     * first part of this file segment.
     
    11551267
    11561268    char recbuf[512];
    1157     TLBFuncRecord * pFuncRec=(TLBFuncRecord *) recbuf;
     1269    MSFT_FuncRecord * pFuncRec=(MSFT_FuncRecord *) recbuf;
    11581270
    11591271    TRACE_(typelib)("\n");
    11601272
    1161     TLB_Read(&infolen, sizeof(INT), pcx, offset);
     1273    MSFT_Read(&infolen, sizeof(INT), pcx, offset);
    11621274
    11631275    for ( i = 0; i < cFuncs ; i++ )
     
    11661278
    11671279        /* name, eventually add to a hash table */
    1168         TLB_Read(&nameoffset,
    1169                  sizeof(INT),
    1170                  pcx,
     1280        MSFT_Read(&nameoffset,
     1281                 sizeof(INT), 
     1282                 pcx, 
    11711283                 offset + infolen + (cFuncs + cVars + i + 1) * sizeof(INT));
    11721284
    1173         (*pptfd)->Name = TLB_ReadName(pcx, nameoffset);
     1285        (*pptfd)->Name = MSFT_ReadName(pcx, nameoffset);
    11741286
    11751287        /* read the function information record */
    1176         TLB_Read(&reclength, sizeof(INT), pcx, recoffset);
    1177 
     1288        MSFT_Read(&reclength, sizeof(INT), pcx, recoffset);
     1289       
    11781290        reclength &= 0x1ff;
    11791291
    1180         TLB_Read(pFuncRec, reclength - sizeof(INT), pcx, DO_NOT_SEEK) ;
     1292        MSFT_Read(pFuncRec, reclength - sizeof(INT), pcx, DO_NOT_SEEK) ;
    11811293
    11821294        /* do the attributes */
     
    11871299        {
    11881300            (*pptfd)->helpcontext = pFuncRec->OptAttr[0] ;
    1189 
     1301           
    11901302            if ( nrattributes > 1 )
    11911303            {
    1192                 (*pptfd)->HelpString = TLB_ReadString(pcx,
     1304                (*pptfd)->HelpString = MSFT_ReadString(pcx,
    11931305                                                      pFuncRec->OptAttr[1]) ;
    11941306
     
    12011313                    else
    12021314                    {
    1203                         (*pptfd)->Entry = TLB_ReadString(pcx,
     1315                        (*pptfd)->Entry = MSFT_ReadString(pcx,
    12041316                                                         pFuncRec->OptAttr[2]);
    12051317                    }
     
    12101322                        if ( nrattributes > 6 && pFuncRec->FKCCIC & 0x80 )
    12111323                        {
    1212                             TLB_CustData(pcx,
    1213                                          pFuncRec->OptAttr[6],
    1214                                          &(*pptfd)->pCustData);
     1324                            MSFT_CustData(pcx,
     1325                                          pFuncRec->OptAttr[6],
     1326                                          &(*pptfd)->pCustData);
    12151327                        }
    12161328                    }
     
    12201332
    12211333        /* fill the FuncDesc Structure */
    1222         TLB_Read( & (*pptfd)->funcdesc.memid,
    1223                   sizeof(INT), pcx,
     1334        MSFT_Read( & (*pptfd)->funcdesc.memid,
     1335                  sizeof(INT), pcx, 
    12241336                  offset + infolen + ( i + 1) * sizeof(INT));
    12251337
     
    12321344        (*pptfd)->funcdesc.wFuncFlags =   LOWORD(pFuncRec->Flags) ;
    12331345
    1234         TLB_GetTdesc(pcx,
    1235                      pFuncRec->DataType,
    1236                      &(*pptfd)->funcdesc.elemdescFunc.tdesc) ;
     1346        MSFT_GetTdesc(pcx,
     1347                      pFuncRec->DataType,   
     1348                      &(*pptfd)->funcdesc.elemdescFunc.tdesc,
     1349                      pTI);
    12371350
    12381351        /* do the parameters/arguments */
     
    12401353        {
    12411354            int j = 0;
    1242             TLBParameterInfo paraminfo;
    1243 
    1244             (*pptfd)->funcdesc.lprgelemdescParam =
     1355            MSFT_ParameterInfo paraminfo;
     1356
     1357            (*pptfd)->funcdesc.lprgelemdescParam = 
    12451358                TLB_Alloc(pFuncRec->nrargs * sizeof(ELEMDESC));
    12461359
    1247             (*pptfd)->pParamDesc =
     1360            (*pptfd)->pParamDesc = 
    12481361                TLB_Alloc(pFuncRec->nrargs * sizeof(TLBParDesc));
    12491362
    1250             TLB_Read(&paraminfo,
    1251                      sizeof(paraminfo),
    1252                      pcx,
    1253                      recoffset + reclength -
    1254                         pFuncRec->nrargs * sizeof(TLBParameterInfo));
     1363            MSFT_Read(&paraminfo,
     1364                      sizeof(paraminfo),
     1365                      pcx,
     1366                      recoffset + reclength -
     1367                      pFuncRec->nrargs * sizeof(MSFT_ParameterInfo));
    12551368
    12561369            for ( j = 0 ; j < pFuncRec->nrargs ; j++ )
     
    12581371                TYPEDESC* lpArgTypeDesc = 0;
    12591372
    1260                 TLB_GetTdesc(pcx,
    1261                              paraminfo.DataType,
    1262                              &(*pptfd)->funcdesc.lprgelemdescParam[j].tdesc) ;
     1373                MSFT_GetTdesc(pcx,
     1374                              paraminfo.DataType,   
     1375                              &(*pptfd)->funcdesc.lprgelemdescParam[j].tdesc,
     1376                              pTI);
    12631377
    12641378                (*pptfd)->funcdesc.lprgelemdescParam[j].u.paramdesc.wParamFlags = paraminfo.Flags;
     
    12661380                (*pptfd)->pParamDesc[j].Name = (void *) paraminfo.oName;
    12671381
    1268                 /* SEEK value = jump to offset,
     1382                /* SEEK value = jump to offset, 
    12691383                 * from there jump to the end of record,
    12701384                 * go back by (j-1) arguments
    12711385                 */
    1272                 TLB_Read( &paraminfo ,
    1273                           sizeof(TLBParameterInfo), pcx,
    1274                           recoffset + reclength - ((pFuncRec->nrargs - j - 1)
    1275                                                    * sizeof(TLBParameterInfo)));
    1276                 lpArgTypeDesc =
     1386                MSFT_Read( &paraminfo ,
     1387                           sizeof(MSFT_ParameterInfo), pcx,
     1388                           recoffset + reclength - ((pFuncRec->nrargs - j - 1)
     1389                                               * sizeof(MSFT_ParameterInfo)));
     1390                lpArgTypeDesc = 
    12771391                    & ((*pptfd)->funcdesc.lprgelemdescParam[j].tdesc);
    12781392
     
    12901404
    12911405                    case VT_USERDEFINED:
    1292                         (*pptfd)->pParamDesc[j].pRefType =
    1293                         TLB_Alloc(sizeof(TLBRefType));
    1294 
    1295                         TLB_DoRefType(pcx,
    1296                                       lpArgTypeDesc->u.hreftype,
    1297                                       & ( (*pptfd)->pParamDesc[j].pRefType ));
     1406                        MSFT_DoRefType(pcx, pTI,
     1407                                       lpArgTypeDesc->u.hreftype);
    12981408
    12991409                        lpArgTypeDesc = NULL;
     
    13121422                TYPEDESC* lpArgTypeDesc;
    13131423
    1314                 (*pptfd)->funcdesc.elemdescFunc =
     1424                (*pptfd)->funcdesc.elemdescFunc = 
    13151425                (*pptfd)->funcdesc.lprgelemdescParam[j];
    13161426
     
    13251435                        break;
    13261436                    case VT_CARRAY:
    1327                         lpArgTypeDesc =
     1437                        lpArgTypeDesc = 
    13281438                        & (lpArgTypeDesc->u.lpadesc->tdescElem);
    13291439
     
    13311441
    13321442                    case VT_USERDEFINED:
    1333                         (*pptfd)->pParamDesc[j].pRefType
    1334                         = TLB_Alloc(sizeof(TLBRefType));
    1335 
    1336                         TLB_DoRefType(pcx,
    1337                                       lpArgTypeDesc->u.hreftype,
    1338                                       &((*pptfd)->pParamDesc[j].pRefType));
     1443                        MSFT_DoRefType(pcx,
     1444                                       pTI,
     1445                                       lpArgTypeDesc->u.hreftype);
    13391446
    13401447                        lpArgTypeDesc = NULL;
     
    13521459                /* name */
    13531460                (*pptfd)->pParamDesc[j].Name =
    1354                     TLB_ReadName( pcx, (int)(*pptfd)->pParamDesc[j].Name );
     1461                    MSFT_ReadName( pcx, (int)(*pptfd)->pParamDesc[j].Name );
    13551462
    13561463                /* default value */
    1357                 if ( (PARAMFLAG_FHASDEFAULT &
     1464                if ( (PARAMFLAG_FHASDEFAULT & 
    13581465                      (*pptfd)->funcdesc.lprgelemdescParam[j].u.paramdesc.wParamFlags) &&
    13591466                     ((pFuncRec->FKCCIC) & 0x1000) )
    13601467                {
    1361                     INT* pInt = (INT *)((char *)pFuncRec +
    1362                                    reclength -
     1468                    INT* pInt = (INT *)((char *)pFuncRec + 
     1469                                   reclength - 
    13631470                                   (pFuncRec->nrargs * 4 + 1) * sizeof(INT) );
    13641471
     
    13681475                    pParamDesc->pparamdescex->cBytes = sizeof(PARAMDESCEX);
    13691476
    1370                     TLB_ReadValue(&(pParamDesc->pparamdescex->varDefaultValue),
     1477                    MSFT_ReadValue(&(pParamDesc->pparamdescex->varDefaultValue),
    13711478                        pInt[j], pcx);
    13721479                }
     
    13741481                if ( nrattributes > 7 + j && pFuncRec->FKCCIC & 0x80 )
    13751482                {
    1376                     TLB_CustData(pcx,
    1377                                  pFuncRec->OptAttr[7+j],
    1378                                  &(*pptfd)->pParamDesc[j].pCustData);
     1483                    MSFT_CustData(pcx,
     1484                                  pFuncRec->OptAttr[7+j],
     1485                                  &(*pptfd)->pParamDesc[j].pCustData);
    13791486                }
    13801487           }
     
    13891496    }
    13901497}
    1391 static void TLB_DoVars(TLBContext *pcx, int cFuncs, int cVars,
    1392                           int offset, TLBVarDesc ** pptvd)
     1498static void MSFT_DoVars(TLBContext *pcx, ITypeInfoImpl *pTI, int cFuncs,
     1499                       int cVars, int offset, TLBVarDesc ** pptvd)
    13931500{
    13941501    int infolen, nameoffset, reclength;
    13951502    char recbuf[256];
    1396     TLBVarRecord * pVarRec=(TLBVarRecord *) recbuf;
     1503    MSFT_VarRecord * pVarRec=(MSFT_VarRecord *) recbuf;
    13971504    int i;
    13981505    int recoffset;
     
    14001507    TRACE_(typelib)("\n");
    14011508
    1402     TLB_Read(&infolen,sizeof(INT), pcx, offset);
    1403     TLB_Read(&recoffset,sizeof(INT), pcx, offset + infolen +
     1509    MSFT_Read(&infolen,sizeof(INT), pcx, offset);
     1510    MSFT_Read(&recoffset,sizeof(INT), pcx, offset + infolen +
    14041511        ((cFuncs+cVars)*2+cFuncs + 1)*sizeof(INT));
    14051512    recoffset += offset+sizeof(INT);
     
    14071514        *pptvd=TLB_Alloc(sizeof(TLBVarDesc));
    14081515    /* name, eventually add to a hash table */
    1409         TLB_Read(&nameoffset, sizeof(INT), pcx,
     1516        MSFT_Read(&nameoffset, sizeof(INT), pcx,
    14101517            offset + infolen + (cFuncs + cVars + i + 1) * sizeof(INT));
    1411         (*pptvd)->Name=TLB_ReadName(pcx, nameoffset);
     1518        (*pptvd)->Name=MSFT_ReadName(pcx, nameoffset);
    14121519    /* read the variable information record */
    1413         TLB_Read(&reclength, sizeof(INT), pcx, recoffset);
     1520        MSFT_Read(&reclength, sizeof(INT), pcx, recoffset);
    14141521        reclength &=0xff;
    1415         TLB_Read(pVarRec, reclength - sizeof(INT), pcx, DO_NOT_SEEK) ;
     1522        MSFT_Read(pVarRec, reclength - sizeof(INT), pcx, DO_NOT_SEEK) ;
    14161523    /* Optional data */
    14171524        if(reclength >(6*sizeof(INT)) )
    14181525            (*pptvd)->HelpContext=pVarRec->HelpContext;
    14191526        if(reclength >(7*sizeof(INT)) )
    1420             (*pptvd)->HelpString = TLB_ReadString(pcx, pVarRec->oHelpString) ;
     1527            (*pptvd)->HelpString = MSFT_ReadString(pcx, pVarRec->oHelpString) ;
    14211528        if(reclength >(8*sizeof(INT)) )
    14221529        if(reclength >(9*sizeof(INT)) )
    14231530            (*pptvd)->HelpStringContext=pVarRec->HelpStringContext;
    14241531    /* fill the VarDesc Structure */
    1425         TLB_Read(&(*pptvd)->vardesc.memid, sizeof(INT), pcx,
     1532        MSFT_Read(&(*pptvd)->vardesc.memid, sizeof(INT), pcx,
    14261533            offset + infolen + ( i + 1) * sizeof(INT));
    14271534        (*pptvd)->vardesc.varkind = pVarRec->VarKind;
    14281535        (*pptvd)->vardesc.wVarFlags = pVarRec->Flags;
    1429         TLB_GetTdesc(pcx, pVarRec->DataType,
    1430             &(*pptvd)->vardesc.elemdescVar.tdesc) ;
     1536        MSFT_GetTdesc(pcx, pVarRec->DataType,   
     1537            &(*pptvd)->vardesc.elemdescVar.tdesc, pTI);
    14311538/*   (*pptvd)->vardesc.lpstrSchema; is reserved (SDK) fixme?? */
    14321539        if(pVarRec->VarKind == VAR_CONST ){
    14331540            (*pptvd)->vardesc.u.lpvarValue=TLB_Alloc(sizeof(VARIANT));
    1434             TLB_ReadValue((*pptvd)->vardesc.u.lpvarValue,
     1541            MSFT_ReadValue((*pptvd)->vardesc.u.lpvarValue,
    14351542                pVarRec->OffsValue, pcx);
    14361543        } else
     
    14411548}
    14421549/* fill in data for a hreftype (offset). When the refernced type is contained
    1443  * in the typelib, its just an (file) offset in the type info base dir.
    1444  * If comes from import, its an offset+1 in the ImpInfo table
     1550 * in the typelib, it's just an (file) offset in the type info base dir.
     1551 * If comes from import, it's an offset+1 in the ImpInfo table
    14451552 * */
    1446 static void TLB_DoRefType(TLBContext *pcx,
    1447                           int offset, TLBRefType ** pprtd)
     1553static void MSFT_DoRefType(TLBContext *pcx, ITypeInfoImpl *pTI,
     1554                          int offset)
    14481555{
    14491556    int j;
     1557    TLBRefType **ppRefType = &pTI->reflist;
    14501558
    14511559    TRACE_(typelib)("TLB context %p, TLB offset %x\n", pcx, offset);
    14521560
    1453     if(!HREFTYPE_INTHISFILE( offset)) {
     1561    while(*ppRefType) {
     1562        if((*ppRefType)->reference == offset)
     1563            return;
     1564        ppRefType = &(*ppRefType)->next;
     1565    }
     1566
     1567    *ppRefType = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
     1568                           sizeof(**ppRefType));
     1569
     1570    if(!MSFT_HREFTYPE_INTHISFILE( offset)) {
    14541571        /* external typelib */
    1455         TLBImpInfo impinfo;
     1572        MSFT_ImpInfo impinfo;
    14561573        TLBImpLib *pImpLib=(pcx->pLibInfo->pImpLibs);
    14571574
    14581575        TRACE_(typelib)("offset %x, masked offset %x\n", offset, offset + (offset & 0xfffffffc));
    14591576
    1460         TLB_Read(&impinfo, sizeof(impinfo), pcx,
     1577        MSFT_Read(&impinfo, sizeof(impinfo), pcx,
    14611578            pcx->pTblDir->pImpInfo.offset + (offset & 0xfffffffc));
    14621579        for(j=0;pImpLib;j++){   /* search the known offsets of all import libraries */
     
    14651582        }
    14661583        if(pImpLib){
    1467             (*pprtd)->reference=offset;
    1468             (*pprtd)->pImpTLInfo = pImpLib;
    1469             TLB_ReadGuid(&(*pprtd)->guid, impinfo.oGuid, pcx);
     1584            (*ppRefType)->reference=offset;
     1585            (*ppRefType)->pImpTLInfo = pImpLib;
     1586            MSFT_ReadGuid(&(*ppRefType)->guid, impinfo.oGuid, pcx);
     1587            (*ppRefType)->index = TLB_REF_USE_GUID;
    14701588        }else{
    14711589            ERR("Cannot find a reference\n");
    1472             (*pprtd)->reference=-1;
    1473             (*pprtd)->pImpTLInfo=(void *)-1;
     1590            (*ppRefType)->reference=-1;
     1591            (*ppRefType)->pImpTLInfo=TLB_REF_NOT_FOUND;
    14741592        }
    14751593    }else{
    14761594        /* in this typelib */
    1477         (*pprtd)->reference=offset;
    1478         (*pprtd)->pImpTLInfo=(void *)-2;
     1595        (*ppRefType)->index = MSFT_HREFTYPE_INDEX(offset);
     1596        (*ppRefType)->reference=offset;
     1597        (*ppRefType)->pImpTLInfo=TLB_REF_INTERNAL;
    14791598    }
    14801599}
    14811600
    14821601/* process Implemented Interfaces of a com class */
    1483 static void TLB_DoImplTypes(TLBContext *pcx, int count,
    1484                           int offset, TLBRefType ** pprtd)
     1602static void MSFT_DoImplTypes(TLBContext *pcx, ITypeInfoImpl *pTI, int count,
     1603                            int offset)
    14851604{
    14861605    int i;
    1487     TLBRefRecord refrec;
     1606    MSFT_RefRecord refrec;
     1607    TLBImplType **ppImpl = &pTI->impltypelist;
    14881608
    14891609    TRACE_(typelib)("\n");
     
    14911611    for(i=0;i<count;i++){
    14921612        if(offset<0) break; /* paranoia */
    1493         *pprtd=TLB_Alloc(sizeof(TLBRefType));
    1494         TLB_Read(&refrec,sizeof(refrec),pcx,offset+pcx->pTblDir->pRefTab.offset);
    1495         TLB_DoRefType(pcx, refrec.reftype, pprtd);
    1496         (*pprtd)->flags=refrec.flags;
    1497         (*pprtd)->ctCustData=
    1498             TLB_CustData(pcx, refrec.oCustData, &(*pprtd)->pCustData);
     1613        *ppImpl=TLB_Alloc(sizeof(**ppImpl));
     1614        MSFT_Read(&refrec,sizeof(refrec),pcx,offset+pcx->pTblDir->pRefTab.offset);
     1615        MSFT_DoRefType(pcx, pTI, refrec.reftype);
     1616        (*ppImpl)->hRef = refrec.reftype;
     1617        (*ppImpl)->implflags=refrec.flags;
     1618        (*ppImpl)->ctCustData=
     1619            MSFT_CustData(pcx, refrec.oCustData, &(*ppImpl)->pCustData);
    14991620        offset=refrec.onext;
    1500         pprtd=&((*pprtd)->next);
     1621        ppImpl=&((*ppImpl)->next);
    15011622    }
    15021623}
     
    15041625 * process a typeinfo record
    15051626 */
    1506 ITypeInfoImpl * TLB_DoTypeInfo(
     1627ITypeInfoImpl * MSFT_DoTypeInfo(
    15071628    TLBContext *pcx,
    15081629    int count,
    15091630    ITypeLibImpl * pLibInfo)
    15101631{
    1511     TLBTypeInfoBase tiBase;
     1632    MSFT_TypeInfoBase tiBase;
    15121633    ITypeInfoImpl *ptiRet;
    15131634
     
    15151636
    15161637    ptiRet = (ITypeInfoImpl*) ITypeInfo_Constructor();
    1517     TLB_Read(&tiBase, sizeof(tiBase) ,pcx ,
     1638    MSFT_Read(&tiBase, sizeof(tiBase) ,pcx ,
    15181639        pcx->pTblDir->pTypeInfoTab.offset+count*sizeof(tiBase));
    15191640/* this is where we are coming from */
     
    15231644    FIXME("Assign constructor/destructor memid\n");
    15241645
    1525     TLB_ReadGuid(&ptiRet->TypeAttr.guid, tiBase.posguid, pcx);
     1646    MSFT_ReadGuid(&ptiRet->TypeAttr.guid, tiBase.posguid, pcx);
    15261647    ptiRet->TypeAttr.lcid=pLibInfo->LibAttr.lcid;   /* FIXME: correct? */
    15271648    ptiRet->TypeAttr.memidConstructor=MEMBERID_NIL ;/* FIXME */
     
    15391660    ptiRet->TypeAttr.cbSizeVft=tiBase.cbSizeVft; /* FIXME: this is only the non inherited part */
    15401661    if(ptiRet->TypeAttr.typekind == TKIND_ALIAS)
    1541         TLB_GetTdesc(pcx, tiBase.datatype1,
    1542             &ptiRet->TypeAttr.tdescAlias) ;
     1662        MSFT_GetTdesc(pcx, tiBase.datatype1,
     1663            &ptiRet->TypeAttr.tdescAlias, ptiRet);
    15431664
    15441665/*  FIXME: */
     
    15461667
    15471668/* name, eventually add to a hash table */
    1548     ptiRet->Name=TLB_ReadName(pcx, tiBase.NameOffset);
     1669    ptiRet->Name=MSFT_ReadName(pcx, tiBase.NameOffset);
    15491670    TRACE_(typelib)("reading %s\n", debugstr_w(ptiRet->Name));
    15501671    /* help info */
    1551     ptiRet->DocString=TLB_ReadString(pcx, tiBase.docstringoffs);
     1672    ptiRet->DocString=MSFT_ReadString(pcx, tiBase.docstringoffs);
    15521673    ptiRet->dwHelpStringContext=tiBase.helpstringcontext;
    15531674    ptiRet->dwHelpContext=tiBase.helpcontext;
     
    15571678    /* functions */
    15581679    if(ptiRet->TypeAttr.cFuncs >0 )
    1559         TLB_DoFuncs(pcx, ptiRet->TypeAttr.cFuncs ,ptiRet->TypeAttr.cVars,
    1560         tiBase.memoffset, & ptiRet->funclist);
     1680        MSFT_DoFuncs(pcx, ptiRet, ptiRet->TypeAttr.cFuncs,
     1681                    ptiRet->TypeAttr.cVars,
     1682                    tiBase.memoffset, & ptiRet->funclist);
    15611683    /* variables */
    15621684    if(ptiRet->TypeAttr.cVars >0 )
    1563         TLB_DoVars(pcx, ptiRet->TypeAttr.cFuncs ,ptiRet->TypeAttr.cVars,
    1564         tiBase.memoffset, & ptiRet->varlist);
    1565     if(ptiRet->TypeAttr.cImplTypes >0 ){
     1685        MSFT_DoVars(pcx, ptiRet, ptiRet->TypeAttr.cFuncs,
     1686                   ptiRet->TypeAttr.cVars,
     1687                   tiBase.memoffset, & ptiRet->varlist);
     1688    if(ptiRet->TypeAttr.cImplTypes >0 ) {
    15661689        switch(ptiRet->TypeAttr.typekind)
    15671690        {
    15681691        case TKIND_COCLASS:
    1569             TLB_DoImplTypes(pcx, ptiRet->TypeAttr.cImplTypes ,
    1570                 tiBase.datatype1, & ptiRet->impltypelist);
     1692            MSFT_DoImplTypes(pcx, ptiRet, ptiRet->TypeAttr.cImplTypes ,
     1693                tiBase.datatype1);
    15711694            break;
    15721695        case TKIND_DISPATCH:
    1573             ptiRet->impltypelist=TLB_Alloc(sizeof(TLBRefType));
    1574 
     1696            ptiRet->impltypelist=TLB_Alloc(sizeof(TLBImplType));
     1697           
    15751698            if (tiBase.datatype1 != -1)
    15761699            {
    1577               TLB_DoRefType(pcx, tiBase.datatype1, & ptiRet->impltypelist);
     1700              MSFT_DoRefType(pcx, ptiRet, tiBase.datatype1);
     1701              ptiRet->impltypelist->hRef = tiBase.datatype1;
    15781702            }
    15791703            else
    1580             {
     1704            { /* FIXME: This is a really bad hack to add IDispatch */
    15811705              char* szStdOle     = "stdole2.tlb\0";
    15821706              int   nStdOleLen = strlen(szStdOle);
    1583 
    1584               ptiRet->impltypelist->guid             = IID_IDispatch;
    1585               ptiRet->impltypelist->reference        = -1;
    1586               ptiRet->impltypelist->pImpTLInfo       = TLB_Alloc(sizeof(TLBImpLib));
    1587               ptiRet->impltypelist->pImpTLInfo->guid = IID_StdOle;
    1588               ptiRet->impltypelist->pImpTLInfo->name = SysAllocStringLen(NULL, nStdOleLen  + 1);
    1589 
    1590               MultiByteToWideChar(CP_ACP,
    1591                                   MB_PRECOMPOSED,
    1592                                   szStdOle,
    1593                                   -1,
    1594                                   ptiRet->impltypelist->pImpTLInfo->name,
    1595                                   SysStringLen(ptiRet->impltypelist->pImpTLInfo->name));
    1596 
    1597               ptiRet->impltypelist->pImpTLInfo->lcid          = 0;
    1598               ptiRet->impltypelist->pImpTLInfo->wVersionMajor = 2;
    1599               ptiRet->impltypelist->pImpTLInfo->wVersionMinor = 0;
    1600             }
     1707              TLBRefType **ppRef = &ptiRet->reflist;
     1708
     1709              while(*ppRef) {
     1710                if((*ppRef)->reference == -1)
     1711                  break;
     1712                ppRef = &(*ppRef)->next;
     1713              }
     1714              if(!*ppRef) {
     1715                *ppRef = TLB_Alloc(sizeof(**ppRef));
     1716                (*ppRef)->guid             = IID_IDispatch;
     1717                (*ppRef)->reference        = -1;
     1718                (*ppRef)->index            = TLB_REF_USE_GUID;
     1719                (*ppRef)->pImpTLInfo       = TLB_Alloc(sizeof(TLBImpLib));
     1720                (*ppRef)->pImpTLInfo->guid = IID_StdOle;             
     1721                (*ppRef)->pImpTLInfo->name = SysAllocStringLen(NULL,
     1722                                                              nStdOleLen  + 1);
     1723             
     1724                MultiByteToWideChar(CP_ACP,
     1725                                    MB_PRECOMPOSED,
     1726                                    szStdOle,
     1727                                    -1,
     1728                                    (*ppRef)->pImpTLInfo->name,
     1729                                    SysStringLen((*ppRef)->pImpTLInfo->name));
     1730                                 
     1731                (*ppRef)->pImpTLInfo->lcid          = 0;
     1732                (*ppRef)->pImpTLInfo->wVersionMajor = 2;
     1733                (*ppRef)->pImpTLInfo->wVersionMinor = 0;
     1734              }
     1735            }
    16011736            break;
    16021737        default:
    1603             ptiRet->impltypelist=TLB_Alloc(sizeof(TLBRefType));
    1604             TLB_DoRefType(pcx, tiBase.datatype1, & ptiRet->impltypelist);
     1738            ptiRet->impltypelist=TLB_Alloc(sizeof(TLBImplType));
     1739            MSFT_DoRefType(pcx, ptiRet, tiBase.datatype1);
     1740            ptiRet->impltypelist->hRef = tiBase.datatype1;
    16051741            break;
    1606         }
     1742       }
    16071743    }
    16081744    ptiRet->ctCustData=
    1609         TLB_CustData(pcx, tiBase.oCustData, &ptiRet->pCustData);
     1745        MSFT_CustData(pcx, tiBase.oCustData, &ptiRet->pCustData);
    16101746
    16111747    TRACE_(typelib)("%s guid: %s kind:%s\n",
     
    16181754
    16191755/****************************************************************************
    1620  *  TLB_ReadTypeLib
     1756 *      TLB_ReadTypeLib
    16211757 *
    16221758 * find the type of the typelib file and map the typelib resource into
     
    16241760 */
    16251761#define MSFT_SIGNATURE 0x5446534D /* "MSFT" */
     1762#define SLTG_SIGNATURE 0x47544c53 /* "SLTG" */
    16261763int TLB_ReadTypeLib(LPSTR pszFileName, ITypeLib2 **ppTypeLib)
    16271764{
     
    16401777
    16411778    /* is it a DLL? */
    1642     for (i=0 ; i < nStrLen ; ++i)
    1643     {
    1644         pszFileName[i] = tolower(pszFileName[i]);
    1645     }
     1779        for (i=0 ; i < nStrLen ; ++i)
     1780        {
     1781            pszFileName[i] = tolower(pszFileName[i]);
     1782        }
    16461783    pszTypeLibIndex = strstr(pszFileName, ".dll");
    16471784
     
    16551792    if (pszTypeLibIndex && pszTypeLibIndex < pszFileName + nStrLen)
    16561793    {
    1657       /* yes -> it's a index! store DLL name, without the trailing back-slash */
     1794      /* yes -> it's an index! store DLL name, without the trailing back-slash */
    16581795      size_t nMemToAlloc = pszTypeLibIndex - pszFileName;
    1659 
     1796     
    16601797      pszDllName = HeapAlloc(GetProcessHeap(),
    1661                           HEAP_ZERO_MEMORY,
     1798                          HEAP_ZERO_MEMORY, 
    16621799                          nMemToAlloc + 1);
    1663 
     1800                         
    16641801      strncpy(pszDllName, pszFileName, nMemToAlloc);
    1665 
     1802     
    16661803      /* move index string pointer pass the backslash */
    16671804      while (*pszTypeLibIndex == '\\')
     
    16721809      /* No index, reset variable to 1 */
    16731810      pszDllName = HeapAlloc(GetProcessHeap(),
    1674                           HEAP_ZERO_MEMORY,
     1811                          HEAP_ZERO_MEMORY, 
    16751812                          nStrLen + 1);
    1676 
     1813                         
    16771814      strncpy(pszDllName, pszFileName, nStrLen);
    1678 
     1815     
    16791816      pszTypeLibIndex = "1\0";
    16801817    }
     
    16941831        if(pBase)
    16951832        {
     1833          /* retrieve file size */
     1834          DWORD dwTLBLength = GetFileSize(hFile, NULL);
     1835
    16961836          /* first try to load as *.tlb */
    16971837          dwSignature = *((DWORD*) pBase);
    16981838          if ( dwSignature == MSFT_SIGNATURE)
    16991839          {
    1700                 /* retrieve file size */
    1701                 DWORD dwTLBLength = GetFileSize(hFile, NULL);
    1702 
    1703             *ppTypeLib = ITypeLib2_Constructor(pBase, dwTLBLength);
     1840            *ppTypeLib = ITypeLib2_Constructor_MSFT(pBase, dwTLBLength);
    17041841            ITypeLib2_AddRef(*ppTypeLib);
    17051842          }
     1843          else if ( dwSignature == SLTG_SIGNATURE)
     1844          {
     1845            *ppTypeLib = ITypeLib2_Constructor_SLTG(pBase, dwTLBLength);
     1846            ITypeLib2_AddRef(*ppTypeLib);
     1847          }
    17061848          UnmapViewOfFile(pBase);
    17071849        }
     
    17261868            LPVOID pBase = LockResource(hGlobal);
    17271869            DWORD  dwTLBLength = SizeofResource(hinstDLL, hrsrc);
    1728 
     1870           
    17291871            if (pBase)
    17301872            {
     
    17331875              if ( dwSignature == MSFT_SIGNATURE)
    17341876              {
    1735                   *ppTypeLib = ITypeLib2_Constructor(pBase, dwTLBLength);
     1877                  *ppTypeLib = ITypeLib2_Constructor_MSFT(pBase, dwTLBLength);
    17361878                  ITypeLib2_AddRef(*ppTypeLib);
    1737               }
     1879              }
     1880              else if ( dwSignature == SLTG_SIGNATURE)
     1881              {
     1882                  *ppTypeLib = ITypeLib2_Constructor_SLTG(pBase, dwTLBLength);
     1883                  ITypeLib2_AddRef(*ppTypeLib);
     1884              }
    17381885              else
    17391886              {
     
    17611908
    17621909/****************************************************************************
    1763  *  ITypeLib2_Constructor
    1764  *
    1765  * loading a typelib from a in-memory image
    1766  */
    1767 static ITypeLib2* ITypeLib2_Constructor(LPVOID pLib, DWORD dwTLBLength)
     1910 *      ITypeLib2_Constructor_MSFT
     1911 *
     1912 * loading an MSFT typelib from an in-memory image
     1913 */
     1914static ITypeLib2* ITypeLib2_Constructor_MSFT(LPVOID pLib, DWORD dwTLBLength)
    17681915{
    17691916    TLBContext cx;
    17701917    long lPSegDir;
    1771     TLB2Header tlbHeader;
    1772     TLBSegDir tlbSegDir;
     1918    MSFT_Header tlbHeader;
     1919    MSFT_SegDir tlbSegDir;
    17731920    ITypeLibImpl * pTypeLibImpl;
    17741921
     
    17871934    cx.pLibInfo = pTypeLibImpl;
    17881935    cx.length = dwTLBLength;
    1789 
     1936   
    17901937    /* read header */
    1791     TLB_Read((void*)&tlbHeader, sizeof(tlbHeader), &cx, 0);
     1938    MSFT_Read((void*)&tlbHeader, sizeof(tlbHeader), &cx, 0);
    17921939    TRACE("header:\n");
    17931940    TRACE("\tmagic1=0x%08x ,magic2=0x%08x\n",tlbHeader.magic1,tlbHeader.magic2 );
    17941941    if (memcmp(&tlbHeader.magic1,TLBMAGIC2,4)) {
    1795     FIXME("Header type magic 0x%08x not supported.\n",tlbHeader.magic1);
    1796     return NULL;
    1797     }
    1798     /* there is a small number of information here until the next important
     1942        FIXME("Header type magic 0x%08x not supported.\n",tlbHeader.magic1);
     1943        return NULL;
     1944    }
     1945    /* there is a small amount of information here until the next important
    17991946     * part:
    18001947     * the segment directory . Try to calculate the amount of data */
     
    18031950    /* now read the segment directory */
    18041951    TRACE("read segment directory (at %ld)\n",lPSegDir);
    1805     TLB_Read((void*)&tlbSegDir, sizeof(tlbSegDir), &cx, lPSegDir);
     1952    MSFT_Read((void*)&tlbSegDir, sizeof(tlbSegDir), &cx, lPSegDir); 
    18061953    cx.pTblDir = &tlbSegDir;
    18071954
     
    18101957    {
    18111958        ERR("cannot find the table directory, ptr=0x%lx\n",lPSegDir);
    1812     HeapFree(GetProcessHeap(),0,pTypeLibImpl);
    1813     return NULL;
     1959        HeapFree(GetProcessHeap(),0,pTypeLibImpl);
     1960        return NULL;
    18141961    }
    18151962
    18161963    /* now fill our internal data */
    18171964    /* TLIBATTR fields */
    1818     TLB_ReadGuid(&pTypeLibImpl->LibAttr.guid, tlbHeader.posguid, &cx);
     1965    MSFT_ReadGuid(&pTypeLibImpl->LibAttr.guid, tlbHeader.posguid, &cx);
    18191966    pTypeLibImpl->LibAttr.lcid = tlbHeader.lcid;
    18201967    pTypeLibImpl->LibAttr.syskind = tlbHeader.varflags & 0x0f; /* check the mask */
     
    18241971
    18251972    /* name, eventually add to a hash table */
    1826     pTypeLibImpl->Name = TLB_ReadName(&cx, tlbHeader.NameOffset);
     1973    pTypeLibImpl->Name = MSFT_ReadName(&cx, tlbHeader.NameOffset);
    18271974
    18281975    /* help info */
    1829     pTypeLibImpl->DocString = TLB_ReadString(&cx, tlbHeader.helpstring);
    1830     pTypeLibImpl->HelpFile = TLB_ReadString(&cx, tlbHeader.helpfile);
     1976    pTypeLibImpl->DocString = MSFT_ReadString(&cx, tlbHeader.helpstring);
     1977    pTypeLibImpl->HelpFile = MSFT_ReadString(&cx, tlbHeader.helpfile);
    18311978
    18321979    if( tlbHeader.varflags & HELPDLLFLAG)
    18331980    {
    18341981            int offset;
    1835             TLB_Read(&offset, sizeof(offset), &cx, sizeof(tlbHeader));
    1836             pTypeLibImpl->HelpStringDll = TLB_ReadString(&cx, offset);
     1982            MSFT_Read(&offset, sizeof(offset), &cx, sizeof(tlbHeader));
     1983            pTypeLibImpl->HelpStringDll = MSFT_ReadString(&cx, offset);
    18371984    }
    18381985
     
    18421989    if(tlbHeader.CustomDataOffset >= 0)
    18431990    {
    1844         pTypeLibImpl->ctCustData = TLB_CustData(&cx, tlbHeader.CustomDataOffset, &pTypeLibImpl->pCustData);
     1991        pTypeLibImpl->ctCustData = MSFT_CustData(&cx, tlbHeader.CustomDataOffset, &pTypeLibImpl->pCustData);
    18451992    }
    18461993
     
    18511998        INT16 td[4];
    18521999        pTypeLibImpl->pTypeDesc = TLB_Alloc( cTD * sizeof(TYPEDESC));
    1853         TLB_Read(td, sizeof(td), &cx, tlbSegDir.pTypdescTab.offset);
     2000        MSFT_Read(td, sizeof(td), &cx, tlbSegDir.pTypdescTab.offset);
    18542001        for(i=0; i<cTD; )
    1855     {
     2002        {
    18562003            /* FIXME: add several sanity checks here */
    18572004            pTypeLibImpl->pTypeDesc[i].vt = td[0] & VT_TYPEMASK;
    18582005            if(td[0] == VT_PTR || td[0] == VT_SAFEARRAY)
    1859         {
    1860             /* FIXME: check safearray */
     2006            {
     2007                /* FIXME: check safearray */
    18612008                if(td[3] < 0)
    18622009                    pTypeLibImpl->pTypeDesc[i].u.lptdesc= & stndTypeDesc[td[2]];
     
    18642011                    pTypeLibImpl->pTypeDesc[i].u.lptdesc= & pTypeLibImpl->pTypeDesc[td[2]/8];
    18652012            }
    1866         else if(td[0] == VT_CARRAY)
     2013            else if(td[0] == VT_CARRAY)
    18672014            {
    1868             /* array descr table here */
    1869             pTypeLibImpl->pTypeDesc[i].u.lpadesc = (void *)((int) td[2]);  /* temp store offset in*/
     2015                /* array descr table here */
     2016                pTypeLibImpl->pTypeDesc[i].u.lpadesc = (void *)((int) td[2]);  /* temp store offset in*/
    18702017            }
    18712018            else if(td[0] == VT_USERDEFINED)
    1872         {
     2019            {
    18732020                pTypeLibImpl->pTypeDesc[i].u.hreftype = MAKELONG(td[2],td[3]);
    18742021            }
    1875         if(++i<cTD) TLB_Read(td, sizeof(td), &cx, DO_NOT_SEEK);
     2022            if(++i<cTD) MSFT_Read(td, sizeof(td), &cx, DO_NOT_SEEK);
    18762023        }
    18772024
    18782025        /* second time around to fill the array subscript info */
    18792026        for(i=0;i<cTD;i++)
    1880     {
     2027        {
    18812028            if(pTypeLibImpl->pTypeDesc[i].vt != VT_CARRAY) continue;
    18822029            if(tlbSegDir.pArrayDescriptions.offset>0)
    1883         {
    1884                 TLB_Read(td, sizeof(td), &cx, tlbSegDir.pArrayDescriptions.offset + (int) pTypeLibImpl->pTypeDesc[i].u.lpadesc);
     2030            {
     2031                MSFT_Read(td, sizeof(td), &cx, tlbSegDir.pArrayDescriptions.offset + (int) pTypeLibImpl->pTypeDesc[i].u.lpadesc);
    18852032                pTypeLibImpl->pTypeDesc[i].u.lpadesc = TLB_Alloc(sizeof(ARRAYDESC)+sizeof(SAFEARRAYBOUND)*(td[3]-1));
    18862033
     
    18932040
    18942041                for(j = 0; j<td[2]; j++)
    1895         {
    1896                     TLB_Read(& pTypeLibImpl->pTypeDesc[i].u.lpadesc->rgbounds[j].cElements,
     2042                {
     2043                    MSFT_Read(& pTypeLibImpl->pTypeDesc[i].u.lpadesc->rgbounds[j].cElements,
    18972044                        sizeof(INT), &cx, DO_NOT_SEEK);
    1898                     TLB_Read(& pTypeLibImpl->pTypeDesc[i].u.lpadesc->rgbounds[j].lLbound,
     2045                    MSFT_Read(& pTypeLibImpl->pTypeDesc[i].u.lpadesc->rgbounds[j].lLbound,
    18992046                        sizeof(INT), &cx, DO_NOT_SEEK);
    19002047                }
    19012048            }
    1902         else
    1903         {
     2049            else
     2050            {
    19042051                pTypeLibImpl->pTypeDesc[i].u.lpadesc = NULL;
    19052052                ERR("didn't find array description data\n");
     
    19162063
    19172064        while(offset < tlbSegDir.pImpFiles.offset +tlbSegDir.pImpFiles.length)
    1918     {
     2065        {
    19192066            *ppImpLib = TLB_Alloc(sizeof(TLBImpLib));
    19202067            (*ppImpLib)->offset = offset - tlbSegDir.pImpFiles.offset;
    1921             TLB_Read(&oGuid, sizeof(INT), &cx, offset);
    1922 
    1923             TLB_Read(&(*ppImpLib)->lcid,          sizeof(LCID),   &cx, DO_NOT_SEEK);
    1924             TLB_Read(&(*ppImpLib)->wVersionMajor, sizeof(WORD),   &cx, DO_NOT_SEEK);
    1925             TLB_Read(&(*ppImpLib)->wVersionMinor, sizeof(WORD),   &cx, DO_NOT_SEEK);
    1926             TLB_Read(& size,                      sizeof(UINT16), &cx, DO_NOT_SEEK);
     2068            MSFT_Read(&oGuid, sizeof(INT), &cx, offset);
     2069
     2070            MSFT_Read(&(*ppImpLib)->lcid,          sizeof(LCID),   &cx, DO_NOT_SEEK);
     2071            MSFT_Read(&(*ppImpLib)->wVersionMajor, sizeof(WORD),   &cx, DO_NOT_SEEK);
     2072            MSFT_Read(&(*ppImpLib)->wVersionMinor, sizeof(WORD),   &cx, DO_NOT_SEEK);
     2073            MSFT_Read(& size,                      sizeof(UINT16), &cx, DO_NOT_SEEK);
    19272074
    19282075            size >>= 2;
    19292076            (*ppImpLib)->name = TLB_Alloc(size+1);
    1930             TLB_Read((*ppImpLib)->name, size, &cx, DO_NOT_SEEK);
    1931             TLB_ReadGuid(&(*ppImpLib)->guid, oGuid, &cx);
     2077            MSFT_Read((*ppImpLib)->name, size, &cx, DO_NOT_SEEK);
     2078            MSFT_ReadGuid(&(*ppImpLib)->guid, oGuid, &cx);
    19322079            offset = (offset + sizeof(INT) + sizeof(DWORD) + sizeof(LCID) + sizeof(UINT16) + size + 3) & 0xfffffffc;
    19332080
     
    19452092        for(i = 0; i<(int)tlbHeader.nrtypeinfos; i++)
    19462093        {
    1947             *ppTI = TLB_DoTypeInfo(&cx, i, pTypeLibImpl);
     2094            *ppTI = MSFT_DoTypeInfo(&cx, i, pTypeLibImpl);
    19482095
    19492096            ITypeInfo_AddRef((ITypeInfo*) *ppTI);
     
    19572104}
    19582105
     2106
     2107static BSTR TLB_MultiByteToBSTR(char *ptr)
     2108{
     2109    DWORD len;
     2110    WCHAR *nameW;
     2111    BSTR ret;
     2112
     2113    len = MultiByteToWideChar(CP_ACP, 0, ptr, -1, NULL, 0);
     2114    nameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
     2115    MultiByteToWideChar(CP_ACP, 0, ptr, -1, nameW, len);
     2116    ret = SysAllocString(nameW);
     2117    HeapFree(GetProcessHeap(), 0, nameW);
     2118    return ret;
     2119}
     2120
     2121static BOOL TLB_GUIDFromString(char *str, GUID *guid)
     2122{
     2123  char b[3];
     2124  int i;
     2125  short s;
     2126
     2127  if(sscanf(str, "%lx-%hx-%hx-%hx", &guid->Data1, &guid->Data2, &guid->Data3, &s) != 4) {
     2128    FIXME("Can't parse guid %s\n", debugstr_guid(guid));
     2129    return FALSE;
     2130  }
     2131
     2132  guid->Data4[0] = s >> 8;
     2133  guid->Data4[1] = s & 0xff;
     2134
     2135  b[2] = '\0';
     2136  for(i = 0; i < 6; i++) {
     2137    memcpy(b, str + 24 + 2 * i, 2);
     2138    guid->Data4[i + 2] = strtol(b, NULL, 16);
     2139  }
     2140  return TRUE;
     2141}
     2142
     2143static WORD SLTG_ReadString(char *ptr, BSTR *pBstr)
     2144{
     2145    WORD bytelen;
     2146    DWORD len;
     2147    WCHAR *nameW;
     2148
     2149    *pBstr = NULL;
     2150    bytelen = *(WORD*)ptr;
     2151    if(bytelen == 0xffff) return 2;
     2152    len = MultiByteToWideChar(CP_ACP, 0, ptr + 2, bytelen, NULL, 0);
     2153    nameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
     2154    len = MultiByteToWideChar(CP_ACP, 0, ptr + 2, bytelen, nameW, len);
     2155    *pBstr = SysAllocStringLen(nameW, len);
     2156    HeapFree(GetProcessHeap(), 0, nameW);
     2157    return bytelen + 2;
     2158}
     2159
     2160static WORD SLTG_ReadStringA(char *ptr, char **str)
     2161{
     2162    WORD bytelen;
     2163
     2164    *str = NULL;
     2165    bytelen = *(WORD*)ptr;
     2166    if(bytelen == 0xffff) return 2;
     2167    *str = HeapAlloc(GetProcessHeap(), 0, bytelen + 1);
     2168    memcpy(*str, ptr + 2, bytelen);
     2169    (*str)[bytelen] = '\0';
     2170    return bytelen + 2;
     2171}
     2172
     2173static DWORD SLTG_ReadLibBlk(LPVOID pLibBlk, ITypeLibImpl *pTypeLibImpl)
     2174{
     2175    char *ptr = pLibBlk;
     2176    WORD w;
     2177
     2178    if((w = *(WORD*)ptr) != SLTG_LIBBLK_MAGIC) {
     2179        FIXME("libblk magic = %04x\n", w);
     2180        return 0;
     2181    }
     2182
     2183    ptr += 6;
     2184    if((w = *(WORD*)ptr) != 0xffff) {
     2185        FIXME("LibBlk.res06 = %04x. Assumung string and skipping\n", w);
     2186        ptr += w;
     2187    }
     2188    ptr += 2;
     2189
     2190    ptr += SLTG_ReadString(ptr, &pTypeLibImpl->DocString);
     2191
     2192    ptr += SLTG_ReadString(ptr, &pTypeLibImpl->HelpFile);
     2193
     2194    pTypeLibImpl->dwHelpContext = *(DWORD*)ptr;
     2195    ptr += 4;
     2196
     2197    pTypeLibImpl->LibAttr.syskind = *(WORD*)ptr;
     2198    ptr += 2;
     2199
     2200    pTypeLibImpl->LibAttr.lcid = *(WORD*)ptr;
     2201    ptr += 2;
     2202
     2203    ptr += 4; /* skip res12 */
     2204
     2205    pTypeLibImpl->LibAttr.wLibFlags = *(WORD*)ptr;
     2206    ptr += 2;
     2207
     2208    pTypeLibImpl->LibAttr.wMajorVerNum = *(WORD*)ptr;
     2209    ptr += 2;
     2210
     2211    pTypeLibImpl->LibAttr.wMinorVerNum = *(WORD*)ptr;
     2212    ptr += 2;
     2213
     2214    memcpy(&pTypeLibImpl->LibAttr.guid, ptr, sizeof(GUID));
     2215    ptr += sizeof(GUID);
     2216
     2217    return ptr - (char*)pLibBlk;
     2218}
     2219
     2220static WORD *SLTG_DoType(WORD *pType, char *pBlk, ELEMDESC *pElem)
     2221{
     2222    BOOL done = FALSE;
     2223    TYPEDESC *pTD = &pElem->tdesc;
     2224
     2225    /* Handle [in/out] first */
     2226    if((*pType & 0xc000) == 0xc000)
     2227        pElem->u.paramdesc.wParamFlags = PARAMFLAG_NONE;
     2228    else if(*pType & 0x8000)
     2229        pElem->u.paramdesc.wParamFlags = PARAMFLAG_FIN | PARAMFLAG_FOUT;
     2230    else if(*pType & 0x4000)
     2231        pElem->u.paramdesc.wParamFlags = PARAMFLAG_FOUT;
     2232    else
     2233        pElem->u.paramdesc.wParamFlags = PARAMFLAG_FIN;
     2234
     2235    if(*pType & 0x2000)
     2236        pElem->u.paramdesc.wParamFlags |= PARAMFLAG_FLCID;
     2237
     2238    if(*pType & 0x80)
     2239        pElem->u.paramdesc.wParamFlags |= PARAMFLAG_FRETVAL;
     2240
     2241    while(!done) {
     2242        if((*pType & 0xe00) == 0xe00) {
     2243            pTD->vt = VT_PTR;
     2244            pTD->u.lptdesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
     2245                                       sizeof(TYPEDESC));
     2246            pTD = pTD->u.lptdesc;
     2247        }
     2248        switch(*pType & 0x7f) {
     2249        case VT_PTR:
     2250            pTD->vt = VT_PTR;
     2251            pTD->u.lptdesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
     2252                                       sizeof(TYPEDESC));
     2253            pTD = pTD->u.lptdesc;
     2254            break;
     2255
     2256        case VT_USERDEFINED:
     2257            pTD->vt = VT_USERDEFINED;
     2258            pTD->u.hreftype = *(++pType) / 4;
     2259            done = TRUE;
     2260            break;
     2261
     2262        case VT_CARRAY:
     2263          {
     2264            /* *(pType+1) is offset to a SAFEARRAY, *(pType+2) is type of
     2265               array */
     2266
     2267            SAFEARRAY *pSA = (SAFEARRAY *)(pBlk + *(++pType));
     2268
     2269            pTD->vt = VT_CARRAY;
     2270            pTD->u.lpadesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
     2271                                sizeof(ARRAYDESC) +
     2272                                (pSA->cDims - 1) * sizeof(SAFEARRAYBOUND));
     2273            pTD->u.lpadesc->cDims = pSA->cDims;
     2274            memcpy(pTD->u.lpadesc->rgbounds, pSA->rgsabound,
     2275                   pSA->cDims * sizeof(SAFEARRAYBOUND));
     2276
     2277            pTD = &pTD->u.lpadesc->tdescElem;
     2278            break;
     2279          }
     2280
     2281        case VT_SAFEARRAY:
     2282          {
     2283            /* FIXME: *(pType+1) gives an offset to SAFEARRAY, is this
     2284               useful? */
     2285
     2286            pType++;
     2287            pTD->vt = VT_SAFEARRAY;
     2288            pTD->u.lptdesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
     2289                                       sizeof(TYPEDESC));
     2290            pTD = pTD->u.lptdesc;
     2291            break;
     2292          }
     2293        default:
     2294            pTD->vt = *pType & 0x7f;
     2295            done = TRUE;
     2296            break;
     2297        }
     2298        pType++;
     2299    }
     2300    return pType;
     2301}
     2302
     2303
     2304static void SLTG_DoRefs(SLTG_RefInfo *pRef, ITypeInfoImpl *pTI,
     2305                        char *pNameTable)
     2306{
     2307    int ref;
     2308    char *name;
     2309    TLBRefType **ppRefType;
     2310
     2311    if(pRef->magic != SLTG_REF_MAGIC) {
     2312        FIXME("Ref magic = %x\n", pRef->magic);
     2313        return;
     2314    }
     2315    name = ( (char*)(&pRef->names) + pRef->number);
     2316
     2317    ppRefType = &pTI->reflist;
     2318    for(ref = 0; ref < pRef->number >> 3; ref++) {
     2319        char *refname;
     2320        unsigned int lib_offs, type_num;
     2321
     2322        *ppRefType = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
     2323                               sizeof(**ppRefType));
     2324
     2325        name += SLTG_ReadStringA(name, &refname);
     2326        if(sscanf(refname, "*\\R%x*#%x", &lib_offs, &type_num) != 2)
     2327            FIXME("Can't sscanf ref\n");
     2328        if(lib_offs != 0xffff) {
     2329            TLBImpLib **import = &pTI->pTypeLib->pImpLibs;
     2330
     2331            while(*import) {
     2332                if((*import)->offset == lib_offs)
     2333                    break;
     2334                import = &(*import)->next;
     2335            }
     2336            if(!*import) {
     2337                char fname[MAX_PATH+1];
     2338                int len;
     2339
     2340                *import = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
     2341                                    sizeof(**import));
     2342                (*import)->offset = lib_offs;
     2343                TLB_GUIDFromString( pNameTable + lib_offs + 4,
     2344                                    &(*import)->guid);
     2345                if(sscanf(pNameTable + lib_offs + 40, "}#%hd.%hd#%lx#%s",
     2346                          &(*import)->wVersionMajor,
     2347                          &(*import)->wVersionMinor,
     2348                          &(*import)->lcid, fname) != 4) {
     2349                  FIXME("can't sscanf ref %s\n",
     2350                        pNameTable + lib_offs + 40);
     2351                }
     2352                len = strlen(fname);
     2353                if(fname[len-1] != '#')
     2354                    FIXME("fname = %s\n", fname);
     2355                fname[len-1] = '\0';
     2356                (*import)->name = TLB_MultiByteToBSTR(fname);
     2357            }
     2358            (*ppRefType)->pImpTLInfo = *import;
     2359        } else { /* internal ref */
     2360          (*ppRefType)->pImpTLInfo = TLB_REF_INTERNAL;
     2361        }
     2362        (*ppRefType)->reference = ref;
     2363        (*ppRefType)->index = type_num;
     2364
     2365        HeapFree(GetProcessHeap(), 0, refname);
     2366        ppRefType = &(*ppRefType)->next;
     2367    }
     2368    if((BYTE)*name != SLTG_REF_MAGIC)
     2369      FIXME("End of ref block magic = %x\n", *name);
     2370    dump_TLBRefType(pTI->reflist);
     2371}
     2372
     2373static char *SLTG_DoImpls(SLTG_ImplInfo *info, ITypeInfoImpl *pTI,
     2374                          BOOL OneOnly)
     2375{
     2376    TLBImplType **ppImplType = &pTI->impltypelist;
     2377
     2378    while(1) {
     2379        *ppImplType = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
     2380                                sizeof(**ppImplType));
     2381        (*ppImplType)->hRef = info->ref;
     2382        (*ppImplType)->implflags = info->impltypeflags;
     2383        pTI->TypeAttr.cImplTypes++;
     2384        ppImplType = &(*ppImplType)->next;
     2385
     2386        if(info->next == 0xffff)
     2387            break;
     2388        if(OneOnly)
     2389            FIXME("Interface inheriting more than one interface\n");
     2390        info++;
     2391    }
     2392    info++;
     2393    return (char*)info;
     2394}
     2395
     2396static void SLTG_ProcessCoClass(char *pBlk, ITypeInfoImpl *pTI,
     2397                                char *pNameTable)
     2398{
     2399    SLTG_TypeInfoHeader *pTIHeader = (SLTG_TypeInfoHeader*)pBlk;
     2400    SLTG_MemberHeader *pMemHeader;
     2401    char *pFirstItem, *pNextItem;
     2402
     2403    if(pTIHeader->href_table != 0xffffffff) {
     2404        SLTG_DoRefs((SLTG_RefInfo*)(pBlk + pTIHeader->href_table), pTI,
     2405                    pNameTable);
     2406    }
     2407
     2408
     2409    pMemHeader = (SLTG_MemberHeader*)(pBlk + pTIHeader->elem_table);
     2410
     2411    pFirstItem = pNextItem = (char*)(pMemHeader + 1);
     2412
     2413    if(*(WORD*)pFirstItem == SLTG_IMPL_MAGIC) {
     2414        pNextItem = SLTG_DoImpls((SLTG_ImplInfo*)pFirstItem, pTI, FALSE);
     2415    }
     2416
     2417    return;
     2418}
     2419
     2420
     2421static void SLTG_ProcessInterface(char *pBlk, ITypeInfoImpl *pTI,
     2422                                  char *pNameTable)
     2423{
     2424    SLTG_TypeInfoHeader *pTIHeader = (SLTG_TypeInfoHeader*)pBlk;
     2425    SLTG_MemberHeader *pMemHeader;
     2426    SLTG_Function *pFunc;
     2427    char *pFirstItem, *pNextItem;
     2428    TLBFuncDesc **ppFuncDesc = &pTI->funclist;
     2429    int num = 0;
     2430
     2431    if(pTIHeader->href_table != 0xffffffff) {
     2432        SLTG_DoRefs((SLTG_RefInfo*)(pBlk + pTIHeader->href_table), pTI,
     2433                    pNameTable);
     2434    }
     2435
     2436    pMemHeader = (SLTG_MemberHeader*)(pBlk + pTIHeader->elem_table);
     2437
     2438    pFirstItem = pNextItem = (char*)(pMemHeader + 1);
     2439
     2440    if(*(WORD*)pFirstItem == SLTG_IMPL_MAGIC) {
     2441        pNextItem = SLTG_DoImpls((SLTG_ImplInfo*)pFirstItem, pTI, TRUE);
     2442    }
     2443
     2444    for(pFunc = (SLTG_Function*)pNextItem, num = 1; 1;
     2445        pFunc = (SLTG_Function*)(pFirstItem + pFunc->next), num++) {
     2446
     2447        int param;
     2448        WORD *pType, *pArg;
     2449
     2450        if(pFunc->magic != SLTG_FUNCTION_MAGIC &&
     2451           pFunc->magic != SLTG_FUNCTION_WITH_FLAGS_MAGIC) {
     2452            FIXME("func magic = %02x\n", pFunc->magic);
     2453            return;
     2454        }
     2455        *ppFuncDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
     2456                                sizeof(**ppFuncDesc));
     2457        (*ppFuncDesc)->Name = TLB_MultiByteToBSTR(pFunc->name + pNameTable);
     2458
     2459        (*ppFuncDesc)->funcdesc.memid = pFunc->dispid;
     2460        (*ppFuncDesc)->funcdesc.invkind = pFunc->inv >> 4;
     2461        (*ppFuncDesc)->funcdesc.callconv = pFunc->nacc & 0x7;
     2462        (*ppFuncDesc)->funcdesc.cParams = pFunc->nacc >> 3;
     2463        (*ppFuncDesc)->funcdesc.cParamsOpt = (pFunc->retnextopt & 0x7e) >> 1;
     2464        (*ppFuncDesc)->funcdesc.oVft = pFunc->vtblpos;
     2465
     2466        if(pFunc->magic == SLTG_FUNCTION_WITH_FLAGS_MAGIC)
     2467            (*ppFuncDesc)->funcdesc.wFuncFlags = pFunc->funcflags;
     2468
     2469        if(pFunc->retnextopt & 0x80)
     2470            pType = &pFunc->rettype;
     2471        else
     2472            pType = (WORD*)(pFirstItem + pFunc->rettype);
     2473
     2474
     2475        SLTG_DoType(pType, pFirstItem, &(*ppFuncDesc)->funcdesc.elemdescFunc);
     2476
     2477        (*ppFuncDesc)->funcdesc.lprgelemdescParam =
     2478          HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
     2479                    (*ppFuncDesc)->funcdesc.cParams * sizeof(ELEMDESC));
     2480        (*ppFuncDesc)->pParamDesc =
     2481          HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
     2482                    (*ppFuncDesc)->funcdesc.cParams * sizeof(TLBParDesc));
     2483
     2484        pArg = (WORD*)(pFirstItem + pFunc->arg_off);
     2485
     2486        for(param = 0; param < (*ppFuncDesc)->funcdesc.cParams; param++) {
     2487            char *paramName = pNameTable + *pArg;
     2488            /* right, if the arg type follows then paramName points to the 2nd
     2489               letter of the name (or there is no name), else if the next
     2490               WORD is an offset to the arg type then paramName points to the
     2491               first letter. Before the name there always seems to be the byte
     2492               0xff or 0x00, so let's take one char off paramName and see what
     2493               we're pointing at.  Got that? */
     2494
     2495            if(*pArg == 0xffff) /* If we don't have a name the type seems to
     2496                                   always follow.  FIXME is this correct? */
     2497              paramName = NULL;
     2498
     2499            pArg++;
     2500
     2501            if(paramName &&
     2502               (*(paramName-1) == '\xff' ||
     2503                *(paramName-1) == '\x00')) { /* the next word is an offset to
     2504                                              the type */
     2505                pType = (WORD*)(pFirstItem + *pArg);
     2506                SLTG_DoType(pType, pFirstItem,
     2507                            &(*ppFuncDesc)->funcdesc.lprgelemdescParam[param]);
     2508                pArg++;
     2509            } else {
     2510                if(paramName)
     2511                  paramName--;
     2512                pArg = SLTG_DoType(pArg, pFirstItem,
     2513                           &(*ppFuncDesc)->funcdesc.lprgelemdescParam[param]);
     2514            }
     2515
     2516            /* Are we an optional param ? */
     2517            if((*ppFuncDesc)->funcdesc.cParams - param <=
     2518               (*ppFuncDesc)->funcdesc.cParamsOpt)
     2519              (*ppFuncDesc)->funcdesc.lprgelemdescParam[param].u.paramdesc.wParamFlags |= PARAMFLAG_FOPT;
     2520
     2521            if(paramName) {
     2522                (*ppFuncDesc)->pParamDesc[param].Name =
     2523                  TLB_MultiByteToBSTR(paramName);
     2524            }
     2525        }
     2526       
     2527        ppFuncDesc = &((*ppFuncDesc)->next);
     2528        if(pFunc->next == 0xffff) break;
     2529    }
     2530    pTI->TypeAttr.cFuncs = num;
     2531    dump_TLBFuncDesc(pTI->funclist);
     2532}
     2533
     2534static void SLTG_ProcessRecord(char *pBlk, ITypeInfoImpl *pTI, char *pNameTable)
     2535{
     2536  SLTG_TypeInfoHeader *pTIHeader = (SLTG_TypeInfoHeader*)pBlk;
     2537  SLTG_MemberHeader *pMemHeader;
     2538  SLTG_RecordItem *pItem;
     2539  char *pFirstItem;
     2540  TLBVarDesc **ppVarDesc = &pTI->varlist;
     2541  int num = 0;
     2542  WORD *pType;
     2543  char buf[300];
     2544
     2545  pMemHeader = (SLTG_MemberHeader*)(pBlk + pTIHeader->elem_table);
     2546
     2547  pFirstItem = (char*)(pMemHeader + 1);
     2548  for(pItem = (SLTG_RecordItem *)pFirstItem, num = 1; 1;
     2549      pItem = (SLTG_RecordItem *)(pFirstItem + pItem->next), num++) {
     2550      if(pItem->magic != SLTG_RECORD_MAGIC) {
     2551          FIXME("record magic = %02x\n", pItem->magic);
     2552          return;
     2553      }
     2554      *ppVarDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
     2555                             sizeof(**ppVarDesc));
     2556      (*ppVarDesc)->Name = TLB_MultiByteToBSTR(pItem->name + pNameTable);
     2557      (*ppVarDesc)->vardesc.memid = pItem->memid;
     2558      (*ppVarDesc)->vardesc.u.oInst = pItem->byte_offs;
     2559      (*ppVarDesc)->vardesc.varkind = VAR_PERINSTANCE;
     2560
     2561      if(pItem->typepos == 0x02)
     2562          pType = &pItem->type;
     2563      else if(pItem->typepos == 0x00)
     2564          pType = (WORD*)(pFirstItem + pItem->type);
     2565      else {
     2566          FIXME("typepos = %02x\n", pItem->typepos);
     2567          break;
     2568      }
     2569
     2570      SLTG_DoType(pType, pFirstItem,
     2571                  &(*ppVarDesc)->vardesc.elemdescVar);
     2572
     2573      /* FIXME("helpcontext, helpstring\n"); */
     2574
     2575      dump_TypeDesc(&(*ppVarDesc)->vardesc.elemdescVar.tdesc, buf);
     2576
     2577      ppVarDesc = &((*ppVarDesc)->next);
     2578      if(pItem->next == 0xffff) break;
     2579  }
     2580  pTI->TypeAttr.cVars = num;
     2581}
     2582
     2583static void SLTG_ProcessEnum(char *pBlk, ITypeInfoImpl *pTI, char *pNameTable)
     2584{
     2585  SLTG_TypeInfoHeader *pTIHeader = (SLTG_TypeInfoHeader*)pBlk;
     2586  SLTG_MemberHeader *pMemHeader;
     2587  SLTG_EnumItem *pItem;
     2588  char *pFirstItem;
     2589  TLBVarDesc **ppVarDesc = &pTI->varlist;
     2590  int num = 0;
     2591
     2592  pMemHeader = (SLTG_MemberHeader*)(pBlk + pTIHeader->elem_table);
     2593
     2594  pFirstItem = (char*)(pMemHeader + 1);
     2595  for(pItem = (SLTG_EnumItem *)pFirstItem, num = 1; 1;
     2596      pItem = (SLTG_EnumItem *)(pFirstItem + pItem->next), num++) {
     2597      if(pItem->magic != SLTG_ENUMITEM_MAGIC) {
     2598          FIXME("enumitem magic = %04x\n", pItem->magic);
     2599          return;
     2600      }
     2601      *ppVarDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
     2602                             sizeof(**ppVarDesc));
     2603      (*ppVarDesc)->Name = TLB_MultiByteToBSTR(pItem->name + pNameTable);
     2604      (*ppVarDesc)->vardesc.memid = pItem->memid;
     2605      (*ppVarDesc)->vardesc.u.lpvarValue = HeapAlloc(GetProcessHeap(), 0,
     2606                                                     sizeof(VARIANT));
     2607      V_VT((*ppVarDesc)->vardesc.u.lpvarValue) = VT_INT;
     2608      V_UNION((*ppVarDesc)->vardesc.u.lpvarValue, intVal) =
     2609        *(INT*)(pItem->value + pFirstItem);
     2610      (*ppVarDesc)->vardesc.elemdescVar.tdesc.vt = VT_I4;
     2611      (*ppVarDesc)->vardesc.varkind = VAR_CONST;
     2612      /* FIXME("helpcontext, helpstring\n"); */
     2613
     2614      ppVarDesc = &((*ppVarDesc)->next);
     2615      if(pItem->next == 0xffff) break;
     2616  }
     2617  pTI->TypeAttr.cVars = num;
     2618}
     2619
     2620/* Because SLTG_OtherTypeInfo is such a painfull struct, we make a more
     2621   managable copy of it into this */
     2622typedef struct {
     2623  WORD small_no;
     2624  char *index_name;
     2625  char *other_name;
     2626  WORD res1a;
     2627  WORD name_offs;
     2628  WORD more_bytes;
     2629  char *extra;
     2630  WORD res20;
     2631  DWORD helpcontext;
     2632  WORD res26;
     2633  GUID uuid;
     2634} SLTG_InternalOtherTypeInfo;
     2635
     2636/****************************************************************************
     2637 *      ITypeLib2_Constructor_SLTG
     2638 *
     2639 * loading a SLTG typelib from an in-memory image
     2640 */
     2641static ITypeLib2* ITypeLib2_Constructor_SLTG(LPVOID pLib, DWORD dwTLBLength)
     2642{
     2643    ITypeLibImpl *pTypeLibImpl;
     2644    SLTG_Header *pHeader;
     2645    SLTG_BlkEntry *pBlkEntry;
     2646    SLTG_Magic *pMagic;
     2647    SLTG_Index *pIndex;
     2648    SLTG_Pad9 *pPad9;
     2649    LPVOID pBlk, pFirstBlk;
     2650    SLTG_LibBlk *pLibBlk;
     2651    SLTG_InternalOtherTypeInfo *pOtherTypeInfoBlks;
     2652    char *pAfterOTIBlks = NULL;
     2653    char *pNameTable, *ptr;
     2654    int i;
     2655    DWORD len, order;
     2656    ITypeInfoImpl **ppTypeInfoImpl;
     2657
     2658    TRACE("%p, TLB length = %ld\n", pLib, dwTLBLength);
     2659
     2660    pTypeLibImpl = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ITypeLibImpl));
     2661    if (!pTypeLibImpl) return NULL;
     2662
     2663    ICOM_VTBL(pTypeLibImpl) = &tlbvt;
     2664    pTypeLibImpl->ref = 1;
     2665
     2666    pHeader = pLib;
     2667   
     2668    TRACE("header:\n");
     2669    TRACE("\tmagic=0x%08lx, file blocks = %d\n", pHeader->SLTG_magic,
     2670          pHeader->nrOfFileBlks );
     2671    if (memcmp(&pHeader->SLTG_magic, TLBMAGIC1, 4)) {
     2672        FIXME("Header type magic 0x%08lx not supported.\n",
     2673              pHeader->SLTG_magic);
     2674        return NULL;
     2675    }
     2676   
     2677    /* There are pHeader->nrOfFileBlks - 2 TypeInfo records in this typelib */
     2678    pTypeLibImpl->TypeInfoCount = pHeader->nrOfFileBlks - 2;
     2679
     2680    /* This points to pHeader->nrOfFileBlks - 1 of SLTG_BlkEntry */
     2681    pBlkEntry = (SLTG_BlkEntry*)(pHeader + 1);
     2682
     2683    /* Next we have a magic block */
     2684    pMagic = (SLTG_Magic*)(pBlkEntry + pHeader->nrOfFileBlks - 1);
     2685
     2686    /* Let's see if we're still in sync */
     2687    if(memcmp(pMagic->CompObj_magic, SLTG_COMPOBJ_MAGIC,
     2688              sizeof(SLTG_COMPOBJ_MAGIC))) {
     2689        FIXME("CompObj magic = %s\n", pMagic->CompObj_magic);
     2690        return NULL;
     2691    }
     2692    if(memcmp(pMagic->dir_magic, SLTG_DIR_MAGIC,
     2693              sizeof(SLTG_DIR_MAGIC))) {
     2694        FIXME("dir magic = %s\n", pMagic->dir_magic);
     2695        return NULL;
     2696    }
     2697
     2698    pIndex = (SLTG_Index*)(pMagic+1);
     2699
     2700    pPad9 = (SLTG_Pad9*)(pIndex + pTypeLibImpl->TypeInfoCount);
     2701
     2702    pFirstBlk = (LPVOID)(pPad9 + 1);
     2703
     2704    /* We'll set up a ptr to the main library block, which is the last one. */
     2705
     2706    for(pBlk = pFirstBlk, order = pHeader->first_blk - 1, i = 0;
     2707          pBlkEntry[order].next != 0;
     2708          order = pBlkEntry[order].next - 1, i++) {
     2709#ifdef __WIN32OS2__
     2710        pBlk = (LPBYTE)pBlk + pBlkEntry[order].len;
     2711#else
     2712        pBlk += pBlkEntry[order].len;
     2713#endif
     2714    }
     2715    pLibBlk = pBlk;
     2716
     2717    len = SLTG_ReadLibBlk(pLibBlk, pTypeLibImpl);
     2718
     2719    /* Now there's 0x40 bytes of 0xffff with the numbers 0 to TypeInfoCount
     2720       interspersed */
     2721
     2722    len += 0x40;
     2723
     2724    /* And now TypeInfoCount of SLTG_OtherTypeInfo */
     2725
     2726    pOtherTypeInfoBlks = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
     2727                                   sizeof(*pOtherTypeInfoBlks) *
     2728                                   pTypeLibImpl->TypeInfoCount);
     2729
     2730
     2731    ptr = (char*)pLibBlk + len;
     2732   
     2733    for(i = 0; i < pTypeLibImpl->TypeInfoCount; i++) {
     2734        WORD w, extra;
     2735        len = 0;
     2736
     2737        pOtherTypeInfoBlks[i].small_no = *(WORD*)ptr;
     2738
     2739        w = *(WORD*)(ptr + 2);
     2740        if(w != 0xffff) {
     2741            len += w;
     2742            pOtherTypeInfoBlks[i].index_name = HeapAlloc(GetProcessHeap(),0,
     2743                                                         w+1);
     2744            memcpy(pOtherTypeInfoBlks[i].index_name, ptr + 4, w);
     2745            pOtherTypeInfoBlks[i].index_name[w] = '\0';
     2746        }
     2747        w = *(WORD*)(ptr + 4 + len);
     2748        if(w != 0xffff) {
     2749            TRACE("\twith %s\n", debugstr_an(ptr + 6 + len, w));
     2750            len += w;
     2751            pOtherTypeInfoBlks[i].other_name = HeapAlloc(GetProcessHeap(),0,
     2752                                                         w+1);
     2753            memcpy(pOtherTypeInfoBlks[i].other_name, ptr + 6 + len, w);
     2754            pOtherTypeInfoBlks[i].other_name[w] = '\0';
     2755        }
     2756        pOtherTypeInfoBlks[i].res1a = *(WORD*)(ptr + len + 6);
     2757        pOtherTypeInfoBlks[i].name_offs = *(WORD*)(ptr + len + 8);
     2758        extra = pOtherTypeInfoBlks[i].more_bytes = *(WORD*)(ptr + 10 + len);
     2759        if(extra) {
     2760            pOtherTypeInfoBlks[i].extra = HeapAlloc(GetProcessHeap(),0,
     2761                                                    extra);
     2762            memcpy(pOtherTypeInfoBlks[i].extra, ptr + 12, extra);
     2763            len += extra;
     2764        }
     2765        pOtherTypeInfoBlks[i].res20 = *(WORD*)(ptr + 12 + len);
     2766        pOtherTypeInfoBlks[i].helpcontext = *(DWORD*)(ptr + 14 + len);
     2767        pOtherTypeInfoBlks[i].res26 = *(WORD*)(ptr + 18 + len);
     2768        memcpy(&pOtherTypeInfoBlks[i].uuid, ptr + 20 + len, sizeof(GUID));
     2769        len += sizeof(SLTG_OtherTypeInfo);
     2770        ptr += len;
     2771    }
     2772
     2773    pAfterOTIBlks = ptr;
     2774
     2775    /* Skip this WORD and get the next DWORD */
     2776    len = *(DWORD*)(pAfterOTIBlks + 2);
     2777
     2778    /* Now add this to pLibBLk and then add 0x216, sprinkle a bit a
     2779       magic dust and we should be pointing at the beginning of the name
     2780       table */
     2781
     2782    pNameTable = (char*)pLibBlk + len + 0x216;
     2783   
     2784    pNameTable += 2;
     2785
     2786    TRACE("Library name is %s\n", pNameTable + pLibBlk->name);
     2787
     2788    pTypeLibImpl->Name = TLB_MultiByteToBSTR(pNameTable + pLibBlk->name);
     2789
     2790
     2791    /* Hopefully we now have enough ptrs set up to actually read in
     2792       some TypeInfos.  It's not clear which order to do them in, so
     2793       I'll just follow the links along the BlkEntry chain and read
     2794       them in in the order in which they're in the file */
     2795
     2796    ppTypeInfoImpl = &(pTypeLibImpl->pTypeInfo);
     2797
     2798    for(pBlk = pFirstBlk, order = pHeader->first_blk - 1, i = 0;
     2799        pBlkEntry[order].next != 0;
     2800        order = pBlkEntry[order].next - 1, i++) {
     2801
     2802      SLTG_TypeInfoHeader *pTIHeader;
     2803
     2804      if(strcmp(pBlkEntry[order].index_string + (char*)pMagic,
     2805                pOtherTypeInfoBlks[i].index_name)) {
     2806        FIXME("Index strings don't match\n");
     2807        return NULL;
     2808      }
     2809
     2810      pTIHeader = pBlk;
     2811      if(pTIHeader->magic != SLTG_TIHEADER_MAGIC) {
     2812        FIXME("TypeInfoHeader magic = %04x\n", pTIHeader->magic);
     2813        return NULL;
     2814      }
     2815      *ppTypeInfoImpl = (ITypeInfoImpl*)ITypeInfo_Constructor();
     2816      (*ppTypeInfoImpl)->pTypeLib = pTypeLibImpl;
     2817      (*ppTypeInfoImpl)->index = i;
     2818      (*ppTypeInfoImpl)->Name = TLB_MultiByteToBSTR(
     2819                                             pOtherTypeInfoBlks[i].name_offs +
     2820                                             pNameTable);
     2821      (*ppTypeInfoImpl)->dwHelpContext = pOtherTypeInfoBlks[i].helpcontext;
     2822      memcpy(&((*ppTypeInfoImpl)->TypeAttr.guid), &pOtherTypeInfoBlks[i].uuid,
     2823             sizeof(GUID));
     2824      (*ppTypeInfoImpl)->TypeAttr.typekind = pTIHeader->typekind;
     2825      (*ppTypeInfoImpl)->TypeAttr.wMajorVerNum = pTIHeader->major_version;
     2826      (*ppTypeInfoImpl)->TypeAttr.wMinorVerNum = pTIHeader->minor_version;
     2827      (*ppTypeInfoImpl)->TypeAttr.wTypeFlags =
     2828        (pTIHeader->typeflags1 >> 3) | (pTIHeader->typeflags2 << 5);
     2829     
     2830      if((pTIHeader->typeflags1 & 7) != 2)
     2831        FIXME("typeflags1 = %02x\n", pTIHeader->typeflags1);
     2832      if(pTIHeader->typeflags3 != 2)
     2833        FIXME("typeflags3 = %02x\n", pTIHeader->typeflags3);
     2834
     2835      TRACE("TypeInfo %s of kind %s guid %s typeflags %04x\n",
     2836            debugstr_w((*ppTypeInfoImpl)->Name),
     2837            typekind_desc[pTIHeader->typekind],
     2838            debugstr_guid(&(*ppTypeInfoImpl)->TypeAttr.guid),
     2839            (*ppTypeInfoImpl)->TypeAttr.wTypeFlags);
     2840
     2841      switch(pTIHeader->typekind) {
     2842      case TKIND_ENUM:
     2843        SLTG_ProcessEnum(pBlk, *ppTypeInfoImpl, pNameTable);
     2844        break;
     2845
     2846      case TKIND_RECORD:
     2847        SLTG_ProcessRecord(pBlk, *ppTypeInfoImpl, pNameTable);
     2848        break;
     2849
     2850      case TKIND_INTERFACE:
     2851        SLTG_ProcessInterface(pBlk, *ppTypeInfoImpl, pNameTable);
     2852        break;
     2853
     2854      case TKIND_COCLASS:
     2855        SLTG_ProcessCoClass(pBlk, *ppTypeInfoImpl, pNameTable);
     2856        break;
     2857
     2858      default:
     2859        FIXME("Not processing typekind %d\n", pTIHeader->typekind);
     2860        break;
     2861
     2862      }
     2863
     2864      ppTypeInfoImpl = &((*ppTypeInfoImpl)->next);
     2865#ifdef __WIN32OS2__
     2866      pBlk = (LPBYTE)pBlk + pBlkEntry[order].len;
     2867#else
     2868      pBlk += pBlkEntry[order].len;
     2869#endif
     2870    }
     2871
     2872    if(i != pTypeLibImpl->TypeInfoCount) {
     2873      FIXME("Somehow processed %d TypeInfos\n", i);
     2874      return NULL;
     2875    }
     2876
     2877    HeapFree(GetProcessHeap(), 0, pOtherTypeInfoBlks);
     2878    return (ITypeLib2*)pTypeLibImpl;
     2879}
     2880
    19592881/* ITypeLib::QueryInterface
    19602882 */
    19612883static HRESULT WINAPI ITypeLib2_fnQueryInterface(
    1962     ITypeLib2 * iface,
    1963     REFIID riid,
    1964     VOID **ppvObject)
     2884        ITypeLib2 * iface,
     2885        REFIID riid,
     2886        VOID **ppvObject)
    19652887{
    19662888    ICOM_THIS( ITypeLibImpl, iface);
     
    19692891
    19702892    *ppvObject=NULL;
    1971     if(IsEqualIID(riid, &IID_IUnknown) ||
     2893    if(IsEqualIID(riid, &IID_IUnknown) || 
    19722894       IsEqualIID(riid,&IID_ITypeLib)||
    19732895       IsEqualIID(riid,&IID_ITypeLib2))
     
    20042926
    20052927    --(This->ref);
    2006 
     2928   
    20072929    TRACE("(%p)->(%u)\n",This, This->ref);
    20082930
     
    20362958          This->HelpStringDll = NULL;
    20372959      }
    2038 
     2960   
    20392961      ITypeInfo_Release((ITypeInfo*) This->pTypeInfo);
    20402962      HeapFree(GetProcessHeap(),0,This);
     
    20462968
    20472969/* ITypeLib::GetTypeInfoCount
    2048  *
     2970 * 
    20492971 * Returns the number of type descriptions in the type library
    20502972 */
     
    20622984static HRESULT WINAPI ITypeLib2_fnGetTypeInfo(
    20632985    ITypeLib2 *iface,
    2064     UINT index,
     2986    UINT index, 
    20652987    ITypeInfo **ppTInfo)
    20662988{
    20672989    int i;
    2068 
     2990   
    20692991    ICOM_THIS( ITypeLibImpl, iface);
    20702992    ITypeInfoImpl *pTypeInfo = This->pTypeInfo;
     
    20732995
    20742996    if (!ppTInfo) return E_INVALIDARG;
    2075 
     2997   
    20762998    /* search element n in list */
    20772999    for(i=0; i < index; i++)
     
    20833005        return TYPE_E_ELEMENTNOTFOUND;
    20843006      }
    2085     }
     3007    }   
    20863008
    20873009    *ppTInfo = (ITypeInfo *) pTypeInfo;
    2088 
     3010   
    20893011    ITypeInfo_AddRef(*ppTInfo);
    20903012    TRACE("-- found (%p)\n",*ppTInfo);
     
    21093031
    21103032    if(!pTKind) return E_INVALIDARG;
    2111 
     3033   
    21123034    /* search element n in list */
    21133035    for(i=0; i < index; i++)
     
    21563078    }
    21573079
    2158     TRACE("-- found (%p, %s)\n",
    2159           pTypeInfo,
     3080    TRACE("-- found (%p, %s)\n", 
     3081          pTypeInfo, 
    21603082          debugstr_w(pTypeInfo->Name));
    21613083
     
    21713093 */
    21723094static HRESULT WINAPI ITypeLib2_fnGetLibAttr(
    2173     ITypeLib2 *iface,
    2174     LPTLIBATTR *ppTLibAttr)
     3095        ITypeLib2 *iface,
     3096        LPTLIBATTR *ppTLibAttr)
    21753097{
    21763098    ICOM_THIS( ITypeLibImpl, iface);
     
    21883110 */
    21893111static HRESULT WINAPI ITypeLib2_fnGetTypeComp(
    2190     ITypeLib2 *iface,
    2191     ITypeComp **ppTComp)
     3112        ITypeLib2 *iface,
     3113        ITypeComp **ppTComp)
    21923114{
    21933115    ICOM_THIS( ITypeLibImpl, iface);
     
    22083130    BSTR *pBstrName,
    22093131    BSTR *pBstrDocString,
    2210     DWORD *pdwHelpContext,
     3132    DWORD *pdwHelpContext, 
    22113133    BSTR *pBstrHelpFile)
    22123134{
    22133135    ICOM_THIS( ITypeLibImpl, iface);
    2214 
     3136   
    22153137    HRESULT result = E_INVALIDARG;
    2216 
     3138   
    22173139    ITypeInfo *pTInfo;
    22183140
    2219 
     3141   
    22203142    TRACE("(%p) index %d Name(%p) DocString(%p) HelpContext(%p) HelpFile(%p)\n",
    22213143        This, index,
    2222         pBstrName, pBstrDocString,
     3144        pBstrName, pBstrDocString, 
    22233145        pdwHelpContext, pBstrHelpFile);
    2224 
     3146   
    22253147    if(index<0)
    2226     {
     3148    { 
    22273149       /* documentation for the typelib */
    22283150       if(pBstrName && This->Name)
     
    22383160           if (!(*pBstrDocString)) return STG_E_INSUFFICIENTMEMORY;
    22393161       }
    2240 
     3162   
    22413163       if(pdwHelpContext)
    22423164       {
     
    22523174       result = S_OK;
    22533175    }
    2254     else
     3176    else 
    22553177    {
    22563178        /* for a typeinfo */
     
    22593181        if(SUCCEEDED(result))
    22603182        {
    2261             result = ITypeInfo_GetDocumentation(pTInfo,
    2262                                           MEMBERID_NIL,
     3183            result = ITypeInfo_GetDocumentation(pTInfo, 
     3184                                          MEMBERID_NIL, 
    22633185                                          pBstrName,
    2264                                           pBstrDocString,
     3186                                          pBstrDocString, 
    22653187                                          pdwHelpContext, pBstrHelpFile);
    2266 
     3188           
    22673189            ITypeInfo_Release(pTInfo);
    22683190        }
     
    22783200 */
    22793201static HRESULT WINAPI ITypeLib2_fnIsName(
    2280     ITypeLib2 *iface,
    2281     LPOLESTR szNameBuf,
    2282     ULONG lHashVal,
    2283     BOOL *pfName)
     3202        ITypeLib2 *iface,
     3203        LPOLESTR szNameBuf,
     3204        ULONG lHashVal,
     3205        BOOL *pfName)
    22843206{
    22853207    ICOM_THIS( ITypeLibImpl, iface);
     
    22913213
    22923214    TRACE("(%p)->(%s,%08lx,%p)\n", This, debugstr_w(szNameBuf), lHashVal,
    2293       pfName);
     3215          pfName);
    22943216
    22953217    *pfName=TRUE;
     
    23043226        for(pVInfo=pTInfo->varlist;pVInfo;pVInfo=pVInfo->next)
    23053227            if(!memcmp(szNameBuf,pVInfo->Name, nNameBufLen)) goto ITypeLib2_fnIsName_exit;
    2306 
     3228       
    23073229    }
    23083230    *pfName=FALSE;
     
    23113233    TRACE("(%p)slow! search for %s: %s found!\n", This,
    23123234          debugstr_w(szNameBuf), *pfName?"NOT":"");
    2313 
     3235   
    23143236    return S_OK;
    23153237}
     
    23223244 */
    23233245static HRESULT WINAPI ITypeLib2_fnFindName(
    2324     ITypeLib2 *iface,
    2325     LPOLESTR szNameBuf,
    2326     ULONG lHashVal,
    2327     ITypeInfo **ppTInfo,
    2328     MEMBERID *rgMemId,
    2329     UINT16 *pcFound)
     3246        ITypeLib2 *iface,
     3247        LPOLESTR szNameBuf,
     3248        ULONG lHashVal,
     3249        ITypeInfo **ppTInfo,
     3250        MEMBERID *rgMemId,
     3251        UINT16 *pcFound)
    23303252{
    23313253    ICOM_THIS( ITypeLibImpl, iface);
     
    23343256    TLBVarDesc *pVInfo;
    23353257    int i,j = 0;
    2336 
     3258   
    23373259    UINT nNameBufLen = SysStringLen(szNameBuf);
    23383260
     
    23573279
    23583280    *pcFound=j;
    2359 
     3281   
    23603282    return S_OK;
    23613283}
     
    23673289 */
    23683290static VOID WINAPI ITypeLib2_fnReleaseTLibAttr(
    2369     ITypeLib2 *iface,
    2370     TLIBATTR *pTLibAttr)
     3291        ITypeLib2 *iface,
     3292        TLIBATTR *pTLibAttr)
    23713293{
    23723294    ICOM_THIS( ITypeLibImpl, iface);
     
    23803302 */
    23813303static HRESULT WINAPI ITypeLib2_fnGetCustData(
    2382     ITypeLib2 * iface,
    2383     REFGUID guid,
     3304        ITypeLib2 * iface,
     3305        REFGUID guid,
    23843306        VARIANT *pVarVal)
    23853307{
     
    23913313      if( IsEqualIID(guid, &pCData->guid)) break;
    23923314    }
    2393 
     3315   
    23943316    TRACE("(%p) guid %s %s found!x)\n", This, debugstr_guid(guid), pCData? "" : "NOT");
    23953317
     
    24103332 */
    24113333static HRESULT WINAPI ITypeLib2_fnGetLibStatistics(
    2412     ITypeLib2 * iface,
     3334        ITypeLib2 * iface,
    24133335        ULONG *pcUniqueNames,
    2414     ULONG *pcchUniqueNames)
     3336        ULONG *pcchUniqueNames)
    24153337{
    24163338    ICOM_THIS( ITypeLibImpl, iface);
     
    24313353 */
    24323354static HRESULT WINAPI ITypeLib2_fnGetDocumentation2(
    2433     ITypeLib2 * iface,
     3355        ITypeLib2 * iface,
    24343356        INT index,
    2435     LCID lcid,
    2436     BSTR *pbstrHelpString,
     3357        LCID lcid,
     3358        BSTR *pbstrHelpString,
    24373359        DWORD *pdwHelpStringContext,
    2438     BSTR *pbstrHelpStringDll)
     3360        BSTR *pbstrHelpStringDll)
    24393361{
    24403362    ICOM_THIS( ITypeLibImpl, iface);
     
    24643386      /* for a typeinfo */
    24653387      result=ITypeLib2_GetTypeInfo(iface, index, &pTInfo);
    2466 
     3388     
    24673389      if(SUCCEEDED(result))
    2468       {
     3390      { 
    24693391        ITypeInfo2 * pTInfo2;
    2470         result = ITypeInfo_QueryInterface(pTInfo,
    2471                                           &IID_ITypeInfo2,
     3392        result = ITypeInfo_QueryInterface(pTInfo, 
     3393                                          &IID_ITypeInfo2, 
    24723394                                          (LPVOID*) &pTInfo2);
    24733395
    24743396        if(SUCCEEDED(result))
    24753397        {
    2476           result = ITypeInfo2_GetDocumentation2(pTInfo2,
    2477                                            MEMBERID_NIL,
     3398          result = ITypeInfo2_GetDocumentation2(pTInfo2, 
     3399                                           MEMBERID_NIL, 
    24783400                                           lcid,
    2479                                            pbstrHelpString,
    2480                                            pdwHelpStringContext,
     3401                                           pbstrHelpString, 
     3402                                           pdwHelpStringContext, 
    24813403                                           pbstrHelpStringDll);
    2482 
     3404 
    24833405          ITypeInfo2_Release(pTInfo2);
    24843406        }
    2485 
     3407           
    24863408        ITypeInfo_Release(pTInfo);
    24873409      }
     
    24923414/* ITypeLib2::GetAllCustData
    24933415 *
    2494  * Gets all custom data items for the library.
     3416 * Gets all custom data items for the library. 
    24953417 *
    24963418 */
    24973419static HRESULT WINAPI ITypeLib2_fnGetAllCustData(
    2498     ITypeLib2 * iface,
     3420        ITypeLib2 * iface,
    24993421        CUSTDATA *pCustData)
    25003422{
     
    25023424    TLBCustData *pCData;
    25033425    int i;
    2504     TRACE("(%p) returning %d items\n", This, This->ctCustData);
     3426    TRACE("(%p) returning %d items\n", This, This->ctCustData); 
    25053427    pCustData->prgCustData = TLB_Alloc(This->ctCustData * sizeof(CUSTDATAITEM));
    25063428    if(pCustData->prgCustData ){
     
    25573479 */
    25583480static HRESULT WINAPI ITypeInfo_fnQueryInterface(
    2559     ITypeInfo2 *iface,
    2560     REFIID riid,
    2561     VOID **ppvObject)
     3481        ITypeInfo2 *iface,
     3482        REFIID riid,
     3483        VOID **ppvObject)
    25623484{
    25633485    ICOM_THIS( ITypeLibImpl, iface);
     
    25663488
    25673489    *ppvObject=NULL;
    2568     if(IsEqualIID(riid, &IID_IUnknown) ||
     3490    if(IsEqualIID(riid, &IID_IUnknown) || 
    25693491            IsEqualIID(riid,&IID_ITypeInfo)||
    25703492            IsEqualIID(riid,&IID_ITypeInfo2))
     
    25993521
    26003522    --(This->ref);
    2601 
     3523   
    26023524    TRACE("(%p)->(%u)\n",This, This->ref);
    26033525
     
    26063528      FIXME("destroy child objects\n");
    26073529
    2608       TRACE("destroying ITypeInfo(%p)\n",This);
     3530      TRACE("destroying ITypeInfo(%p)\n",This); 
    26093531      if (This->Name)
    26103532      {
     
    26123534          This->Name = 0;
    26133535      }
    2614 
     3536     
    26153537      if (This->DocString)
    26163538      {
     
    26713593    ICOM_THIS( ITypeInfoImpl, iface);
    26723594    int i;
    2673     TLBFuncDesc * pFDesc;
     3595    TLBFuncDesc * pFDesc; 
    26743596    TRACE("(%p) index %d\n", This, index);
    26753597    for(i=0, pFDesc=This->funclist; i!=index && pFDesc; i++, pFDesc=pFDesc->next)
     
    26853607/* ITypeInfo::GetVarDesc
    26863608 *
    2687  * Retrieves a VARDESC structure that describes the specified variable.
     3609 * Retrieves a VARDESC structure that describes the specified variable. 
    26883610 *
    26893611 */
     
    26933615    ICOM_THIS( ITypeInfoImpl, iface);
    26943616    int i;
    2695     TLBVarDesc * pVDesc;
     3617    TLBVarDesc * pVDesc; 
    26963618    TRACE("(%p) index %d\n", This, index);
    26973619    for(i=0, pVDesc=This->varlist; i!=index && pVDesc; i++, pVDesc=pVDesc->next)
     
    27153637{
    27163638    ICOM_THIS( ITypeInfoImpl, iface);
    2717     TLBFuncDesc * pFDesc;
    2718     TLBVarDesc * pVDesc;
     3639    TLBFuncDesc * pFDesc; 
     3640    TLBVarDesc * pVDesc; 
    27193641    int i;
    27203642    TRACE("(%p) memid=0x%08lx Maxname=%d\n", This, memid, cMaxNames);
     
    27263648      {
    27273649        if(!i)
    2728           *rgBstrNames=SysAllocString(pFDesc->Name);
     3650          *rgBstrNames=SysAllocString(pFDesc->Name);
    27293651        else
    27303652          rgBstrNames[i]=SysAllocString(pFDesc->pParamDesc[i-1].Name);
     
    27473669          ITypeInfo *pTInfo;
    27483670          HRESULT result;
    2749           result=ITypeInfo_GetRefTypeInfo(iface, This->impltypelist->reference, &pTInfo);
     3671          result=ITypeInfo_GetRefTypeInfo(iface, This->impltypelist->hRef,
     3672                                          &pTInfo);
    27503673          if(SUCCEEDED(result))
    2751       {
     3674          {
    27523675            result=ITypeInfo_GetNames(pTInfo, memid, rgBstrNames, cMaxNames, pcNames);
    27533676            ITypeInfo_Release(pTInfo);
     
    27573680        }
    27583681        else
    2759     {
     3682        {
    27603683          WARN("no names found\n");
    2761     }
     3684        }
    27623685        *pcNames=0;
    27633686        return TYPE_E_ELEMENTNOTFOUND;
     
    27773700 */
    27783701static HRESULT WINAPI ITypeInfo_fnGetRefTypeOfImplType(
    2779     ITypeInfo2 *iface,
     3702        ITypeInfo2 *iface,
    27803703        UINT index,
    2781     HREFTYPE  *pRefType)
     3704        HREFTYPE  *pRefType)
    27823705{
    27833706    ICOM_THIS( ITypeInfoImpl, iface);
    27843707    int(i);
    2785     TLBRefType *pIref = This->impltypelist;
     3708    TLBImplType *pImpl = This->impltypelist;
    27863709
    27873710    TRACE("(%p) index %d\n", This, index);
     
    27943717      */
    27953718      if( This->TypeAttr.typekind != TKIND_DISPATCH) return E_INVALIDARG;
    2796 
     3719     
    27973720      if (This->TypeAttr.wTypeFlags & TYPEFLAG_FDISPATCHABLE &&
    27983721          This->TypeAttr.wTypeFlags & TYPEFLAG_FDUAL )
     
    28023725      else
    28033726      {
    2804         if (!pIref) return TYPE_E_ELEMENTNOTFOUND;
    2805         *pRefType = pIref->reference;
     3727        if (!pImpl) return TYPE_E_ELEMENTNOTFOUND;
     3728        *pRefType = pImpl->hRef;
    28063729      }
    28073730    }
     
    28093732    {
    28103733      /* get element n from linked list */
    2811       for(i=0; pIref && i<index; i++)
     3734      for(i=0; pImpl && i<index; i++)
    28123735      {
    2813         pIref = pIref->next;
     3736        pImpl = pImpl->next;
    28143737      }
    2815 
    2816       if (!pIref) return TYPE_E_ELEMENTNOTFOUND;
    2817 
    2818       *pRefType = pIref->reference;
    2819 
    2820       TRACE("-- 0x%08lx %s\n",pIref->reference, debugstr_guid(&pIref->guid) );
    2821     }
    2822 
     3738     
     3739      if (!pImpl) return TYPE_E_ELEMENTNOTFOUND;
     3740     
     3741      *pRefType = pImpl->hRef;
     3742     
     3743      TRACE("-- 0x%08lx\n", pImpl->hRef );
     3744    }
     3745   
    28233746    return S_OK;
    2824 
     3747   
    28253748}
    28263749
    28273750/* ITypeInfo::GetImplTypeFlags
    2828  *
    2829  * Retrieves the IMPLTYPEFLAGS enumeration for one implemented interface
     3751 * 
     3752 * Retrieves the IMPLTYPEFLAGS enumeration for one implemented interface 
    28303753 * or base interface in a type description.
    28313754 */
     
    28343757{
    28353758    ICOM_THIS( ITypeInfoImpl, iface);
    2836     int(i);
    2837     TLBRefType *pIref;
     3759    int i;
     3760    TLBImplType *pImpl;
     3761
    28383762    TRACE("(%p) index %d\n", This, index);
    2839     for(i=0, pIref=This->impltypelist; i<index && pIref; i++, pIref=pIref->next)
     3763    for(i=0, pImpl=This->impltypelist; i<index && pImpl;
     3764        i++, pImpl=pImpl->next)
    28403765        ;
    2841     if(i==index && pIref){
    2842         *pImplTypeFlags=pIref->flags;
     3766    if(i==index && pImpl){
     3767        *pImplTypeFlags=pImpl->implflags;
    28433768        return S_OK;
    28443769    }
     
    28553780{
    28563781    ICOM_THIS( ITypeInfoImpl, iface);
    2857     TLBFuncDesc * pFDesc;
    2858     TLBVarDesc * pVDesc;
     3782    TLBFuncDesc * pFDesc; 
     3783    TLBVarDesc * pVDesc; 
    28593784    HRESULT ret=S_OK;
    2860     UINT nNameLen = SysStringLen(*rgszNames);
    2861 
     3785        UINT nNameLen = SysStringLen(*rgszNames);
     3786       
    28623787    TRACE("(%p) Name %s cNames %d\n", This, debugstr_w(*rgszNames),
    28633788            cNames);
     
    28673792            if(cNames) *pMemId=pFDesc->funcdesc.memid;
    28683793            for(i=1; i < cNames; i++){
    2869                 UINT nParamLen = SysStringLen(rgszNames[i]);
     3794                                UINT nParamLen = SysStringLen(rgszNames[i]);
    28703795                for(j=0; j<pFDesc->funcdesc.cParams; j++)
    28713796                    if(memcmp(rgszNames[i],pFDesc->pParamDesc[j].Name, nParamLen))
     
    28783803            return ret;
    28793804        }
    2880     }
     3805    }   
    28813806    for(pVDesc=This->varlist; pVDesc; pVDesc=pVDesc->next) {
    28823807        if( !memcmp(*rgszNames, pVDesc->Name, nNameLen)) {
     
    28853810        }
    28863811    }
    2887     /* not found, see if this is and interface with an inheritance */
    2888     if(This->TypeAttr.typekind==TKIND_INTERFACE &&
     3812    /* not found, see if this is and interface with an inheritance */       
     3813    if(This->TypeAttr.typekind==TKIND_INTERFACE && 
    28893814            This->TypeAttr.cImplTypes ){
    28903815        /* recursive search */
    28913816        ITypeInfo *pTInfo;
    2892         ret=ITypeInfo_GetRefTypeInfo(iface,
    2893                 This->impltypelist->reference, &pTInfo);
     3817        ret=ITypeInfo_GetRefTypeInfo(iface, 
     3818                This->impltypelist->hRef, &pTInfo);
    28943819        if(SUCCEEDED(ret)){
    28953820            ret=ITypeInfo_GetIDsOfNames(pTInfo, rgszNames, cNames, pMemId );
     
    29043829
    29053830/* ITypeInfo::Invoke
    2906  *
     3831 * 
    29073832 * Invokes a method, or accesses a property of an object, that implements the
    29083833 * interface described by the type description.
     
    29123837
    29133838    if (TRACE_ON(ole)) {
    2914     int i;
    2915     MESSAGE("Calling %p(",func);
    2916     for (i=0;i<nrargs;i++) MESSAGE("%08lx,",args[i]);
    2917     MESSAGE(")\n");
     3839        int i;
     3840        MESSAGE("Calling %p(",func);
     3841        for (i=0;i<nrargs;i++) MESSAGE("%08lx,",args[i]);
     3842        MESSAGE(")\n");
    29183843    }
    29193844
     
    29213846    case CC_STDCALL:
    29223847
    2923     switch (nrargs) {
    2924     case 0: {
     3848        switch (nrargs) {
     3849        case 0: {
    29253850#ifdef __WIN32OS2__
    2926         DWORD (* WINAPI xfunc)() = func;
     3851                DWORD (* WINAPI xfunc)() = func;
    29273852#else
    2928         DWORD (WINAPI *xfunc)() = func;
     3853                DWORD (WINAPI *xfunc)() = func;
    29293854#endif
    2930         res = xfunc();
    2931         break;
    2932     }
    2933     case 1: {
     3855                res = xfunc();
     3856                break;
     3857        }
     3858        case 1: {
    29343859#ifdef __WIN32OS2__
    2935         DWORD (* WINAPI xfunc)(DWORD) = func;
     3860                DWORD (* WINAPI xfunc)(DWORD) = func;
    29363861#else
    2937         DWORD (WINAPI *xfunc)(DWORD) = func;
     3862                DWORD (WINAPI *xfunc)(DWORD) = func;
    29383863#endif
    2939         res = xfunc(args[0]);
    2940         break;
    2941     }
    2942     case 2: {
     3864                res = xfunc(args[0]);
     3865                break;
     3866        }
     3867        case 2: {
    29433868#ifdef __WIN32OS2__
    2944         DWORD (* WINAPI xfunc)(DWORD,DWORD) = func;
     3869                DWORD (* WINAPI xfunc)(DWORD,DWORD) = func;
    29453870#else
    2946         DWORD (WINAPI *xfunc)(DWORD,DWORD) = func;
     3871                DWORD (WINAPI *xfunc)(DWORD,DWORD) = func;
    29473872#endif
    2948         res = xfunc(args[0],args[1]);
    2949         break;
    2950     }
    2951     case 3: {
     3873                res = xfunc(args[0],args[1]);
     3874                break;
     3875        }
     3876        case 3: {
    29523877#ifdef __WIN32OS2__
    2953         DWORD (* WINAPI xfunc)(DWORD,DWORD,DWORD) = func;
     3878                DWORD (* WINAPI xfunc)(DWORD,DWORD,DWORD) = func;
    29543879#else
    2955         DWORD (WINAPI *xfunc)(DWORD,DWORD,DWORD) = func;
     3880                DWORD (WINAPI *xfunc)(DWORD,DWORD,DWORD) = func;
    29563881#endif
    2957         res = xfunc(args[0],args[1],args[2]);
    2958         break;
    2959     }
     3882                res = xfunc(args[0],args[1],args[2]);
     3883                break;
     3884        }
     3885        default:
     3886                FIXME("unsupported number of arguments %d in stdcall\n",nrargs);
     3887                res = -1;
     3888                break;
     3889        }
     3890        break;
    29603891    default:
    2961         FIXME("unsupported number of arguments %d in stdcall\n",nrargs);
    2962         res = -1;
    2963         break;
    2964     }
    2965     break;
    2966     default:
    2967     FIXME("unsupported calling convention %d\n",callconv);
    2968     res = -1;
    2969     break;
     3892        FIXME("unsupported calling convention %d\n",callconv);
     3893        res = -1;
     3894        break;
    29703895    }
    29713896    TRACE("returns %08lx\n",res);
     
    29843909{
    29853910    ICOM_THIS( ITypeInfoImpl, iface);
    2986     TLBFuncDesc * pFDesc;
    2987     TLBVarDesc * pVDesc;
     3911    TLBFuncDesc * pFDesc; 
     3912    TLBVarDesc * pVDesc; 
    29883913    int i;
    29893914
     
    29943919
    29953920    for(pFDesc=This->funclist; pFDesc; pFDesc=pFDesc->next)
    2996     if (pFDesc->funcdesc.memid == memid) {
    2997         if (pFDesc->funcdesc.invkind & (dwFlags & ~DISPATCH_METHOD))
    2998         break;
    2999     }
     3921        if (pFDesc->funcdesc.memid == memid) {
     3922            if (pFDesc->funcdesc.invkind & (dwFlags & ~DISPATCH_METHOD))
     3923                break;
     3924        }
    30003925    if (pFDesc) {
    3001     dump_TLBFuncDescOne(pFDesc);
    3002     switch (pFDesc->funcdesc.funckind) {
    3003     case FUNC_PUREVIRTUAL:
    3004     case FUNC_VIRTUAL: {
    3005         DWORD res;
    3006         DWORD *args = (DWORD*)HeapAlloc(GetProcessHeap(),0,sizeof(DWORD)*(pFDesc->funcdesc.cParams+1));
    3007         DWORD *args2 = (DWORD*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD)*(pFDesc->funcdesc.cParams));
    3008         args[0] = (DWORD)pIUnk;
    3009 
    3010         for (i=0;i<pFDesc->funcdesc.cParams;i++) {
    3011         if (i<pDispParams->cArgs) {
    3012             TRACE("set %d to disparg type %d vs %d\n",i,
    3013                 V_VT(pDispParams->rgvarg+i),
    3014                 pFDesc->funcdesc.lprgelemdescParam[i].tdesc.vt
    3015             );
    3016             args[i+1] = V_UNION(pDispParams->rgvarg+i,lVal);
    3017         } else {
    3018             TYPEDESC *tdesc = &(pFDesc->funcdesc.lprgelemdescParam[i].tdesc);
    3019             TRACE("set %d to pointer for get (type is %d)\n",i,tdesc->vt);
    3020             /*FIXME: give pointers for the rest, so propertyget works*/
    3021             args[i+1] = (DWORD)&args2[i];
    3022 
    3023             /* If pointer to variant, pass reference to variant
    3024              * in result variant array.
    3025              */
    3026             if ((tdesc->vt == VT_PTR) &&
    3027             (tdesc->u.lptdesc->vt == VT_VARIANT) &&
    3028             pVarResult
    3029             )
    3030             args[i+1] = (DWORD)(pVarResult+(i-pDispParams->cArgs));
    3031         }
    3032         }
    3033         if (pFDesc->funcdesc.cParamsOpt)
    3034         FIXME("Does not support optional parameters (%d)\n",
    3035             pFDesc->funcdesc.cParamsOpt
    3036         );
    3037 
    3038         res = _invoke((*(DWORD***)pIUnk)[pFDesc->funcdesc.oVft/4],
    3039             pFDesc->funcdesc.callconv,
    3040             pFDesc->funcdesc.cParams+1,
    3041             args
    3042         );
    3043         if (pVarResult && (dwFlags & (DISPATCH_PROPERTYGET))) {
    3044         for (i=0;i<pFDesc->funcdesc.cParams-pDispParams->cArgs;i++) {
    3045             TYPEDESC *tdesc = &(pFDesc->funcdesc.lprgelemdescParam[i].tdesc);
    3046             /* If we are a pointer to a variant, we are done already */
    3047             if ((tdesc->vt==VT_PTR)&&(tdesc->u.lptdesc->vt==VT_VARIANT))
    3048             continue;
    3049 
    3050             VariantInit(&pVarResult[i]);
    3051             V_UNION(pVarResult+i,intVal) = args2[i];
    3052 
    3053             if (tdesc->vt == VT_PTR)
    3054             tdesc = tdesc->u.lptdesc;
    3055             V_VT(pVarResult+i) = tdesc->vt;
    3056 
    3057             /* HACK: VB5 likes this.
    3058              * I do not know why. There is 1 example in MSDN which uses
    3059              * this which appears broken (mixes int vals and
    3060              * IDispatch*.).
    3061              */
    3062             if ((tdesc->vt == VT_PTR) && (dwFlags & DISPATCH_METHOD))
    3063             V_VT(pVarResult+i) = VT_DISPATCH;
    3064             TRACE("storing into variant: [%d] type %d, val %08x\n",
    3065                 i,V_VT(pVarResult+i),V_UNION(pVarResult+i,intVal)
    3066             );
    3067         }
    3068         }
    3069         HeapFree(GetProcessHeap(),0,args2);
    3070         HeapFree(GetProcessHeap(),0,args);
    3071         return S_OK;
    3072     }
    3073     case FUNC_DISPATCH:  {
    3074        IDispatch *disp;
    3075        HRESULT hr;
    3076 
    3077        hr = IUnknown_QueryInterface((LPUNKNOWN)pIUnk,&IID_IDispatch,(LPVOID*)&disp);
    3078        if (hr) {
    3079            FIXME("FUNC_DISPATCH used on object without IDispatch iface?\n");
    3080            return hr;
    3081        }
    3082        FIXME("Calling Invoke in IDispatch iface. untested!\n");
    3083        hr = IDispatch_Invoke(
    3084            disp,memid,&IID_NULL,LOCALE_USER_DEFAULT,dwFlags,pDispParams,
    3085            pVarResult,pExcepInfo,pArgErr
    3086        );
    3087        if (hr)
    3088            FIXME("IDispatch::Invoke failed with %08lx. (Could be not a real error?)\n",hr);
    3089        IDispatch_Release(disp);
    3090        return hr;
    3091     }
    3092     default:
    3093        FIXME("Unknown function invocation type %d\n",pFDesc->funcdesc.funckind);
    3094        return E_FAIL;
    3095     }
     3926        dump_TLBFuncDescOne(pFDesc);
     3927        switch (pFDesc->funcdesc.funckind) {
     3928        case FUNC_PUREVIRTUAL:
     3929        case FUNC_VIRTUAL: {
     3930            DWORD res;
     3931            DWORD *args = (DWORD*)HeapAlloc(GetProcessHeap(),0,sizeof(DWORD)*(pFDesc->funcdesc.cParams+1));
     3932            DWORD *args2 = (DWORD*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD)*(pFDesc->funcdesc.cParams));
     3933            args[0] = (DWORD)pIUnk;
     3934
     3935            for (i=0;i<pFDesc->funcdesc.cParams;i++) {
     3936                if (i<pDispParams->cArgs) {
     3937                    TRACE("set %d to disparg type %d vs %d\n",i,
     3938                            V_VT(pDispParams->rgvarg+i),
     3939                            pFDesc->funcdesc.lprgelemdescParam[i].tdesc.vt
     3940                    );
     3941                    args[i+1] = V_UNION(pDispParams->rgvarg+i,lVal);
     3942                } else {
     3943                    TYPEDESC *tdesc = &(pFDesc->funcdesc.lprgelemdescParam[i].tdesc);
     3944                    TRACE("set %d to pointer for get (type is %d)\n",i,tdesc->vt);
     3945                    /*FIXME: give pointers for the rest, so propertyget works*/
     3946                    args[i+1] = (DWORD)&args2[i];
     3947
     3948                    /* If pointer to variant, pass reference to variant
     3949                     * in result variant array.
     3950                     */
     3951                    if ((tdesc->vt == VT_PTR) &&
     3952                        (tdesc->u.lptdesc->vt == VT_VARIANT) &&
     3953                        pVarResult
     3954                    )
     3955                        args[i+1] = (DWORD)(pVarResult+(i-pDispParams->cArgs));
     3956                }
     3957            }
     3958            if (pFDesc->funcdesc.cParamsOpt)
     3959                FIXME("Does not support optional parameters (%d)\n",
     3960                        pFDesc->funcdesc.cParamsOpt
     3961                );
     3962
     3963            res = _invoke((*(DWORD***)pIUnk)[pFDesc->funcdesc.oVft/4],
     3964                    pFDesc->funcdesc.callconv,
     3965                    pFDesc->funcdesc.cParams+1,
     3966                    args
     3967            );
     3968            if (pVarResult && (dwFlags & (DISPATCH_PROPERTYGET))) {
     3969                for (i=0;i<pFDesc->funcdesc.cParams-pDispParams->cArgs;i++) {
     3970                    TYPEDESC *tdesc = &(pFDesc->funcdesc.lprgelemdescParam[i].tdesc);
     3971                    /* If we are a pointer to a variant, we are done already */
     3972                    if ((tdesc->vt==VT_PTR)&&(tdesc->u.lptdesc->vt==VT_VARIANT))
     3973                        continue;
     3974
     3975                    VariantInit(&pVarResult[i]);
     3976                    V_UNION(pVarResult+i,intVal) = args2[i];
     3977
     3978                    if (tdesc->vt == VT_PTR)
     3979                        tdesc = tdesc->u.lptdesc;
     3980                    V_VT(pVarResult+i) = tdesc->vt;
     3981
     3982                    /* HACK: VB5 likes this.
     3983                     * I do not know why. There is 1 example in MSDN which uses
     3984                     * this which appears broken (mixes int vals and
     3985                     * IDispatch*.).
     3986                     */
     3987                    if ((tdesc->vt == VT_PTR) && (dwFlags & DISPATCH_METHOD))
     3988                        V_VT(pVarResult+i) = VT_DISPATCH;
     3989                    TRACE("storing into variant: [%d] type %d, val %08x\n",
     3990                            i,V_VT(pVarResult+i),V_UNION(pVarResult+i,intVal)
     3991                    );
     3992                }
     3993            }
     3994            HeapFree(GetProcessHeap(),0,args2);
     3995            HeapFree(GetProcessHeap(),0,args);
     3996            return S_OK;
     3997        }
     3998        case FUNC_DISPATCH:  {
     3999           IDispatch *disp;
     4000           HRESULT hr;
     4001
     4002           hr = IUnknown_QueryInterface((LPUNKNOWN)pIUnk,&IID_IDispatch,(LPVOID*)&disp);
     4003           if (hr) {
     4004               FIXME("FUNC_DISPATCH used on object without IDispatch iface?\n");
     4005               return hr;
     4006           }
     4007           FIXME("Calling Invoke in IDispatch iface. untested!\n");
     4008           hr = IDispatch_Invoke(
     4009               disp,memid,&IID_NULL,LOCALE_USER_DEFAULT,dwFlags,pDispParams,
     4010               pVarResult,pExcepInfo,pArgErr
     4011           );
     4012           if (hr)
     4013               FIXME("IDispatch::Invoke failed with %08lx. (Could be not a real error?)\n",hr);
     4014           IDispatch_Release(disp);
     4015           return hr;
     4016        }
     4017        default:
     4018           FIXME("Unknown function invocation type %d\n",pFDesc->funcdesc.funckind);
     4019           return E_FAIL;
     4020        }
    30964021    } else {
    3097     FIXME("variable based invoking not supported yet.\n");
    3098     for(pVDesc=This->varlist; pVDesc; pVDesc=pVDesc->next) {
    3099         if (pVDesc->vardesc.memid == memid) {
    3100         FIXME("varseek: Found memid name %s\n",debugstr_w(((LPWSTR)pVDesc->Name)));
    3101         dump_TLBVarDesc(pVDesc);
    3102         break;
    3103         }
    3104     }
     4022        FIXME("variable based invoking not supported yet.\n");
     4023        for(pVDesc=This->varlist; pVDesc; pVDesc=pVDesc->next) {
     4024            if (pVDesc->vardesc.memid == memid) {
     4025                FIXME("varseek: Found memid name %s\n",debugstr_w(((LPWSTR)pVDesc->Name)));
     4026                dump_TLBVarDesc(pVDesc);
     4027                break;
     4028            }
     4029        }
    31054030    }
    31064031    FIXME("Did not find member id %d!\n",(int)memid);
     
    31094034
    31104035/* ITypeInfo::GetDocumentation
    3111  *
     4036 * 
    31124037 * Retrieves the documentation string, the complete Help file name and path,
    31134038 * and the context ID for the Help topic for a specified type description.
     
    31184043{
    31194044    ICOM_THIS( ITypeInfoImpl, iface);
    3120     TLBFuncDesc * pFDesc;
    3121     TLBVarDesc * pVDesc;
     4045    TLBFuncDesc * pFDesc; 
     4046    TLBVarDesc * pVDesc; 
    31224047    TRACE("(%p) memid %ld Name(%p) DocString(%p)"
    31234048          " HelpContext(%p) HelpFile(%p)\n",
     
    31364061    for(pFDesc=This->funclist; pFDesc; pFDesc=pFDesc->next)
    31374062        if(pFDesc->funcdesc.memid==memid){
    3138             return S_OK;
     4063          if(pBstrName)
     4064            *pBstrName = SysAllocString(pFDesc->Name);
     4065          if(pBstrDocString)
     4066            *pBstrDocString=SysAllocString(pFDesc->HelpString);
     4067          if(pdwHelpContext)
     4068            *pdwHelpContext=pFDesc->helpcontext;
     4069          return S_OK;
    31394070        }
    31404071    for(pVDesc=This->varlist; pVDesc; pVDesc=pVDesc->next)
    31414072        if(pVDesc->vardesc.memid==memid){
     4073            FIXME("Not implemented\n");
    31424074            return S_OK;
    31434075        }
     
    31474079
    31484080/*  ITypeInfo::GetDllEntry
    3149  *
     4081 * 
    31504082 * Retrieves a description or specification of an entry point for a function
    31514083 * in a DLL.
     
    31614093
    31624094/* ITypeInfo::GetRefTypeInfo
    3163  *
     4095 * 
    31644096 * If a type description references other type descriptions, it retrieves
    31654097 * the referenced type descriptions.
    31664098 */
    31674099static HRESULT WINAPI ITypeInfo_fnGetRefTypeInfo(
    3168     ITypeInfo2 *iface,
     4100        ITypeInfo2 *iface,
    31694101        HREFTYPE hRefType,
    3170     ITypeInfo  **ppTInfo)
     4102        ITypeInfo  **ppTInfo)
    31714103{
    31724104    ICOM_THIS( ITypeInfoImpl, iface);
    31734105    HRESULT result = E_FAIL;
    31744106
    3175     if(HREFTYPE_INTHISFILE(hRefType))
     4107
     4108    if (hRefType == -1 &&
     4109        (((ITypeInfoImpl*) This)->TypeAttr.typekind   == TKIND_DISPATCH) &&
     4110        (((ITypeInfoImpl*) This)->TypeAttr.wTypeFlags &  TYPEFLAG_FDUAL))
    31764111    {
    3177       ITypeLib *pTLib;
    3178       int Index;
    3179       result = ITypeInfo_GetContainingTypeLib(iface, &pTLib, &Index);
    3180       if(SUCCEEDED( result ))
    3181       {
    3182         result=ITypeLib2_GetTypeInfo(pTLib, HREFTYPE_INDEX(hRefType), ppTInfo);
    3183         ITypeLib2_Release(pTLib );
    3184       }
    3185     }
    3186     else if (hRefType == -1 &&
    3187              (((ITypeInfoImpl*) This)->TypeAttr.typekind   == TKIND_DISPATCH) &&
    3188              (((ITypeInfoImpl*) This)->TypeAttr.wTypeFlags &  TYPEFLAG_FDUAL))
    3189     {
    3190       /* when we meet a DUAL dispinterface, we must create the interface
    3191       * version of it.
    3192       */
    3193       ITypeInfoImpl* pTypeInfoImpl = (ITypeInfoImpl*) ITypeInfo_Constructor();
    3194 
    3195 
    3196       /* the interface version contains the same information as the dispinterface
    3197        * copy the contents of the structs.
    3198        */
    3199       *pTypeInfoImpl = *This;
    3200       pTypeInfoImpl->ref = 1;
    3201 
    3202       /* change the type to interface */
    3203       pTypeInfoImpl->TypeAttr.typekind = TKIND_INTERFACE;
    3204 
    3205       *ppTInfo = (ITypeInfo*) pTypeInfoImpl;
    3206 
    3207       ITypeInfo_AddRef((ITypeInfo*) pTypeInfoImpl);
    3208 
    3209       result = S_OK;
    3210     }
    3211     else
    3212     {
    3213       /* imported type lib */
    3214       TLBRefType   *pRefType     = NULL;
    3215 
    3216       /* search in implemented types */
    3217       for( pRefType = This->impltypelist;
    3218            pRefType && (pRefType->reference != hRefType);
    3219            pRefType = pRefType->next);
    3220 
    3221       if(!pRefType)
    3222       {
    3223         TYPEATTR*       pMyTypeAttr  = &This->TypeAttr;
    3224         unsigned short  cFuncs       = pMyTypeAttr->cFuncs;
    3225         unsigned short  cVars        = pMyTypeAttr->cVars;
    3226 
    3227         /* search in arguments */
    3228         if (cFuncs > 0)
    3229         {
    3230           unsigned short  cFuncIndex   = 0;
    3231 
    3232           TLBFuncDesc*    pCurrFunc    = This->funclist;
    3233 
    3234           for (cFuncIndex = 0; !pRefType && cFuncIndex < cFuncs ; ++cFuncIndex)
    3235           {
    3236             FUNCDESC*  pCurrFuncDesc = &pCurrFunc->funcdesc;
    3237 
    3238             short      cParams       = pCurrFuncDesc->cParams;
    3239             short      cParamIndex   = 0;
    3240 
    3241             for (cParamIndex = 0 ;
    3242                  !pRefType && cParamIndex < cParams ;
    3243                  ++cParamIndex)
    3244             {
    3245               TLBParDesc* pCurrParamDesc = &(pCurrFunc->pParamDesc[cParamIndex]);
    3246 
    3247               if ( pCurrParamDesc->pRefType && pCurrParamDesc->pRefType->reference == hRefType)
    3248               {
    3249                 pRefType = pCurrParamDesc->pRefType;
    3250                 break; /* also break from outer loop since pRefType != 0 */
    3251               }
    3252             }
    3253 
    3254             pCurrFunc = pCurrFunc->next;
    3255           }
    3256         }
    3257         /* search in variables */
    3258         else if (cVars > 0)
    3259         {
    3260           FIXME("search hreftype in variables, if any\n");
    3261           result = E_INVALIDARG; // FIXME : correct?
    3262         }
    3263       }
    3264 
    3265       /* href-referenced typeinfo found! */
    3266       if (pRefType || hRefType == -1)
    3267       {
    3268         ITypeLibImpl *pTypeLib = pRefType->pImpTLInfo->pImpTypeLib;
    3269 
    3270         if(pTypeLib)
    3271         {
    3272           TRACE("typeinfo in imported typelib that is already loaded\n");
    3273 
    3274           result = ITypeLib2_GetTypeInfoOfGuid((LPTYPELIB)pTypeLib,
    3275                                            &pRefType->guid,
    3276                                            ppTInfo);
    3277         }
    3278         else
    3279         {
    3280           result = LoadRegTypeLib( &pRefType->pImpTLInfo->guid,
    3281                       pRefType->pImpTLInfo->wVersionMajor,
    3282                       pRefType->pImpTLInfo->wVersionMinor,
    3283                       pRefType->pImpTLInfo->lcid,
    3284                       (LPTYPELIB *)&pTypeLib);
    3285 
    3286           if(!SUCCEEDED(result))
    3287           {
    3288             BSTR libnam=SysAllocString(pRefType->pImpTLInfo->name);
    3289             TRACE("typeinfo in imported typelib that isn't already loaded\n");
    3290             result=LoadTypeLib(libnam, (LPTYPELIB *)&pTypeLib);
    3291             SysFreeString(libnam);
    3292           }
    3293           if(SUCCEEDED(result))
    3294           {
    3295             result=ITypeLib2_GetTypeInfoOfGuid((LPTYPELIB)pTypeLib, &pRefType->guid, ppTInfo);
    3296             pRefType->pImpTLInfo->pImpTypeLib = pTypeLib;
    3297             ITypeLib2_AddRef((ITypeLib*) pTypeLib);
    3298           }
    3299         }
    3300       }
     4112          /* when we meet a DUAL dispinterface, we must create the interface
     4113          * version of it.
     4114          */
     4115          ITypeInfoImpl* pTypeInfoImpl = (ITypeInfoImpl*) ITypeInfo_Constructor();
     4116
     4117               
     4118          /* the interface version contains the same information as the dispinterface
     4119           * copy the contents of the structs.
     4120           */
     4121          *pTypeInfoImpl = *This;
     4122          pTypeInfoImpl->ref = 1;
     4123               
     4124          /* change the type to interface */
     4125          pTypeInfoImpl->TypeAttr.typekind = TKIND_INTERFACE;
     4126         
     4127          *ppTInfo = (ITypeInfo*) pTypeInfoImpl;
     4128
     4129          ITypeInfo_AddRef((ITypeInfo*) pTypeInfoImpl);
     4130
     4131          result = S_OK;
     4132
     4133    } else {
     4134        TLBRefType *pRefType;
     4135        for(pRefType = This->reflist; pRefType; pRefType = pRefType->next) {
     4136            if(pRefType->reference == hRefType)
     4137                break;
     4138        }
     4139        if(!pRefType)
     4140          FIXME("Can't find pRefType for ref %lx\n", hRefType);
     4141        if(pRefType && hRefType != -1) {
     4142            ITypeLib *pTLib;
     4143
     4144            if(pRefType->pImpTLInfo == TLB_REF_INTERNAL) {
     4145                int Index;
     4146                result = ITypeInfo_GetContainingTypeLib(iface, &pTLib, &Index);
     4147            } else {
     4148                if(pRefType->pImpTLInfo->pImpTypeLib) {
     4149                    TRACE("typeinfo in imported typelib that is already loaded\n");
     4150                    pTLib = (ITypeLib*)pRefType->pImpTLInfo->pImpTypeLib;
     4151                    ITypeLib2_AddRef((ITypeLib*) pTLib);
     4152                    result = S_OK;
     4153                } else {
     4154                    TRACE("typeinfo in imported typelib that isn't already loaded\n");
     4155                    result = LoadRegTypeLib( &pRefType->pImpTLInfo->guid,
     4156                                             pRefType->pImpTLInfo->wVersionMajor,
     4157                                             pRefType->pImpTLInfo->wVersionMinor,
     4158                                             pRefType->pImpTLInfo->lcid,
     4159                                             &pTLib);
     4160
     4161                    if(!SUCCEEDED(result)) {
     4162                        BSTR libnam=SysAllocString(pRefType->pImpTLInfo->name);
     4163                        result=LoadTypeLib(libnam, &pTLib);
     4164                        SysFreeString(libnam);
     4165                    }
     4166                    if(SUCCEEDED(result)) {
     4167                        pRefType->pImpTLInfo->pImpTypeLib = (ITypeLibImpl*)pTLib;
     4168                        ITypeLib2_AddRef(pTLib);
     4169                    }
     4170                }
     4171            }
     4172            if(SUCCEEDED(result)) {
     4173                if(pRefType->index == TLB_REF_USE_GUID)
     4174                    result = ITypeLib2_GetTypeInfoOfGuid(pTLib,
     4175                                                         &pRefType->guid,
     4176                                                         ppTInfo);
     4177                else
     4178                    result = ITypeLib2_GetTypeInfo(pTLib, pRefType->index,
     4179                                                   ppTInfo);
     4180            }
     4181        }
    33014182    }
    33024183
     
    33074188
    33084189/* ITypeInfo::AddressOfMember
    3309  *
     4190 * 
    33104191 * Retrieves the addresses of static functions or variables, such as those
    33114192 * defined in a DLL.
     
    33204201
    33214202/* ITypeInfo::CreateInstance
    3322  *
    3323  * Creates a new instance of a type that describes a component object class
     4203 * 
     4204 * Creates a new instance of a type that describes a component object class 
    33244205 * (coclass).
    33254206 */
    3326 static HRESULT WINAPI ITypeInfo_fnCreateInstance( ITypeInfo2 *iface,
    3327         IUnknown *pUnk, REFIID riid, VOID  **ppvObj)
     4207static HRESULT WINAPI ITypeInfo_fnCreateInstance( ITypeInfo2 *iface, 
     4208        IUnknown *pUnk, REFIID riid, VOID  **ppvObj) 
    33284209{
    33294210    ICOM_THIS( ITypeInfoImpl, iface);
     
    33374218 */
    33384219static HRESULT WINAPI ITypeInfo_fnGetMops( ITypeInfo2 *iface, MEMBERID memid,
    3339                 BSTR  *pBstrMops)
     4220                                BSTR  *pBstrMops)
    33404221{
    33414222    ICOM_THIS( ITypeInfoImpl, iface);
     
    33454226
    33464227/* ITypeInfo::GetContainingTypeLib
    3347  *
     4228 * 
    33484229 * Retrieves the containing type library and the index of the type description
    33494230 * within that type library.
     
    33804261 */
    33814262static HRESULT WINAPI ITypeInfo_fnReleaseFuncDesc(
    3382     ITypeInfo2 *iface,
     4263        ITypeInfo2 *iface,
    33834264        FUNCDESC *pFuncDesc)
    33844265{
     
    34184299 * Returns the type flags without any allocations. This returns a DWORD type
    34194300 * flag, which expands the type flags without growing the TYPEATTR (type
    3420  * attribute).
     4301 * attribute). 
    34214302 *
    34224303 */
     
    34434324    HRESULT result;
    34444325    /* FIXME: should check for invKind??? */
    3445     for(i=0, pFuncInfo=This->funclist;pFuncInfo &&
     4326    for(i=0, pFuncInfo=This->funclist;pFuncInfo && 
    34464327            memid != pFuncInfo->funcdesc.memid; i++, pFuncInfo=pFuncInfo->next);
    34474328    if(pFuncInfo){
     
    34604341 *
    34614342 * Binds to a specific member based on a known DISPID, where the member name
    3462  * is not known (for example, when binding to a default member).
     4343 * is not known (for example, when binding to a default member). 
    34634344 *
    34644345 */
     
    34704351    int i;
    34714352    HRESULT result;
    3472     for(i=0, pVarInfo=This->varlist; pVarInfo &&
     4353    for(i=0, pVarInfo=This->varlist; pVarInfo && 
    34734354            memid != pVarInfo->vardesc.memid; i++, pVarInfo=pVarInfo->next)
    34744355        ;
     
    34904371 */
    34914372static HRESULT WINAPI ITypeInfo2_fnGetCustData(
    3492     ITypeInfo2 * iface,
    3493     REFGUID guid,
    3494     VARIANT *pVarVal)
     4373        ITypeInfo2 * iface,
     4374        REFGUID guid,
     4375        VARIANT *pVarVal)
    34954376{
    34964377    ICOM_THIS( ITypeInfoImpl, iface);
     
    35164397 */
    35174398static HRESULT WINAPI ITypeInfo2_fnGetFuncCustData(
    3518     ITypeInfo2 * iface,
    3519     UINT index,
    3520     REFGUID guid,
    3521     VARIANT *pVarVal)
     4399        ITypeInfo2 * iface,
     4400        UINT index,
     4401        REFGUID guid,
     4402        VARIANT *pVarVal)
    35224403{
    35234404    ICOM_THIS( ITypeInfoImpl, iface);
    35244405    TLBCustData *pCData=NULL;
    3525     TLBFuncDesc * pFDesc;
     4406    TLBFuncDesc * pFDesc; 
    35264407    int i;
    35274408    for(i=0, pFDesc=This->funclist; i!=index && pFDesc; i++,
     
    35474428 */
    35484429static HRESULT WINAPI ITypeInfo2_fnGetParamCustData(
    3549     ITypeInfo2 * iface,
    3550     UINT indexFunc,
    3551     UINT indexParam,
    3552     REFGUID guid,
    3553     VARIANT *pVarVal)
    3554 {
     4430        ITypeInfo2 * iface,
     4431        UINT indexFunc,
     4432        UINT indexParam,
     4433        REFGUID guid,
     4434        VARIANT *pVarVal)
     4435{   
    35554436    ICOM_THIS( ITypeInfoImpl, iface);
    35564437    TLBCustData *pCData=NULL;
    3557     TLBFuncDesc * pFDesc;
     4438    TLBFuncDesc * pFDesc; 
    35584439    int i;
    35594440
     
    35614442
    35624443    if(pFDesc && indexParam >=0 && indexParam<pFDesc->funcdesc.cParams)
    3563         for(pCData=pFDesc->pParamDesc[indexParam].pCustData; pCData;
     4444        for(pCData=pFDesc->pParamDesc[indexParam].pCustData; pCData; 
    35644445                pCData = pCData->next)
    35654446            if( IsEqualIID(guid, &pCData->guid)) break;
     
    35764457}
    35774458
    3578 /* ITypeInfo2::GetVarcCustData
     4459/* ITypeInfo2::GetVarCustData
    35794460 *
    35804461 * Gets the custom data
    35814462 */
    35824463static HRESULT WINAPI ITypeInfo2_fnGetVarCustData(
    3583     ITypeInfo2 * iface,
    3584     UINT index,
    3585     REFGUID guid,
    3586     VARIANT *pVarVal)
    3587 {
     4464        ITypeInfo2 * iface,
     4465        UINT index,
     4466        REFGUID guid,
     4467        VARIANT *pVarVal)
     4468{   
    35884469    ICOM_THIS( ITypeInfoImpl, iface);
    35894470    TLBCustData *pCData=NULL;
    3590     TLBVarDesc * pVDesc;
     4471    TLBVarDesc * pVDesc; 
    35914472    int i;
    35924473
     
    36124493}
    36134494
    3614 /* ITypeInfo2::GetImplcCustData
     4495/* ITypeInfo2::GetImplCustData
    36154496 *
    36164497 * Gets the custom data
    36174498 */
    36184499static HRESULT WINAPI ITypeInfo2_fnGetImplTypeCustData(
    3619     ITypeInfo2 * iface,
    3620     UINT index,
    3621     REFGUID guid,
    3622     VARIANT *pVarVal)
    3623 {
     4500        ITypeInfo2 * iface,
     4501        UINT index,
     4502        REFGUID guid,
     4503        VARIANT *pVarVal)
     4504{   
    36244505    ICOM_THIS( ITypeInfoImpl, iface);
    36254506    TLBCustData *pCData=NULL;
    3626     TLBRefType * pRDesc;
     4507    TLBImplType * pRDesc;
    36274508    int i;
    36284509
     
    36364517      }
    36374518    }
    3638 
     4519   
    36394520    TRACE("(%p) guid %s %s found!x)\n", This, debugstr_guid(guid), pCData? "" : "NOT");
    36404521
     
    36494530
    36504531/* ITypeInfo2::GetDocumentation2
    3651  *
     4532 * 
    36524533 * Retrieves the documentation string, the complete Help file name and path,
    36534534 * the localization context to use, and the context ID for the library Help
     
    36564537 */
    36574538static HRESULT WINAPI ITypeInfo2_fnGetDocumentation2(
    3658     ITypeInfo2 * iface,
    3659     MEMBERID memid,
    3660     LCID lcid,
    3661     BSTR *pbstrHelpString,
    3662     DWORD *pdwHelpStringContext,
    3663     BSTR *pbstrHelpStringDll)
     4539        ITypeInfo2 * iface,
     4540        MEMBERID memid,
     4541        LCID lcid,
     4542        BSTR *pbstrHelpString,
     4543        DWORD *pdwHelpStringContext,
     4544        BSTR *pbstrHelpStringDll)
    36644545{
    36654546    ICOM_THIS( ITypeInfoImpl, iface);
    3666     TLBFuncDesc * pFDesc;
    3667     TLBVarDesc * pVDesc;
     4547    TLBFuncDesc * pFDesc; 
     4548    TLBVarDesc * pVDesc; 
    36684549    TRACE("(%p) memid %ld lcid(0x%lx)  HelpString(%p) "
    36694550          "HelpStringContext(%p) HelpStringDll(%p)\n",
     
    37124593/* ITypeInfo2::GetAllCustData
    37134594 *
    3714  * Gets all custom data items for the Type info.
     4595 * Gets all custom data items for the Type info. 
    37154596 *
    37164597 */
    37174598static HRESULT WINAPI ITypeInfo2_fnGetAllCustData(
    3718     ITypeInfo2 * iface,
    3719     CUSTDATA *pCustData)
     4599        ITypeInfo2 * iface,
     4600        CUSTDATA *pCustData)
    37204601{
    37214602    ICOM_THIS( ITypeInfoImpl, iface);
     
    37234604    int i;
    37244605
    3725     TRACE("(%p) returning %d items\n", This, This->ctCustData);
     4606    TRACE("(%p) returning %d items\n", This, This->ctCustData); 
    37264607
    37274608    pCustData->prgCustData = TLB_Alloc(This->ctCustData * sizeof(CUSTDATAITEM));
     
    37454626 */
    37464627static HRESULT WINAPI ITypeInfo2_fnGetAllFuncCustData(
    3747     ITypeInfo2 * iface,
    3748     UINT index,
    3749     CUSTDATA *pCustData)
     4628        ITypeInfo2 * iface,
     4629        UINT index,
     4630        CUSTDATA *pCustData)
    37504631{
    37514632    ICOM_THIS( ITypeInfoImpl, iface);
    37524633    TLBCustData *pCData;
    3753     TLBFuncDesc * pFDesc;
     4634    TLBFuncDesc * pFDesc; 
    37544635    int i;
    3755     TRACE("(%p) index %d\n", This, index);
     4636    TRACE("(%p) index %d\n", This, index); 
    37564637    for(i=0, pFDesc=This->funclist; i!=index && pFDesc; i++,
    37574638            pFDesc=pFDesc->next)
     
    37874668    ICOM_THIS( ITypeInfoImpl, iface);
    37884669    TLBCustData *pCData=NULL;
    3789     TLBFuncDesc * pFDesc;
     4670    TLBFuncDesc * pFDesc; 
    37904671    int i;
    3791     TRACE("(%p) index %d\n", This, indexFunc);
     4672    TRACE("(%p) index %d\n", This, indexFunc); 
    37924673    for(i=0, pFDesc=This->funclist; i!=indexFunc && pFDesc; i++,
    37934674            pFDesc=pFDesc->next)
    37944675        ;
    37954676    if(pFDesc && indexParam >=0 && indexParam<pFDesc->funcdesc.cParams){
    3796         pCustData->prgCustData =
     4677        pCustData->prgCustData = 
    37974678            TLB_Alloc(pFDesc->pParamDesc[indexParam].ctCustData *
    37984679                    sizeof(CUSTDATAITEM));
     
    38244705    ICOM_THIS( ITypeInfoImpl, iface);
    38254706    TLBCustData *pCData;
    3826     TLBVarDesc * pVDesc;
     4707    TLBVarDesc * pVDesc; 
    38274708    int i;
    3828     TRACE("(%p) index %d\n", This, index);
     4709    TRACE("(%p) index %d\n", This, index); 
    38294710    for(i=0, pVDesc=This->varlist; i!=index && pVDesc; i++,
    38304711            pVDesc=pVDesc->next)
     
    38564737 */
    38574738static HRESULT WINAPI ITypeInfo2_fnGetAllImplTypeCustData(
    3858     ITypeInfo2 * iface,
    3859     UINT index,
    3860     CUSTDATA *pCustData)
     4739        ITypeInfo2 * iface,
     4740        UINT index,
     4741        CUSTDATA *pCustData)
    38614742{
    38624743    ICOM_THIS( ITypeInfoImpl, iface);
    38634744    TLBCustData *pCData;
    3864     TLBRefType * pRDesc;
     4745    TLBImplType * pRDesc;
    38654746    int i;
    3866     TRACE("(%p) index %d\n", This, index);
     4747    TRACE("(%p) index %d\n", This, index); 
    38674748    for(i=0, pRDesc=This->impltypelist; i!=index && pRDesc; i++,
    38684749            pRDesc=pRDesc->next)
     
    38884769}
    38894770
    3890 static ICOM_VTABLE(ITypeInfo2) tinfvt =
     4771static ICOM_VTABLE(ITypeInfo2) tinfvt = 
    38914772{
    38924773    ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
  • trunk/src/oleaut32/typelib.h

    r6507 r6689  
    1717#define DO_NOT_SEEK (-1)
    1818
    19 #define HREFTYPE_INTHISFILE(href) (!((href) & 3))
    20 #define HREFTYPE_INDEX(href) ((href) /sizeof(TLBTypeInfoBase))
     19#define MSFT_HREFTYPE_INTHISFILE(href) (!((href) & 3))
     20#define MSFT_HREFTYPE_INDEX(href) ((href) /sizeof(MSFT_TypeInfoBase))
    2121
    2222/*-------------------------FILE STRUCTURES-----------------------------------*/
    2323
     24/* There are two known file formats, those created with ICreateTypeLib
     25 * have the signature "SLGT" as their first four bytes, while those created
     26 * with ICreateTypeLib2 have "MSFT".
     27 */
     28
     29/*****************************************************
     30 *                MSFT typelibs
     31 *
     32 * These are TypeLibs created with ICreateTypeLib2
     33 *
     34 */
    2435
    2536/*
     
    2839 * 
    2940 */
    30 typedef struct tagTLB2Header {
     41typedef struct tagMSFT_Header {
    3142/*0x00*/INT magic1;       /* 0x5446534D "MSFT" */
    3243        INT   magic2;       /* 0x00010002 version nr? */
     
    3748        INT   varflags;     /* (largely) unknown flags ,seems to be always 41 */
    3849                            /* becomes 0x51 with a helpfile defined */
    39                             /* if help dll defined its 0x151 */
     50                            /* if help dll defined it's 0x151 */
    4051                            /* update : the lower nibble is syskind */
    4152        INT   version;      /* set with SetVersion() */
     
    5566        INT   dispatchpos;      /* gets a value (1+n*0x0c) with Idispatch interfaces */
    5667/*0x50*/INT   res50;            /* is zero becomes one when an interface is derived */
    57 } TLB2Header;
     68} MSFT_Header;
    5869
    5970/* segments in the type lib file have a structure like this: */
    60 typedef struct _tptag {
     71typedef struct tagMSFT_pSeg {
    6172        INT   offset;       /* absolute offset in file */
    6273        INT   length;       /* length of segment */
     
    6475        INT   res0c;        /* unknown always 0x0f in the header */
    6576                            /* 0x03 in the typeinfo_data */
    66 } pSeg;
     77} MSFT_pSeg;
    6778
    6879/* layout of the main segment directory */
    69 typedef struct tagTLBSegDir {
    70 /*1*/pSeg pTypeInfoTab; /* each type info get an entry of 0x64 bytes */
    71                         /* (25 ints) */
    72 /*2*/pSeg pImpInfo;     /* table with info for imported types */
    73 /*3*/pSeg pImpFiles;    /* import libaries */
    74 /*4*/pSeg pRefTab;      /* References table */
    75 /*5*/pSeg pLibtab;      /* always exists, alway same size (0x80) */
    76                         /* hash table w offsets to guid????? */
    77 /*6*/pSeg pGuidTab;     /* all guids are stored here together with  */
    78                         /* offset in some table???? */
    79 /*7*/pSeg res07;        /* always created, alway same size (0x200) */
    80                         /* purpose largely unknown */
    81 /*8*/pSeg pNametab;     /* name tables */
    82 /*9*/pSeg pStringtab;   /*string table */
    83 /*A*/pSeg pTypdescTab;  /* table with type descriptors */
    84 /*B*/pSeg pArrayDescriptions;
    85 /*C*/pSeg pCustData;    /*  data table, used for custom data and default */
    86                         /* parameter values */
    87 /*D*/pSeg pCDGuids;     /* table with offsets for the guids and into the customer data table */
    88 /*E*/pSeg res0e;            /* unknown */
    89 /*F*/pSeg res0f;            /* unknown  */
    90 } TLBSegDir;
     80typedef struct tagMSFT_SegDir {
     81/*1*/MSFT_pSeg pTypeInfoTab; /* each type info get an entry of 0x64 bytes */
     82                             /* (25 ints) */
     83/*2*/MSFT_pSeg pImpInfo;     /* table with info for imported types */
     84/*3*/MSFT_pSeg pImpFiles;    /* import libaries */
     85/*4*/MSFT_pSeg pRefTab;      /* References table */
     86/*5*/MSFT_pSeg pLibtab;      /* always exists, alway same size (0x80) */
     87                             /* hash table w offsets to guid????? */
     88/*6*/MSFT_pSeg pGuidTab;     /* all guids are stored here together with  */
     89                             /* offset in some table???? */
     90/*7*/MSFT_pSeg res07;        /* always created, alway same size (0x200) */
     91                             /* purpose largely unknown */
     92/*8*/MSFT_pSeg pNametab;     /* name tables */
     93/*9*/MSFT_pSeg pStringtab;   /* string table */
     94/*A*/MSFT_pSeg pTypdescTab;  /* table with type descriptors */
     95/*B*/MSFT_pSeg pArrayDescriptions;
     96/*C*/MSFT_pSeg pCustData;    /* data table, used for custom data and default */
     97                             /* parameter values */
     98/*D*/MSFT_pSeg pCDGuids;     /* table with offsets for the guids and into */
     99                             /* the customer data table */
     100/*E*/MSFT_pSeg res0e;        /* unknown */
     101/*F*/MSFT_pSeg res0f;        /* unknown  */
     102} MSFT_SegDir;
    91103
    92104
    93105/* base type info data */
    94 typedef struct tagTLBTypeInfoBase {
     106typedef struct tagMSFT_TypeInfoBase {
    95107/*000*/ INT   typekind;             /*  it is the TKIND_xxx */
    96108                                    /* some byte alignment stuf */
     
    126138        INT     res18;          /* always? 0 */
    127139/*060*/ INT     res19;          /* always? -1 */
    128     } TLBTypeInfoBase;
     140    } MSFT_TypeInfoBase;
    129141
    130142/* layout of an entry with information on imported types */
    131 typedef struct tagTLBImpInfo {
     143typedef struct tagMSFT_ImpInfo {
    132144    INT     res0;           /* unknown */
    133145    INT     oImpFile;       /* offset inthe Import File table */
    134146    INT     oGuid;          /* offset in Guid table */
    135     } TLBImpInfo;
     147    } MSFT_ImpInfo;
    136148
    137149/* function description data */
     
    1651777*  INT   oArgCustData[1];  // custom data per argument //
    166178*/
    167 } TLBFuncRecord;
     179} MSFT_FuncRecord;
    168180
    169181/* after this may follow an array with default value pointers if the
     
    177189        INT   oName;
    178190        INT   Flags;
    179     } TLBParameterInfo;
     191    } MSFT_ParameterInfo;
    180192
    181193/* Variable description data */
     
    196208    INT   HelpStringContext;
    197209
    198 } TLBVarRecord;
     210} MSFT_VarRecord;
    199211
    200212/* Structure of the reference data  */
    201213typedef struct {
    202     INT   reftype;  /* either offset in type info table, then its */
     214    INT   reftype;  /* either offset in type info table, then it's */
    203215                    /* a multiple of 64 */
    204216                    /* or offset in the external reference table */
     
    207219    INT   oCustData;    /* custom data */
    208220    INT   onext;    /* next offset, -1 if last */
    209 } TLBRefRecord;
     221} MSFT_RefRecord;
    210222
    211223/* this is how a guid is stored */
     
    213225    GUID guid;
    214226    INT   unk10;        /* differntiate with libid, classid etc? */
    215                         /* its -2 for a libary */
     227                        /* it's -2 for a libary */
    216228                        /* it's 0 for an interface */
    217229    INT   unk14;        /* always? -1 */
    218 } TLBGuidEntry;
     230} MSFT_GuidEntry;
    219231/* some data preceding entries in the name table */
    220232typedef struct {
     
    222234                           sometimes 0 (interface, func) */
    223235    INT   unk10;        /* sometimes -1 (lib) , sometimes 0 (interface, func),
    224                            sometime 0x10 (par) */
     236                           sometimes 0x10 (par) */
    225237    INT   namelen;      /* only lower 8 bits are valid */
    226 } TLBNameIntro;
     238} MSFT_NameIntro;
    227239/* the custom data table directory has enties like this */
    228240typedef struct {
    229241    INT   GuidOffset;
    230242    INT   DataOffset;
    231     INT   next;     /* next offset in the table, -1 if its the last */
    232 } TLBCDGuid;
    233 
    234 
     243    INT   next;     /* next offset in the table, -1 if it's the last */
     244} MSFT_CDGuid;
     245
     246
     247/***********************************************************
     248 *
     249 *                SLTG typelibs.
     250 *
     251 * These are created with ICreateTypeLib
     252 *
     253 */
     254
     255#include "pshpack1.h"
     256
     257typedef struct {
     258/*00*/  DWORD SLTG_magic;       /* 0x47544c53  == "SLTG" */
     259/*04*/  WORD nrOfFileBlks;      /* no of SLTG_BlkEntry's + 1 */
     260/*06*/  WORD res06;             /* ?? always 9 */
     261/*08*/  WORD res08;             /* some kind of len/offset ?? */
     262/*0a*/  WORD first_blk;         /* 1 based index into blk entries that
     263                                   corresponds to first block in file */
     264/*0c*/  DWORD res0c;            /* always 0x000204ff */
     265/*10*/  DWORD res10;            /* always 0x00000000 */
     266/*14*/  DWORD res14;            /* always 0x000000c0 */
     267/*18*/  DWORD res18;            /* always 0x46000000 */
     268/*1c*/  DWORD res1c;            /* always 0x00000044 */
     269/*20*/  DWORD res20;            /* always 0xffff0000 */
     270} SLTG_Header;
     271
     272/* This gets followed by a list of block entries */
     273typedef struct {
     274/*00*/  DWORD len;
     275/*04*/  WORD index_string; /* offs from start of SLTG_Magic to index string */
     276/*06*/  WORD next;
     277} SLTG_BlkEntry;
     278
     279/* The order of the blocks in the file is given by starting at Block
     280   entry firt_blk and stepping through using the next pointer */
     281
     282/* These then get followed by this magic */
     283typedef struct {
     284/*00*/ BYTE res00;              /* always 0x01 */
     285/*01*/ CHAR CompObj_magic[8];   /* always "CompObj" */
     286/*09*/ CHAR dir_magic[4];       /* always "dir" */
     287} SLTG_Magic;
     288
     289#define SLTG_COMPOBJ_MAGIC "CompObj"
     290#define SLTG_DIR_MAGIC "dir"
     291
     292/* Next we have SLTG_Header.nrOfFileBlks - 2 of Index strings.  These
     293are persumbably unique to within the file and look something like
     294"AAAAAAAAAA" with the first character incremented from 'A' to ensure
     295uniqueness.  I guess successive chars increment when we need to wrap
     296the first one. */
     297
     298typedef struct {
     299/*00*/ CHAR string[11];
     300} SLTG_Index;
     301
     302
     303/* This is followed by SLTG_pad9 */
     304typedef struct {
     305/*00*/ CHAR pad[9];     /* 9 '\0's */
     306} SLTG_Pad9;
     307
     308
     309/* Now we have the noOfFileBlks - 1 worth of blocks. The length of
     310each block is given by its entry in SLTG_BlkEntry. */
     311
     312/* type SLTG_NAME in rather like a BSTR except that the length in
     313bytes is given by the first WORD and the string contains 8bit chars */
     314
     315typedef WORD SLTG_Name;
     316
     317/* The main library block looks like this.  This one seems to come last */
     318
     319typedef struct {
     320/*00*/  WORD magic;             /* 0x51cc */
     321/*02*/  WORD res02;             /* 0x0003, 0x0004 */
     322/*04*/  WORD name;              /* offset to name in name table */
     323/*06*/  SLTG_Name res06;        /* maybe this is just WORD == 0xffff */
     324        SLTG_Name helpstring;
     325        SLTG_Name helpfile;
     326        DWORD helpcontext;
     327        WORD syskind;           /* == 1 for win32, 0 for win16 */
     328        WORD lcid;              /* == 0x409, 0x809 etc */
     329        DWORD res12;            /* == 0 */
     330        WORD libflags;          /* LIBFLAG_* */
     331        WORD maj_vers;
     332        WORD min_vers;
     333        GUID uuid;
     334} SLTG_LibBlk;
     335
     336#define SLTG_LIBBLK_MAGIC 0x51cc
     337
     338/* we then get 0x40 bytes worth of 0xffff or small numbers followed by
     339   nrOfFileBlks - 2 of these */
     340typedef struct {
     341        WORD small_no;
     342        SLTG_Name index_name; /* This refers to a name in the directory */
     343        SLTG_Name other_name; /* Another one of these weird names */
     344        WORD res1a;           /* 0xffff */
     345        WORD name_offs;       /* offset to name in name table */
     346        WORD more_bytes;      /* if this is non-zero we get this many
     347                                 bytes before the next element, which seem
     348                                 to reference the docstring of the type ? */
     349        WORD res20;           /* 0xffff */
     350        DWORD helpcontext;
     351        WORD res26;           /* 0xffff */
     352        GUID uuid;
     353} SLTG_OtherTypeInfo;
     354
     355/* Next we get WORD 0x0003 followed by a DWORD which if we add to
     3560x216 gives the offset to the name table from the start of the LibBlk
     357struct */
     358
     359typedef struct {
     360/*00*/  WORD magic;             /* 0x0501 */
     361/*02*/  DWORD href_table;       /* if not 0xffffffff, then byte offset from
     362                                   beginning of struct to href table */
     363/*06*/  DWORD res06;            /* 0xffffffff */
     364/*0a*/  DWORD elem_table;       /* offset to members */
     365/*0e*/  DWORD res0e;            /* 0xffffffff */
     366/*12*/  WORD major_version;     /* major version number */
     367/*14*/  WORD minor_version;     /* minor version number */
     368/*16*/  DWORD res16;    /* 0xfffe0000 */
     369/*1a*/  BYTE typeflags1;/* 0x02 | top 5 bits hold l5sbs of TYPEFLAGS */
     370/*1b*/  BYTE typeflags2;/* TYPEFLAGS >> 5 */
     371/*1c*/  BYTE typeflags3;/* 0x02*/
     372/*1d*/  BYTE typekind;  /* 0x03 == TKIND_INTERFACE etc. */
     373/*1e*/  DWORD res1e;    /* 0x00000000 or 0xffffffff */
     374} SLTG_TypeInfoHeader;
     375
     376#define SLTG_TIHEADER_MAGIC 0x0501
     377
     378typedef struct {
     379/*00*/ WORD res00; /* 0x0001 sometimes 0x0003 ?? */
     380/*02*/ WORD res02; /* 0xffff */
     381/*04*/ BYTE res04; /* 0x01 */
     382/*05*/ DWORD cbExtra; /* No of bytes that follow */
     383} SLTG_MemberHeader;
     384
     385typedef struct {
     386/*00*/  WORD magic;     /* 0x120a */
     387/*02*/  WORD next;      /* offset in bytes to next block from start of block
     388                           group, 0xffff if last item */
     389/*04*/  WORD name;      /* offset to name within name table */
     390/*06*/  WORD value;     /* offset to value from start of block group */
     391/*08*/  WORD res08;     /* 0x56 */
     392/*0a*/  DWORD memid;    /* memid */
     393/*0e*/  WORD helpcontext;/* 0xfffe == no context, 0x0001 == stored in EnumInfo struct, else offset
     394                            to value from start of block group */
     395/*10*/  WORD helpstring;/* offset from start of block group to string offset */
     396} SLTG_EnumItem;
     397
     398#define SLTG_ENUMITEM_MAGIC 0x120a
     399
     400
     401typedef struct {
     402        BYTE magic;     /* 0x4c or 0x6c */
     403        BYTE inv;       /* high nibble is INVOKE_KIND, low nibble = 2 */
     404        WORD next;      /* byte offset from beginning of group to next fn */
     405        WORD name;      /* Offset within name table to name */
     406        DWORD dispid;   /* dispid */
     407        WORD helpcontext; /* helpcontext (again 1 is special) */
     408        WORD helpstring;/* helpstring offset to offset */
     409        WORD arg_off;   /* offset to args from start of block */
     410        BYTE nacc;      /* lowest 3bits are CALLCONV, rest are no of args */
     411        BYTE retnextopt;/* if 0x80 bit set ret type follows else next WORD
     412                           is offset to ret type. No of optional args is
     413                           middle 6 bits */
     414        WORD rettype;   /* return type VT_?? or offset to ret type */
     415        WORD vtblpos;   /* position in vtbl? */
     416        WORD funcflags; /* present if magic == 0x6c */
     417/* Param list starts, repeat next two as required */
     418#if 0
     419        WORD  name;     /* offset to 2nd letter of name */
     420        WORD+ type;     /* VT_ of param */
     421#endif
     422} SLTG_Function;
     423
     424#define SLTG_FUNCTION_MAGIC 0x4c
     425#define SLTG_FUNCTION_WITH_FLAGS_MAGIC 0x6c
     426
     427typedef struct {
     428/*00*/  BYTE magic;             /* 0xdf */
     429/*01*/  BYTE res01;             /* 0x00 */
     430/*02*/  DWORD res02;            /* 0xffffffff */
     431/*06*/  DWORD res06;            /* 0xffffffff */
     432/*0a*/  DWORD res0a;            /* 0xffffffff */
     433/*0e*/  DWORD res0e;            /* 0xffffffff */
     434/*12*/  DWORD res12;            /* 0xffffffff */
     435/*16*/  DWORD res16;            /* 0xffffffff */
     436/*1a*/  DWORD res1a;            /* 0xffffffff */
     437/*1e*/  DWORD res1e;            /* 0xffffffff */
     438/*22*/  DWORD res22;            /* 0xffffffff */
     439/*26*/  DWORD res26;            /* 0xffffffff */
     440/*2a*/  DWORD res2a;            /* 0xffffffff */
     441/*2e*/  DWORD res2e;            /* 0xffffffff */
     442/*32*/  DWORD res32;            /* 0xffffffff */
     443/*36*/  DWORD res36;            /* 0xffffffff */
     444/*3a*/  DWORD res3a;            /* 0xffffffff */
     445/*3e*/  DWORD res3e;            /* 0xffffffff */
     446/*42*/  WORD  res42;            /* 0xffff */
     447/*44*/  DWORD number;           /* this is 8 times the number of refs */
     448/*48*/  /* Now we have number bytes (8 for each ref) of SLTG_UnknownRefInfo */
     449
     450/*50*/  WORD res50;             /* 0xffff */
     451/*52*/  BYTE res52;             /* 0x01 */
     452/*53*/  DWORD res53;            /* 0x00000000 */
     453/*57*/  SLTG_Name names[1];
     454  /*    Now we have number/8 SLTG_Names (first WORD is no of bytes in the ascii
     455   *    string).  Strings look like "*\Rxxxx*#n".  If xxxx == ffff then the
     456   *    ref refers to the nth type listed in this library (0 based).  Else
     457   *    the xxxx (which maybe fewer than 4 digits) is the offset into the name
     458   *    table to a string "*\G{<guid>}#1.0#0#C:\WINNT\System32\stdole32.tlb#"
     459   *    The guid is the typelib guid; the ref again refers to the nth type of
     460   *    the imported typelib.
     461   */
     462
     463/*xx*/ BYTE resxx;              /* 0xdf */
     464
     465} SLTG_RefInfo;
     466
     467#define SLTG_REF_MAGIC 0xdf
     468
     469typedef struct {
     470        WORD res00;     /* 0x0001 */
     471        BYTE res02;     /* 0x02 */
     472        BYTE res03;     /* 0x40 if internal ref, 0x00 if external ? */
     473        WORD res04;     /* 0xffff */
     474        WORD res06;     /* 0x0000, 0x0013 or 0xffff ?? */
     475} SLTG_UnknownRefInfo;
     476
     477typedef struct {
     478  WORD res00; /* 0x004a */
     479  WORD next;  /* byte offs to next interface */
     480  WORD res04; /* 0xffff */
     481  BYTE impltypeflags; /* IMPLTYPEFLAG_* */
     482  BYTE res07; /* 0x80 */
     483  WORD res08; /* 0x0012, 0x0028 ?? */
     484  WORD ref;   /* number in ref table ? */
     485  WORD res0c; /* 0x4000 */
     486  WORD res0e; /* 0xfffe */
     487  WORD res10; /* 0xffff */
     488  WORD res12; /* 0x001d */
     489  WORD pos_in_table; /* 0x0, 0x4, ? */
     490} SLTG_ImplInfo;
     491
     492#define SLTG_IMPL_MAGIC 0x004a
     493
     494typedef struct {
     495  BYTE magic; /* 0x0a */
     496  BYTE typepos;
     497  WORD next;
     498  WORD name;
     499  WORD byte_offs; /* pos in struct */
     500  WORD type; /* if typepos == 0x02 this is the type, else offset to type */
     501  DWORD memid;
     502  WORD helpcontext; /* ?? */
     503  WORD helpstring; /* ?? */
     504} SLTG_RecordItem;
     505
     506#define SLTG_RECORD_MAGIC 0x0a
     507
     508
     509/* CARRAYs look like this
     510WORD type == VT_CARRAY
     511WORD offset from start of block to SAFEARRAY
     512WORD typeofarray
     513*/
     514
     515#include "poppack.h"
    235516
    236517/*---------------------------END--------------------------------------------*/
    237518#endif
     519
     520
  • trunk/src/oleaut32/variant.c

    r6648 r6689  
    1 /* $Id: variant.c,v 1.5 2001-09-05 13:19:02 bird Exp $ */
    21/*
    32 * VARIANT
Note: See TracChangeset for help on using the changeset viewer.