typelib.c 50.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * OleView (typelib.c)
 *
 * Copyright 2006 Piotr Caban
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "main.h"

23
#include "wine/debug.h"
24
#include "wine/unicode.h"
25 26 27

WINE_DEFAULT_DEBUG_CHANNEL(oleview);

28 29 30
TYPELIB typelib;
static const WCHAR wszTypeLib[] = { 'T','Y','P','E','L','I','B','\0' };

31 32 33
static const WCHAR wszFailed[] = { '<','f','a','i','l','e','d','>','\0' };
static const WCHAR wszSpace[] = { ' ','\0' };
static const WCHAR wszAsterix[] = { '*','\0' };
34
static const WCHAR wszComa[] = { ',','\0' };
35
static const WCHAR wszEquals[] = { '=','\0' };
36 37 38 39 40 41
static const WCHAR wszSemicolon[] = { ';','\0' };
static const WCHAR wszNewLine[] = { '\n','\0' };
static const WCHAR wszOpenBrackets1[] = { '[','\0' };
static const WCHAR wszCloseBrackets1[] = { ']','\0' };
static const WCHAR wszOpenBrackets2[] = { '(','\0' };
static const WCHAR wszCloseBrackets2[] = { ')','\0' };
42 43
static const WCHAR wszOpenBrackets3[] = { '{','\0' };
static const WCHAR wszCloseBrackets3[] = { '}','\0' };
44 45
static const WCHAR wszInvertedComa[] = { '"','\0' };
static const WCHAR wszColon[] = { ':','\0' };
46 47

static const WCHAR wszUUID[] = { 'u','u','i','d','\0' };
48
static const WCHAR wszOdl[] = { 'o','d','l','\0' };
49 50 51 52 53

static const WCHAR wszVT_BOOL[]
    = { 'V','A','R','I','A','N','T','_','B','O','O','L','\0' };
static const WCHAR wszVT_UI1[]
    = { 'u','n','s','i','g','n','e','d',' ','c','h','a','r','\0' };
54 55
static const WCHAR wszVT_UI2[]
    = { 'u','n','s','i','g','n','e','d',' ','s','h','o','r','t','\0' };
56 57
static const WCHAR wszVT_UI4[]
    = { 'u','n','s','i','g','n','e','d',' ','l','o','n','g','\0' };
58 59 60 61 62
static const WCHAR wszVT_UI8[] = { 'u','i','n','t','6','4','\0' };
static const WCHAR wszVT_UINT[]
    = { 'u','n','s','i','g','n','e','d',' ','i','n','t','\0' };
static const WCHAR wszVT_I1[] = { 'c','h','a','r','\0' };
static const WCHAR wszVT_I2[] = { 's','h','o','r','t','\0' };
63
static const WCHAR wszVT_I4[] = { 'l','o','n','g','\0' };
64
static const WCHAR wszVT_I8[] = { 'i','n','t','6','4','\0' };
65 66 67 68
static const WCHAR wszVT_R4[] = { 's','i','n','g','l','e','\0' };
static const WCHAR wszVT_INT[] = { 'i','n','t','\0' };
static const WCHAR wszVT_BSTR[] = { 'B','S','T','R','\0' };
static const WCHAR wszVT_CY[] = { 'C','U','R','R','E','N','C','Y','\0' };
69 70 71 72 73
static const WCHAR wszVT_VARIANT[] = { 'V','A','R','I','A','N','T','\0' };
static const WCHAR wszVT_VOID[] = { 'v','o','i','d','\0' };
static const WCHAR wszVT_ERROR[] = { 'S','C','O','D','E','\0' };
static const WCHAR wszVT_LPSTR[] = { 'L','P','S','T','R','\0' };
static const WCHAR wszVT_LPWSTR[] = { 'L','P','W','S','T','R','\0' };
74 75 76 77 78
static const WCHAR wszVT_HRESULT[] = { 'H','R','E','S','U','L','T','\0' };
static const WCHAR wszVT_UNKNOWN[] = { 'I','U','n','k','n','o','w','n','\0' };
static const WCHAR wszVT_DISPATCH[] = { 'I','D','i','s','p','a','t','c','h','\0' };
static const WCHAR wszVT_DATE[] = { 'D','A','T','E','\0' };
static const WCHAR wszVT_R8[] = { 'd','o','u','b','l','e','\0' };
79
static const WCHAR wszVT_SAFEARRAY[] = { 'S','A','F','E','A','R','R','A','Y','\0' };
80

81
const WCHAR wszFormat[] = { '0','x','%','.','8','l','x','\0' };
82
static const WCHAR wszStdCall[] = { '_','s','t','d','c','a','l','l','\0' };
83
static const WCHAR wszId[] = { 'i','d','\0' };
84 85 86 87 88 89 90
static const WCHAR wszPropPut[] = { 'p','r','o','p','p','u','t','\0' };
static const WCHAR wszPropGet[] = { 'p','r','o','p','g','e','t','\0' };
static const WCHAR wszPropPutRef[] = { 'p','r','o','p','p','u','t','r','e','f','\0' };
static const WCHAR wszPARAMFLAG_FIN[] = { 'i','n','\0' };
static const WCHAR wszPARAMFLAG_FOUT[] = { 'o','u','t','\0' };
static const WCHAR wszPARAMFLAG_FLCID[] = { 'c','i','d','\0' };
static const WCHAR wszPARAMFLAG_FRETVAL[] = { 'r','e','t','v','a','l','\0' };
91
static const WCHAR wszPARAMFLAG_FOPT[] = { 'o','p','t','i','o','n','a','l','\0' };
92 93
static const WCHAR wszPARAMFLAG_FHASCUSTDATA[]
    = { 'h','a','s','c','u','s','t','d','a','t','a','\0' };
94 95
static const WCHAR wszDefaultValue[]
    = { 'd','e','f','a','u','l','t','v','a','l','u','e','\0' };
96

97
static const WCHAR wszReadOnly[] = { 'r','e','a','d','o','n','l','y','\0' };
98
static const WCHAR wszConst[] = { 'c','o','n','s','t','\0' };
99

100
static void ShowLastError(void)
101 102 103 104 105 106 107 108 109 110 111 112 113 114
{
    DWORD error = GetLastError();
    LPWSTR lpMsgBuf;
    WCHAR wszTitle[MAX_LOAD_STRING];

    LoadString(globals.hMainInst, IDS_TYPELIBTITLE, wszTitle,
            sizeof(WCHAR[MAX_LOAD_STRING]));
    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
            NULL, error, 0, (LPTSTR) &lpMsgBuf, 0, NULL);
    MessageBox(NULL, lpMsgBuf, wszTitle, MB_OK | MB_ICONERROR);
    LocalFree(lpMsgBuf);
    return;
}

115
static void SaveIdl(WCHAR *wszFileName)
116 117 118 119
{
    HTREEITEM hIDL;
    TVITEM tvi;
    HANDLE hFile;
120
    DWORD len, dwNumWrite;
121
    char *wszIdl;
122
    TYPELIB_DATA *data;
123 124 125 126 127 128 129

    hIDL = TreeView_GetChild(typelib.hTree, TVI_ROOT);

    memset(&tvi, 0, sizeof(TVITEM));
    tvi.hItem = hIDL;

    SendMessage(typelib.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
130
    data = (TYPELIB_DATA *)tvi.lParam;
131 132

    hFile = CreateFile(wszFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
133
                       NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
134 135 136 137 138 139
    if(hFile == INVALID_HANDLE_VALUE)
    {
        ShowLastError();
        return;
    }

140 141 142
    len = WideCharToMultiByte( CP_UTF8, 0, data->idl, data->idlLen, NULL, 0, NULL, NULL );
    wszIdl = HeapAlloc(GetProcessHeap(), 0, len);
    WideCharToMultiByte( CP_UTF8, 0, data->idl, data->idlLen, wszIdl, len, NULL, NULL );
143

144 145
    if(!WriteFile(hFile, wszIdl, len, &dwNumWrite, NULL))
        ShowLastError();
146 147 148 149 150

    HeapFree(GetProcessHeap(), 0, wszIdl);
    CloseHandle(hFile);
}

151
static void GetSaveIdlAsPath(void)
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
{
    OPENFILENAME saveidl;
    WCHAR *pFileName;
    WCHAR wszPath[MAX_LOAD_STRING];
    WCHAR wszDir[MAX_LOAD_STRING];
    static const WCHAR wszDefaultExt[] = { 'i','d','l',0 };
    static const WCHAR wszIdlFiles[] = { '*','.','i','d','l','\0','\0' };

    memset(&saveidl, 0, sizeof(saveidl));

    lstrcpyW(wszDir, typelib.wszFileName);
    pFileName = wszDir + lstrlenW(wszDir);
    while(*pFileName != '.' && *pFileName != '\\' && *pFileName != '/'
            && pFileName > wszDir) pFileName -= 1;
    if(*pFileName == '.')
    {
        *pFileName = '\0';
        while(*pFileName != '\\' && *pFileName != '/' && pFileName > wszDir)
            pFileName -= 1;
    }
    if(*pFileName == '\\' || *pFileName == '/') pFileName += 1;
    lstrcpyW(wszPath, pFileName);

    GetCurrentDirectory(MAX_LOAD_STRING, wszDir);

    saveidl.lStructSize = sizeof(OPENFILENAME);
    saveidl.hwndOwner = globals.hTypeLibWnd;
    saveidl.hInstance = globals.hMainInst;
    saveidl.lpstrFilter = wszIdlFiles;
    saveidl.lpstrFile = wszPath;
    saveidl.nMaxFile = MAX_LOAD_STRING;
    saveidl.lpstrInitialDir = wszDir;
    saveidl.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
    saveidl.lpstrDefExt = wszDefaultExt;

    if (GetSaveFileName(&saveidl))
        SaveIdl(wszPath);
}

191 192 193 194 195
void AddToStrW(WCHAR *wszDest, const WCHAR *wszSource)
{
    lstrcpyW(&wszDest[lstrlenW(wszDest)], wszSource);
}

196 197 198 199 200 201
void AddToTLDataStrW(TYPELIB_DATA *pTLData, const WCHAR *wszSource)
{
    int SourceLen = lstrlenW(wszSource);

    pTLData->idl = HeapReAlloc(GetProcessHeap(), 0, pTLData->idl,
            sizeof(WCHAR)*(pTLData->idlLen+SourceLen+1));
202

203 204 205 206
    memcpy(&pTLData->idl[pTLData->idlLen], wszSource, sizeof(WCHAR)*(SourceLen+1));
    pTLData->idlLen += SourceLen;
}

207
void AddToTLDataStrWithTabsW(TYPELIB_DATA *pTLData, WCHAR *wszSource)
208 209 210 211 212 213
{
    int lineLen = lstrlenW(wszSource);
    int newLinesNo = 0;
    WCHAR *pSourcePos = (WCHAR *)wszSource;
    WCHAR *pSourceBeg;

214
    if(!lineLen) return;
215 216 217 218 219
    while(*pSourcePos)
    {
        if(*pSourcePos == *wszNewLine) newLinesNo++;
        pSourcePos += 1;
    }
220
    if(*(pSourcePos - 1) != *wszNewLine) newLinesNo++;
221 222 223 224 225 226

    pTLData->idl = HeapReAlloc(GetProcessHeap(), 0, pTLData->idl,
            sizeof(WCHAR)*(pTLData->idlLen+lineLen+4*newLinesNo+1));

    pSourcePos = (WCHAR *)wszSource;
    pSourceBeg = (WCHAR *)wszSource;
227
    while(newLinesNo)
228
    {
229
        if(*pSourcePos != *wszNewLine && *pSourcePos)
230 231 232 233
        {
            pSourcePos += 1;
            continue;
        }
234 235
        newLinesNo--;

236
        if(*pSourcePos)
237 238 239 240 241 242
        {
            *pSourcePos = '\0';
            lineLen = lstrlenW(pSourceBeg)+1;
            *pSourcePos = '\n';
            pSourcePos += 1;
        }
243
        else lineLen = lstrlenW(pSourceBeg);
244 245 246 247 248 249 250

        pTLData->idl[pTLData->idlLen] = *wszSpace;
        pTLData->idl[pTLData->idlLen+1] = *wszSpace;
        pTLData->idl[pTLData->idlLen+2] = *wszSpace;
        pTLData->idl[pTLData->idlLen+3] = *wszSpace;
        memcpy(&pTLData->idl[pTLData->idlLen+4], pSourceBeg, sizeof(WCHAR)*lineLen);
        pTLData->idlLen += lineLen + 4;
251
        pTLData->idl[pTLData->idlLen] = '\0';
252 253 254 255 256

        pSourceBeg = pSourcePos;
    }
}

257
static TYPELIB_DATA *InitializeTLData(void)
258 259 260
{
    TYPELIB_DATA *pTLData;

261
    pTLData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TYPELIB_DATA));
262 263

    pTLData->idl = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR));
264
    pTLData->idl[0] = '\0';
265

266
    return pTLData;
267 268
}

269
static void AddSpaces(TYPELIB_DATA *pTLData, int tabSize)
270 271 272 273 274
{
    for(; tabSize>0; tabSize--)
        AddToTLDataStrW(pTLData, wszSpace);
}

275
static void AddChildrenData(HTREEITEM hParent, TYPELIB_DATA *pData)
276 277 278 279 280 281 282
{
    HTREEITEM hCur;
    TVITEM tvi;

    memset(&tvi, 0, sizeof(&tvi));

    hCur = TreeView_GetChild(typelib.hTree, hParent);
283 284
    if(!hCur) return;

285 286 287 288 289
    do
    {
        tvi.hItem = hCur;
        SendMessage(typelib.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
        if(tvi.lParam && ((TYPELIB_DATA *)(tvi.lParam))->idlLen)
290
            AddToTLDataStrWithTabsW(pData, ((TYPELIB_DATA *)(tvi.lParam))->idl);
291 292 293
    }while((hCur = TreeView_GetNextSibling(typelib.hTree, hCur)));
}

294
static void CreateTypeInfo(WCHAR *wszAddTo, WCHAR *wszAddAfter, TYPEDESC tdesc, ITypeInfo *pTypeInfo)
295
{
296
    int i;
297 298 299
    BSTR bstrData;
    HRESULT hRes;
    ITypeInfo *pRefTypeInfo;
300 301
    WCHAR wszBuf[MAX_LOAD_STRING];
    WCHAR wszFormat[] = { '[','%','l','u',']','\0' };
302 303 304 305 306 307 308 309

    switch(tdesc.vt&VT_TYPEMASK)
    {
#define VTADDTOSTR(x) case x:\
        AddToStrW(wszAddTo, wsz##x);\
        break
        VTADDTOSTR(VT_BOOL);
        VTADDTOSTR(VT_UI1);
310
        VTADDTOSTR(VT_UI2);
311
        VTADDTOSTR(VT_UI4);
312 313 314 315
        VTADDTOSTR(VT_UI8);
        VTADDTOSTR(VT_UINT);
        VTADDTOSTR(VT_I1);
        VTADDTOSTR(VT_I2);
316
        VTADDTOSTR(VT_I4);
317
        VTADDTOSTR(VT_I8);
318 319 320 321
        VTADDTOSTR(VT_R4);
        VTADDTOSTR(VT_INT);
        VTADDTOSTR(VT_BSTR);
        VTADDTOSTR(VT_CY);
322 323 324 325 326
        VTADDTOSTR(VT_VARIANT);
        VTADDTOSTR(VT_VOID);
        VTADDTOSTR(VT_ERROR);
        VTADDTOSTR(VT_LPSTR);
        VTADDTOSTR(VT_LPWSTR);
327 328 329 330 331
        VTADDTOSTR(VT_HRESULT);
        VTADDTOSTR(VT_UNKNOWN);
        VTADDTOSTR(VT_DISPATCH);
        VTADDTOSTR(VT_DATE);
        VTADDTOSTR(VT_R8);
332 333 334 335 336 337 338 339
        case VT_CARRAY:
        for(i=0; i<U(tdesc).lpadesc->cDims; i++)
        {
            wsprintfW(wszBuf, wszFormat, U(tdesc).lpadesc->rgbounds[i].cElements);
            AddToStrW(wszAddAfter, wszBuf);
        }
        CreateTypeInfo(wszAddTo, wszAddAfter, U(tdesc).lpadesc->tdescElem, pTypeInfo);
        break;
340 341 342 343 344 345
	case VT_SAFEARRAY:
	AddToStrW(wszAddTo, wszVT_SAFEARRAY);
	AddToStrW(wszAddTo, wszOpenBrackets2);
        CreateTypeInfo(wszAddTo, wszAddAfter, *U(tdesc).lptdesc, pTypeInfo);
        AddToStrW(wszAddTo, wszCloseBrackets2);
	break;
346
        case VT_PTR:
347
        CreateTypeInfo(wszAddTo, wszAddAfter, *U(tdesc).lptdesc, pTypeInfo);
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
        AddToStrW(wszAddTo, wszAsterix);
        break;
        case VT_USERDEFINED:
        hRes = ITypeInfo_GetRefTypeInfo(pTypeInfo,
                U(tdesc).hreftype, &pRefTypeInfo);
        if(SUCCEEDED(hRes))
        {
            ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL,
                    &bstrData, NULL, NULL, NULL);
            AddToStrW(wszAddTo, bstrData);
            SysFreeString(bstrData);
            ITypeInfo_Release(pRefTypeInfo);
        }
        else AddToStrW(wszAddTo, wszFailed);
        break;
        default:
        WINE_FIXME("tdesc.vt&VT_TYPEMASK == %d not supported\n",
                tdesc.vt&VT_TYPEMASK);
    }
}

369
static int EnumVars(ITypeInfo *pTypeInfo, int cVars, HTREEITEM hParent)
370 371 372 373 374 375 376 377
{
    int i;
    TVINSERTSTRUCT tvis;
    VARDESC *pVarDesc;
    BSTR bstrName;
    WCHAR wszText[MAX_LOAD_STRING];
    WCHAR wszAfter[MAX_LOAD_STRING];

378
    U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
379 380 381 382 383 384 385
    U(tvis).item.cchTextMax = MAX_LOAD_STRING;
    U(tvis).item.pszText = wszText;
    tvis.hInsertAfter = (HTREEITEM)TVI_LAST;
    tvis.hParent = hParent;

    for(i=0; i<cVars; i++)
    {
386 387
        TYPELIB_DATA *tld;

388 389 390 391
        if(FAILED(ITypeInfo_GetVarDesc(pTypeInfo, i, &pVarDesc))) continue;
        if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo, pVarDesc->memid, &bstrName,
                NULL, NULL, NULL))) continue;

392 393
        tld = InitializeTLData();
        U(tvis).item.lParam = (LPARAM) tld;
394 395
        if(pVarDesc->memid < MIN_VAR_ID)
        {
396 397 398 399

            AddToTLDataStrW(tld, wszOpenBrackets1);
            AddToTLDataStrW(tld, wszId);
            AddToTLDataStrW(tld, wszOpenBrackets2);
400
            wsprintfW(wszText, wszFormat, pVarDesc->memid);
401
            AddToTLDataStrW(tld, wszText);
402
            memset(wszText, 0, sizeof(wszText));
403
            AddToTLDataStrW(tld, wszCloseBrackets2);
404 405 406

            if(pVarDesc->wVarFlags & VARFLAG_FREADONLY)
            {
407 408 409
                AddToTLDataStrW(tld, wszComa);
                AddToTLDataStrW(tld, wszSpace);
                AddToTLDataStrW(tld, wszReadOnly);
410
            }
411 412
            AddToTLDataStrW(tld, wszCloseBrackets1);
            AddToTLDataStrW(tld, wszNewLine);
413 414
        }

415 416 417 418 419 420
        memset(wszText, 0, sizeof(wszText));
        memset(wszAfter, 0, sizeof(wszAfter));
        CreateTypeInfo(wszText, wszAfter, pVarDesc->elemdescVar.tdesc, pTypeInfo);
        AddToStrW(wszText, wszSpace);
        AddToStrW(wszText, bstrName);
        AddToStrW(wszText, wszAfter);
421 422 423
        AddToTLDataStrW(tld, wszText);
        AddToTLDataStrW(tld, wszSemicolon);
        AddToTLDataStrW(tld, wszNewLine);
424 425 426 427 428 429 430 431 432

        SendMessage(typelib.hTree, TVM_INSERTITEM, 0, (LPARAM)&tvis);
        SysFreeString(bstrName);
        ITypeInfo_ReleaseVarDesc(pTypeInfo, pVarDesc);
    }

    return 0;
}

433
static int EnumEnums(ITypeInfo *pTypeInfo, int cVars, HTREEITEM hParent)
434 435 436 437 438 439
{
    int i;
    TVINSERTSTRUCT tvis;
    VARDESC *pVarDesc;
    BSTR bstrName;
    WCHAR wszText[MAX_LOAD_STRING];
440
    WCHAR wszAfter[MAX_LOAD_STRING];
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459

    U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
    U(tvis).item.cchTextMax = MAX_LOAD_STRING;
    U(tvis).item.pszText = wszText;
    tvis.hInsertAfter = (HTREEITEM)TVI_LAST;
    tvis.hParent = hParent;

    for(i=0; i<cVars; i++)
    {
        TYPELIB_DATA *tld;

        if(FAILED(ITypeInfo_GetVarDesc(pTypeInfo, i, &pVarDesc))) continue;
        if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo, pVarDesc->memid, &bstrName,
                NULL, NULL, NULL))) continue;

        tld = InitializeTLData();
        U(tvis).item.lParam = (LPARAM) tld;

        memset(wszText, 0, sizeof(wszText));
460
        memset(wszAfter, 0, sizeof(wszAfter));
461 462 463 464 465

        if (pVarDesc->varkind == VAR_CONST)
        {
            VARIANT var;
            VariantInit(&var);
466
            if (VariantChangeType(&var, U(*pVarDesc).lpvarValue, 0, VT_BSTR) == S_OK)
467
            {
468
                AddToStrW(wszText, wszConst);
469
                AddToStrW(wszText, wszSpace);
470 471 472 473
                AddToStrW(wszAfter, wszSpace);
                AddToStrW(wszAfter, wszEquals);
                AddToStrW(wszAfter, wszSpace);
                AddToStrW(wszAfter, V_BSTR(&var));
474 475 476
            }
        }

477 478 479 480 481 482
        CreateTypeInfo(wszText, wszAfter, pVarDesc->elemdescVar.tdesc, pTypeInfo);
        AddToStrW(wszText, wszSpace);
        AddToStrW(wszText, bstrName);
        AddToStrW(wszText, wszAfter);
	AddToTLDataStrW(tld, bstrName);
        AddToTLDataStrW(tld, wszAfter);
483 484 485 486 487 488 489 490 491 492 493 494
	if (i<cVars-1)
            AddToTLDataStrW(tld, wszComa);
        AddToTLDataStrW(tld, wszNewLine);

        SendMessage(typelib.hTree, TVM_INSERTITEM, 0, (LPARAM)&tvis);
        SysFreeString(bstrName);
        ITypeInfo_ReleaseVarDesc(pTypeInfo, pVarDesc);
    }

    return 0;
}

495
static int EnumFuncs(ITypeInfo *pTypeInfo, int cFuncs, HTREEITEM hParent)
496
{
497 498
    int i, j, tabSize;
    unsigned namesNo;
499 500
    TVINSERTSTRUCT tvis;
    FUNCDESC *pFuncDesc;
501 502 503
    BSTR bstrName, *bstrParamNames;
    WCHAR wszText[MAX_LOAD_STRING];
    WCHAR wszAfter[MAX_LOAD_STRING];
504
    WCHAR szRhs[] = {'r','h','s',0};    /* Right-hand side of a propput */
505
    BOOL bFirst;
506

507
    U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
508 509 510 511 512
    tvis.hInsertAfter = (HTREEITEM)TVI_LAST;
    tvis.hParent = hParent;

    for(i=0; i<cFuncs; i++)
    {
513 514
        TYPELIB_DATA *tld;

515 516 517 518
        if(FAILED(ITypeInfo_GetFuncDesc(pTypeInfo, i, &pFuncDesc))) continue;
        if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo, pFuncDesc->memid, &bstrName,
                NULL, NULL, NULL))) continue;

519 520 521
        bstrParamNames = HeapAlloc(GetProcessHeap(), 0,
                sizeof(BSTR*)*(pFuncDesc->cParams+1));
        if(FAILED(ITypeInfo_GetNames(pTypeInfo, pFuncDesc->memid, bstrParamNames,
522 523 524 525 526
                pFuncDesc->cParams+1, &namesNo)))
        {
            HeapFree(GetProcessHeap(), 0, bstrParamNames);
            continue;
        }
527 528 529 530
        SysFreeString(bstrParamNames[0]);

        memset(wszText, 0, sizeof(wszText));
        memset(wszAfter, 0, sizeof(wszAfter));
531
        tld = InitializeTLData();
532 533
        U(tvis).item.cchTextMax = SysStringLen(bstrName);
        U(tvis).item.pszText = bstrName;
534
        U(tvis).item.lParam = (LPARAM) tld;
535 536 537
        bFirst = TRUE;
        if(pFuncDesc->memid < MIN_FUNC_ID)
        {
538
            AddToTLDataStrW(tld, wszOpenBrackets1);
539
            bFirst = FALSE;
540 541
            AddToTLDataStrW(tld, wszId);
            AddToTLDataStrW(tld, wszOpenBrackets2);
542
            wsprintfW(wszText, wszFormat, pFuncDesc->memid);
543 544
            AddToTLDataStrW(tld, wszText);
            AddToTLDataStrW(tld, wszCloseBrackets2);
545 546
            memset(wszText, 0, sizeof(wszText));
        }
547 548 549 550
        CreateTypeInfo(wszText, wszAfter, pFuncDesc->elemdescFunc.tdesc, pTypeInfo);
        switch(pFuncDesc->invkind)
        {
            case INVOKE_PROPERTYGET:
551
                if(bFirst) AddToTLDataStrW(tld, wszOpenBrackets1);
552 553
                else
                {
554 555
                    AddToTLDataStrW(tld, wszComa);
                    AddToTLDataStrW(tld, wszSpace);
556 557
                }
                bFirst = FALSE;
558
                AddToTLDataStrW(tld, wszPropGet);
559 560
                break;
            case INVOKE_PROPERTYPUT:
561
                if(bFirst) AddToTLDataStrW(tld, wszOpenBrackets1);
562 563
                else
                {
564 565
                    AddToTLDataStrW(tld, wszComa);
                    AddToTLDataStrW(tld, wszSpace);
566 567
                }
                bFirst = FALSE;
568
                AddToTLDataStrW(tld, wszPropPut);
569 570
                break;
            case INVOKE_PROPERTYPUTREF:
571
                if(bFirst) AddToTLDataStrW(tld, wszOpenBrackets1);
572 573
                else
                {
574 575
                    AddToTLDataStrW(tld, wszComa);
                    AddToTLDataStrW(tld, wszSpace);
576 577
                }
                bFirst = FALSE;
578
                AddToTLDataStrW(tld, wszPropPutRef);
579 580 581
                break;
            default:;
        }
582 583
        if(!bFirst)
        {
584 585
            AddToTLDataStrW(tld, wszCloseBrackets1);
            AddToTLDataStrW(tld, wszNewLine);
586
        }
587 588 589
        AddToTLDataStrW(tld, wszText);
        AddToTLDataStrW(tld, wszAfter);
        AddToTLDataStrW(tld, wszSpace);
590 591
        if(pFuncDesc->memid >= MIN_FUNC_ID)
        {
592 593
            AddToTLDataStrW(tld, wszStdCall);
            AddToTLDataStrW(tld, wszSpace);
594
        }
595 596 597
        tabSize = tld->idlLen;
        AddToTLDataStrW(tld, bstrName);
        AddToTLDataStrW(tld, wszOpenBrackets2);
598

599
        for(j=0; j<pFuncDesc->cParams; j++)
600
        {
601
            if(j != 0) AddToTLDataStrW(tld, wszComa);
602
            if(pFuncDesc->cParams != 1)
603
            {
604 605
                AddToTLDataStrW(tld, wszNewLine);
                AddSpaces(tld, tabSize);
606
            }
607 608
            bFirst = TRUE;
#define ENUM_PARAM_FLAG(x)\
609
            if(U(pFuncDesc->lprgelemdescParam[j]).paramdesc.wParamFlags & x) \
610
            {\
611
                if(bFirst) AddToTLDataStrW(tld,\
612 613 614
                        wszOpenBrackets1);\
                else\
                {\
615 616
                    AddToTLDataStrW(tld, wszComa);\
                    AddToTLDataStrW(tld, wszSpace);\
617 618
                }\
                bFirst = FALSE;\
619
                AddToTLDataStrW(tld, wsz##x);\
620 621 622 623 624 625 626 627
            }
            ENUM_PARAM_FLAG(PARAMFLAG_FIN);
            ENUM_PARAM_FLAG(PARAMFLAG_FOUT);
            ENUM_PARAM_FLAG(PARAMFLAG_FLCID);
            ENUM_PARAM_FLAG(PARAMFLAG_FRETVAL);
            ENUM_PARAM_FLAG(PARAMFLAG_FOPT);
            ENUM_PARAM_FLAG(PARAMFLAG_FHASCUSTDATA);

628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
            if(U(pFuncDesc->lprgelemdescParam[j]).paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT)
            {
		VARIANT var, *param=&U(pFuncDesc->lprgelemdescParam[j]).paramdesc.pparamdescex->varDefaultValue;
		VariantInit(&var);
                if(bFirst) AddToTLDataStrW(tld,
                        wszOpenBrackets1);
                else
                {
                    AddToTLDataStrW(tld, wszComa);
                    AddToTLDataStrW(tld, wszSpace);
                }
                bFirst = FALSE;
                AddToTLDataStrW(tld, wszDefaultValue);
                AddToTLDataStrW(tld, wszOpenBrackets2);
		if (V_VT(param) == VT_BSTR)
		{
		    AddToTLDataStrW(tld, wszInvertedComa);
		    AddToTLDataStrW(tld, V_BSTR(&var));
		    AddToTLDataStrW(tld, wszInvertedComa);
		} else if (VariantChangeType(&var, param, 0, VT_BSTR) == S_OK)
		    AddToTLDataStrW(tld, V_BSTR(&var));
                AddToTLDataStrW(tld, wszCloseBrackets2);
            }

652 653
            if(!bFirst)
            {
654 655
                AddToTLDataStrW(tld, wszCloseBrackets1);
                AddToTLDataStrW(tld, wszSpace);
656 657 658 659 660 661
            }

            memset(wszText, 0, sizeof(wszText));
            memset(wszAfter, 0, sizeof(wszAfter));
            CreateTypeInfo(wszText, wszAfter, pFuncDesc->lprgelemdescParam[j].tdesc,
                    pTypeInfo);
662 663 664
            AddToTLDataStrW(tld, wszText);
            AddToTLDataStrW(tld, wszAfter);
            AddToTLDataStrW(tld, wszSpace);
665 666 667 668 669 670
            if (j+1 < namesNo) {
                AddToTLDataStrW(tld, bstrParamNames[j+1]);
                SysFreeString(bstrParamNames[j+1]);
            } else {
                AddToTLDataStrW(tld, szRhs);
            }
671
        }
672 673 674
        AddToTLDataStrW(tld, wszCloseBrackets2);
        AddToTLDataStrW(tld, wszSemicolon);
        AddToTLDataStrW(tld, wszNewLine);
675 676

        SendMessage(typelib.hTree, TVM_INSERTITEM, 0, (LPARAM)&tvis);
677
        HeapFree(GetProcessHeap(), 0, bstrParamNames);
678 679 680 681 682 683 684
        SysFreeString(bstrName);
        ITypeInfo_ReleaseFuncDesc(pTypeInfo, pFuncDesc);
    }

    return 0;
}

685
static int EnumImplTypes(ITypeInfo *pTypeInfo, int cImplTypes, HTREEITEM hParent)
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
{
    int i;
    TVINSERTSTRUCT tvis;
    ITypeInfo *pRefTypeInfo;
    HREFTYPE hRefType;
    TYPEATTR *pTypeAttr;
    BSTR bstrName;
    WCHAR wszInheritedInterfaces[MAX_LOAD_STRING];

    if(!cImplTypes) return 0;

    LoadString(globals.hMainInst, IDS_INHERITINTERFACES, wszInheritedInterfaces,
            sizeof(WCHAR[MAX_LOAD_STRING]));

    U(tvis).item.mask = TVIF_TEXT;
    U(tvis).item.cchTextMax = MAX_LOAD_STRING;
    U(tvis).item.pszText = wszInheritedInterfaces;
    tvis.hInsertAfter = (HTREEITEM)TVI_LAST;
    tvis.hParent = hParent;

    tvis.hParent = TreeView_InsertItem(typelib.hTree, &tvis);

    for(i=0; i<cImplTypes; i++)
    {
        if(FAILED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo, i, &hRefType))) continue;
        if(FAILED(ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo)))
            continue;
        if(FAILED(ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
                NULL, NULL, NULL))) continue;
        if(FAILED(ITypeInfo_GetTypeAttr(pRefTypeInfo, &pTypeAttr))) continue;

        U(tvis).item.cchTextMax = SysStringLen(bstrName);
        U(tvis).item.pszText = bstrName;

        hParent = TreeView_InsertItem(typelib.hTree, &tvis);
        EnumVars(pRefTypeInfo, pTypeAttr->cVars, hParent);
        EnumFuncs(pRefTypeInfo, pTypeAttr->cFuncs, hParent);
        EnumImplTypes(pRefTypeInfo, pTypeAttr->cImplTypes, hParent);

        SysFreeString(bstrName);
        ITypeInfo_ReleaseTypeAttr(pRefTypeInfo, pTypeAttr);
        ITypeInfo_Release(pRefTypeInfo);
    }

    return 0;
}

733
static void AddIdlData(HTREEITEM hCur, TYPELIB_DATA *pTLData)
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
{
    TVITEM tvi;

    hCur = TreeView_GetChild(typelib.hTree, hCur);
    memset(&tvi, 0, sizeof(TVITEM));
    tvi.mask = TVIF_PARAM;

    while(hCur)
    {
        tvi.hItem = hCur;
        SendMessage(typelib.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
        AddToTLDataStrW(pTLData, wszNewLine);
        AddToTLDataStrWithTabsW(pTLData, ((TYPELIB_DATA*)(tvi.lParam))->idl);
        hCur = TreeView_GetNextSibling(typelib.hTree, hCur);
    }
}

751
static void AddPredefinitions(HTREEITEM hFirst, TYPELIB_DATA *pTLData)
752 753 754 755 756 757 758 759 760 761 762 763
{
    HTREEITEM hCur;
    TVITEM tvi;
    WCHAR wszText[MAX_LOAD_STRING];
    WCHAR wszPredefinition[] = { '/','/',' ','T','L','i','b',' ',':','\n',
        '/','/',' ','F','o','r','w','a','r','d',' ','d','e','c','l','a','r','e',' ',
        'a','l','l',' ','t','y','p','e','s',' ','d','e','f','i','n','e','d',' ',
        'i','n',' ','t','h','i','s',' ','t','y','p','e','l','i','b','\0' };

    hFirst = TreeView_GetChild(typelib.hTree, hFirst);

    AddToTLDataStrWithTabsW(pTLData, wszPredefinition);
764
    AddToTLDataStrW(pTLData, wszNewLine);
765 766 767 768 769 770 771 772 773 774 775 776 777 778

    hCur = hFirst;
    memset(&tvi, 0, sizeof(TVITEM));
    tvi.mask = TVIF_TEXT|TVIF_PARAM;
    tvi.cchTextMax = MAX_LOAD_STRING;
    tvi.pszText = wszText;
    while(hCur)
    {
        tvi.hItem = hCur;
        SendMessage(typelib.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
        if(((TYPELIB_DATA*)(tvi.lParam))->bPredefine)
        {
            AddToStrW(wszText, wszSemicolon);
            AddToTLDataStrWithTabsW(pTLData, wszText);
779
            AddToTLDataStrW(pTLData, wszNewLine);
780 781 782 783 784
        }
        hCur = TreeView_GetNextSibling(typelib.hTree, hCur);
    }
}

785
static void CreateInterfaceInfo(ITypeInfo *pTypeInfo, int cImplTypes, WCHAR *wszName,
786 787
        WCHAR *wszHelpString, unsigned long ulHelpContext, TYPEATTR *pTypeAttr,
        TYPELIB_DATA *pTLData)
788 789 790 791 792
{
    ITypeInfo *pRefTypeInfo;
    HREFTYPE hRefType;
    BSTR bstrName;
    WCHAR wszGuid[MAX_LOAD_STRING];
793
    WCHAR wszHelpContext[MAX_LOAD_STRING];
794

795
    const WCHAR wszInterface[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
796 797
    const WCHAR wszDispinterface[]
        = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
798
    const WCHAR wszHelpstring[] = { 'h','e','l','p','s','t','r','i','n','g','\0' };
799
    const WCHAR wszHelpcontext[] = { 'h','e','l','p','c','o','n','t','e','x','t','\0' };
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822
    const WCHAR wszTYPEFLAG_FAPPOBJECT[] = { 'a','p','p','o','b','j','e','c','t','\0' };
    const WCHAR wszTYPEFLAG_FCANCREATE[] = { 'c','a','n','c','r','e','a','t','e','\0' };
    const WCHAR wszTYPEFLAG_FLICENSED[] = { 'l','i','c','e','n','s','e','d','\0' };
    const WCHAR wszTYPEFLAG_FPREDECLID[] = { 'p','r','e','d','e','c','l','i','d','\0' };
    const WCHAR wszTYPEFLAG_FHIDDEN[] = { 'h','i','d','d','e','n','\0' };
    const WCHAR wszTYPEFLAG_FCONTROL[] = { 'c','o','n','t','r','o','l','\0' };
    const WCHAR wszTYPEFLAG_FDUAL[] = { 'd','u','a','l','\0' };
    const WCHAR wszTYPEFLAG_FNONEXTENSIBLE[]
        = { 'n','o','n','e','x','t','e','n','s','i','b','l','e','\0' };
    const WCHAR wszTYPEFLAG_FOLEAUTOMATION[]
        = { 'o','l','e','a','u','t','o','m','a','t','i','o','n','\0' };
    const WCHAR wszTYPEFLAG_FRESTRICTED[]
        = { 'r','e','s','t','r','i','c','t','e','d','\0' };
    const WCHAR wszTYPEFLAG_FAGGREGATABLE[]
        = { 'a','g','g','r','e','g','a','t','a','b','l','e','\0' };
    const WCHAR wszTYPEFLAG_FREPLACEABLE[]
        = { 'r','e','p','l','a','c','a','b','l','e','\0' };
    const WCHAR wszTYPEFLAG_FREVERSEBIND[]
        = { 'r','e','v','e','r','s','e','b','i','n','d','\0' };
    const WCHAR wszTYPEFLAG_FPROXY[] = { 'p','r','o','x','y','\0' };

    AddToTLDataStrW(pTLData, wszOpenBrackets1);
    AddToTLDataStrW(pTLData, wszNewLine);
823 824 825 826 827 828 829
    if(pTypeAttr->typekind != TKIND_DISPATCH)
    {
        AddSpaces(pTLData, 4);
        AddToTLDataStrW(pTLData, wszOdl);
        AddToTLDataStrW(pTLData, wszComa);
        AddToTLDataStrW(pTLData, wszNewLine);
    }
830
    AddSpaces(pTLData, 4);
831 832 833 834 835 836 837 838 839 840
    AddToTLDataStrW(pTLData, wszUUID);
    AddToTLDataStrW(pTLData, wszOpenBrackets2);
    StringFromGUID2(&(pTypeAttr->guid), wszGuid, MAX_LOAD_STRING);
    wszGuid[lstrlenW(wszGuid)-1] = '\0';
    AddToTLDataStrW(pTLData, &wszGuid[1]);
    AddToTLDataStrW(pTLData, wszCloseBrackets2);
    if(wszHelpString)
    {
        AddToTLDataStrW(pTLData, wszComa);
        AddToTLDataStrW(pTLData, wszNewLine);
841
        AddSpaces(pTLData, 4);
842 843 844 845 846 847 848
        AddToTLDataStrW(pTLData, wszHelpstring);
        AddToTLDataStrW(pTLData, wszOpenBrackets2);
        AddToTLDataStrW(pTLData, wszInvertedComa);
        AddToTLDataStrW(pTLData, wszHelpString);
        AddToTLDataStrW(pTLData, wszInvertedComa);
        AddToTLDataStrW(pTLData, wszCloseBrackets2);
    }
849 850 851 852
    if(ulHelpContext)
    {
        AddToTLDataStrW(pTLData, wszComa);
        AddToTLDataStrW(pTLData, wszNewLine);
853
        AddSpaces(pTLData, 4);
854 855 856 857 858 859
        AddToTLDataStrW(pTLData, wszHelpcontext);
        AddToTLDataStrW(pTLData, wszOpenBrackets2);
        wsprintfW(wszHelpContext, wszFormat, ulHelpContext);
        AddToTLDataStrW(pTLData, wszHelpContext);
        AddToTLDataStrW(pTLData, wszCloseBrackets2);
    }
860 861
    if(pTypeAttr->wTypeFlags)
    {
862 863
#define ENUM_FLAGS(x) if(pTypeAttr->wTypeFlags & x &&\
        (pTypeAttr->typekind != TKIND_DISPATCH || x != TYPEFLAG_FDISPATCHABLE))\
864
        {\
865 866 867
            AddToTLDataStrW(pTLData, wszComa);\
            AddToTLDataStrW(pTLData, wszNewLine);\
            AddSpaces(pTLData, 4);\
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887
            AddToTLDataStrW(pTLData, wsz##x);\
        }
        ENUM_FLAGS(TYPEFLAG_FAPPOBJECT);
        ENUM_FLAGS(TYPEFLAG_FCANCREATE);
        ENUM_FLAGS(TYPEFLAG_FLICENSED);
        ENUM_FLAGS(TYPEFLAG_FPREDECLID);
        ENUM_FLAGS(TYPEFLAG_FHIDDEN);
        ENUM_FLAGS(TYPEFLAG_FCONTROL);
        ENUM_FLAGS(TYPEFLAG_FDUAL);
        ENUM_FLAGS(TYPEFLAG_FNONEXTENSIBLE);
        ENUM_FLAGS(TYPEFLAG_FOLEAUTOMATION);
        ENUM_FLAGS(TYPEFLAG_FRESTRICTED);
        ENUM_FLAGS(TYPEFLAG_FAGGREGATABLE);
        ENUM_FLAGS(TYPEFLAG_FREPLACEABLE);
        ENUM_FLAGS(TYPEFLAG_FREVERSEBIND);
        ENUM_FLAGS(TYPEFLAG_FPROXY);
    }
    AddToTLDataStrW(pTLData, wszNewLine);
    AddToTLDataStrW(pTLData, wszCloseBrackets1);
    AddToTLDataStrW(pTLData, wszNewLine);
888 889
    if(pTypeAttr->typekind != TKIND_DISPATCH) AddToTLDataStrW(pTLData, wszInterface);
    else AddToTLDataStrW(pTLData, wszDispinterface);
890 891
    AddToTLDataStrW(pTLData, wszName);
    AddToTLDataStrW(pTLData, wszSpace);
892
    if(cImplTypes && pTypeAttr->typekind != TKIND_DISPATCH)
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
    {
        AddToTLDataStrW(pTLData, wszColon);
        AddToTLDataStrW(pTLData, wszSpace);

        ITypeInfo_GetRefTypeOfImplType(pTypeInfo, 0, &hRefType);
        ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo);
        ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
                NULL, NULL, NULL);
        AddToTLDataStrW(pTLData, bstrName);
        AddToTLDataStrW(pTLData, wszSpace);

        SysFreeString(bstrName);
        ITypeInfo_Release(pRefTypeInfo);
    }
    AddToTLDataStrW(pTLData, wszOpenBrackets3);
    AddToTLDataStrW(pTLData, wszNewLine);

    AddToStrW(pTLData->wszInsertAfter, wszCloseBrackets3);
    AddToStrW(pTLData->wszInsertAfter, wszSemicolon);
    AddToStrW(pTLData->wszInsertAfter, wszNewLine);
}

915
static void CreateTypedefHeader(ITypeInfo *pTypeInfo,
916 917 918 919 920 921 922 923 924 925
        TYPEATTR *pTypeAttr, TYPELIB_DATA *pTLData)
{
    BOOL bFirst = TRUE;
    WCHAR wszGuid[MAX_LOAD_STRING];
    const WCHAR wszTypedef[] = { 't','y','p','e','d','e','f',' ','\0' };
    const WCHAR wszPublic[] = { 'p','u','b','l','i','c','\0' };

    AddToTLDataStrW(pTLData, wszTypedef);
    if(memcmp(&pTypeAttr->guid, &GUID_NULL, sizeof(GUID)))
    {
926
        AddToTLDataStrW(pTLData, wszOpenBrackets1);
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
        bFirst = FALSE;
        AddToTLDataStrW(pTLData, wszUUID);
        AddToTLDataStrW(pTLData, wszOpenBrackets2);
        StringFromGUID2(&(pTypeAttr->guid), wszGuid, MAX_LOAD_STRING);
        wszGuid[lstrlenW(wszGuid)-1] = '\0';
        AddToTLDataStrW(pTLData, &wszGuid[1]);
        AddToTLDataStrW(pTLData, wszCloseBrackets2);
    }
    if(pTypeAttr->typekind == TKIND_ALIAS)
    {
        if(bFirst) AddToTLDataStrW(pTLData, wszOpenBrackets1);
        else
        {
            AddToTLDataStrW(pTLData, wszComa);
            AddToTLDataStrW(pTLData, wszSpace);
        }
        bFirst = FALSE;
        AddToTLDataStrW(pTLData, wszPublic);
    }
    if(!bFirst)
    {
        AddToTLDataStrW(pTLData, wszCloseBrackets1);
        AddToTLDataStrW(pTLData, wszNewLine);
    }
}

953
static int PopulateTree(void)
954 955
{
    TVINSERTSTRUCT tvis;
956
    TVITEM tvi;
957
    ITypeLib *pTypeLib;
958
    TLIBATTR *pTLibAttr;
959 960
    ITypeInfo *pTypeInfo, *pRefTypeInfo;
    HREFTYPE hRefType;
961
    TYPEATTR *pTypeAttr;
962
    INT count, i;
963
    ULONG ulHelpContext;
964
    BSTR bstrName;
965 966
    BSTR bstrData;
    WCHAR wszText[MAX_LOAD_STRING];
967
    WCHAR wszAfter[MAX_LOAD_STRING];
968
    HRESULT hRes;
969
    HTREEITEM hParent;
970 971 972
    HTREEITEM hMain;
    BOOL bInsert;
    TYPELIB_DATA *tldDispatch;
973
    TYPELIB_DATA *tld;
974

975 976 977 978 979 980
    const WCHAR wszGeneratedInfo[] = { '/','/',' ','G','e','n','e','r','a','t','e','d',
        ' ','.','I','D','L',' ','f','i','l','e',' ','(','b','y',' ','t','h','e',' ',
        'O','L','E','/','C','O','M',' ','O','b','j','e','c','t',' ',
        'V','i','e','w','e','r',')','\n','/','/','\n','/','/',' ',
        't','y','p','e','l','i','b',' ','f','i','l','e','n','a','m','e',':',' ','\0'};

981
    const WCHAR wszFormat[] = { '%','s',' ','(','%','s',')','\0' };
982 983
    const WCHAR wszFormat2[] = { 'v','e','r','s','i','o','n',
        '(','%','l','d','.','%','l','d',')','\0' };
984 985 986 987 988 989 990 991 992 993 994 995 996

    const WCHAR wszTKIND_ENUM[] = { 't','y','p','e','d','e','f',' ','e','n','u','m',' ','\0' };
    const WCHAR wszTKIND_RECORD[]
        = { 't','y','p','e','d','e','f',' ','s','t','r','u','c','t',' ','\0' };
    const WCHAR wszTKIND_MODULE[] = { 'm','o','d','u','l','e',' ','\0' };
    const WCHAR wszTKIND_INTERFACE[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
    const WCHAR wszTKIND_DISPATCH[]
        = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
    const WCHAR wszTKIND_COCLASS[] = { 'c','o','c','l','a','s','s',' ','\0' };
    const WCHAR wszTKIND_ALIAS[] = { 't','y','p','e','d','e','f',' ','\0' };
    const WCHAR wszTKIND_UNION[]
        = { 't','y','p','e','d','e','f',' ','u','n','i','o','n',' ','\0' };

997 998
    const WCHAR wszHelpString[] = { 'h','e','l','p','s','t','r','i','n','g','\0' };
    const WCHAR wszLibrary[] = { 'l','i','b','r','a','r','y',' ','\0' };
999
    const WCHAR wszTag[] = { 't','a','g','\0' };
1000

1001 1002 1003
    WCHAR wszProperties[] = { 'p','r','o','p','e','r','t','i','e','s','\0' };
    WCHAR wszMethods[] = { 'm','e','t','h','o','d','s','\0' };

1004
    U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
1005 1006
    U(tvis).item.cchTextMax = MAX_LOAD_STRING;
    U(tvis).item.pszText = wszText;
1007 1008 1009
    tvis.hInsertAfter = (HTREEITEM)TVI_LAST;
    tvis.hParent = TVI_ROOT;

1010
    if(FAILED((hRes = LoadTypeLib(typelib.wszFileName, &pTypeLib))))
1011 1012 1013 1014 1015 1016
    {
        WCHAR wszMessage[MAX_LOAD_STRING];
        WCHAR wszError[MAX_LOAD_STRING];

        LoadString(globals.hMainInst, IDS_ERROR_LOADTYPELIB,
                wszError, sizeof(WCHAR[MAX_LOAD_STRING]));
1017
        wsprintfW(wszMessage, wszError, typelib.wszFileName, hRes);
1018 1019 1020
        MessageBox(globals.hMainWnd, wszMessage, NULL, MB_OK|MB_ICONEXCLAMATION);
        return 1;
    }
1021 1022
    count = ITypeLib_GetTypeInfoCount(pTypeLib);

1023
    ITypeLib_GetDocumentation(pTypeLib, -1, &bstrName, &bstrData, NULL, NULL);
1024
    ITypeLib_GetLibAttr(pTypeLib, &pTLibAttr);
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036

    tld = InitializeTLData();
    U(tvis).item.lParam = (LPARAM) tld;
    AddToTLDataStrW(tld, wszGeneratedInfo);
    AddToTLDataStrW(tld, typelib.wszFileName);
    AddToTLDataStrW(tld, wszNewLine);
    AddToTLDataStrW(tld, wszNewLine);
    AddToTLDataStrW(tld, wszOpenBrackets1);
    AddToTLDataStrW(tld, wszNewLine);
    AddSpaces(tld, 4);
    AddToTLDataStrW(tld, wszUUID);
    AddToTLDataStrW(tld, wszOpenBrackets2);
1037 1038
    StringFromGUID2(&(pTLibAttr->guid), wszText, MAX_LOAD_STRING);
    wszText[lstrlenW(wszText)-1] = '\0';
1039 1040 1041 1042 1043
    AddToTLDataStrW(tld, &wszText[1]);
    AddToTLDataStrW(tld, wszCloseBrackets2);
    AddToTLDataStrW(tld, wszComa);
    AddToTLDataStrW(tld, wszNewLine);
    AddSpaces(tld, 4);
1044
    wsprintfW(wszText, wszFormat2, pTLibAttr->wMajorVerNum, pTLibAttr->wMinorVerNum);
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
    AddToTLDataStrW(tld, wszText);
    AddToTLDataStrW(tld, wszComa);
    AddToTLDataStrW(tld, wszNewLine);
    AddSpaces(tld, 4);
    AddToTLDataStrW(tld, wszHelpString);
    AddToTLDataStrW(tld, wszOpenBrackets2);
    AddToTLDataStrW(tld, wszInvertedComa);
    AddToTLDataStrW(tld, bstrData);
    AddToTLDataStrW(tld, wszInvertedComa);
    AddToTLDataStrW(tld, wszCloseBrackets2);
    AddToTLDataStrW(tld, wszNewLine);
    AddToTLDataStrW(tld, wszCloseBrackets1);
    AddToTLDataStrW(tld, wszNewLine);
    AddToTLDataStrW(tld, wszLibrary);
    AddToTLDataStrW(tld, bstrName);
    AddToTLDataStrW(tld, wszNewLine);
    AddToTLDataStrW(tld, wszOpenBrackets3);
    AddToTLDataStrW(tld, wszNewLine);

    AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
    AddToStrW(tld->wszInsertAfter, wszSemicolon);
1066

1067 1068 1069 1070 1071
    wsprintfW(wszText, wszFormat, bstrName, bstrData);
    SysFreeString(bstrName);
    SysFreeString(bstrData);
    tvis.hParent = (HTREEITEM)SendMessage(typelib.hTree,
            TVM_INSERTITEM, 0, (LPARAM)&tvis);
1072

1073 1074
    for(i=0; i<count; i++)
    {
1075
        bInsert = TRUE;
1076
        ITypeLib_GetTypeInfo(pTypeLib, i, &pTypeInfo);
1077

1078
        ITypeInfo_GetDocumentation(pTypeInfo, MEMBERID_NIL, &bstrName, &bstrData,
1079
                &ulHelpContext, NULL);
1080
        ITypeInfo_GetTypeAttr(pTypeInfo, &pTypeAttr);
1081

1082
        memset(wszText, 0, sizeof(wszText));
1083
        memset(wszAfter, 0, sizeof(wszAfter));
1084 1085
        tld = InitializeTLData();
        U(tvis).item.lParam = (LPARAM)tld;
1086 1087
        switch(pTypeAttr->typekind)
        {
1088 1089 1090
            case TKIND_ENUM:
                AddToStrW(wszText, wszTKIND_ENUM);
                AddToStrW(wszText, bstrName);
1091

1092 1093 1094 1095 1096 1097 1098 1099 1100
                CreateTypedefHeader(pTypeInfo, pTypeAttr, tld);
                AddToTLDataStrW(tld, &wszTKIND_ENUM[lstrlenW(wszTKIND_ALIAS)]);
                AddToTLDataStrW(tld, wszOpenBrackets3);
                AddToTLDataStrW(tld,wszNewLine);
                AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
                AddToStrW(tld->wszInsertAfter, wszSpace);
                AddToStrW(tld->wszInsertAfter, bstrName);
                AddToStrW(tld->wszInsertAfter, wszSemicolon);
                AddToStrW(tld->wszInsertAfter, wszNewLine);
1101 1102 1103 1104 1105 1106

                bInsert = FALSE;
                hParent = TreeView_InsertItem(typelib.hTree, &tvis);
                EnumEnums(pTypeInfo, pTypeAttr->cVars, hParent);
                AddChildrenData(hParent, tld);
                AddToTLDataStrW(tld, tld->wszInsertAfter);
1107 1108
                break;
            case TKIND_RECORD:
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
                AddToTLDataStrW(tld, wszTKIND_RECORD);
                AddToTLDataStrW(tld, wszTag);
                AddToTLDataStrW(tld, bstrName);
                AddToTLDataStrW(tld, wszSpace);
                AddToTLDataStrW(tld, wszOpenBrackets3);
                AddToTLDataStrW(tld, wszNewLine);

                AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
                AddToStrW(tld->wszInsertAfter, wszSpace);
                AddToStrW(tld->wszInsertAfter, bstrName);
                AddToStrW(tld->wszInsertAfter, wszSemicolon);
                AddToStrW(tld->wszInsertAfter, wszNewLine);
1121

1122 1123 1124 1125 1126 1127 1128 1129
                AddToStrW(wszText, wszTKIND_RECORD);
                AddToStrW(wszText, bstrName);
                break;
            case TKIND_MODULE:
                AddToStrW(wszText, wszTKIND_MODULE);
                AddToStrW(wszText, bstrName);
                break;
            case TKIND_INTERFACE:
1130
                CreateInterfaceInfo(pTypeInfo, pTypeAttr->cImplTypes, bstrName,
1131 1132
                        bstrData, ulHelpContext, pTypeAttr, tld);
                tld->bPredefine = TRUE;
1133

1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
                AddToStrW(wszText, wszTKIND_INTERFACE);
                AddToStrW(wszText, bstrName);
                break;
            case TKIND_COCLASS:
                AddToStrW(wszText, wszTKIND_COCLASS);
                AddToStrW(wszText, bstrName);
                break;
            case TKIND_UNION:
                AddToStrW(wszText, wszTKIND_UNION);
                AddToStrW(wszText, bstrName);
                break;
1145
            case TKIND_DISPATCH:
1146
                CreateInterfaceInfo(pTypeInfo, pTypeAttr->cImplTypes, bstrName,
1147 1148
                        bstrData, ulHelpContext, pTypeAttr, tld);
                tld->bPredefine = TRUE;
1149 1150
                AddToStrW(wszText, wszTKIND_DISPATCH);
                AddToStrW(wszText, bstrName);
1151 1152 1153

                hParent = TreeView_InsertItem(typelib.hTree, &tvis);
                hMain = tvis.hParent;
1154
                tldDispatch = tld;
1155 1156 1157

                lstrcpyW(wszText, wszProperties);
                tvis.hParent = hParent;
1158 1159 1160 1161 1162
                tld = InitializeTLData();
                U(tvis).item.lParam = (LPARAM) tld;
                AddToTLDataStrW(tld, wszProperties);
                AddToTLDataStrW(tld, wszColon);
                AddToTLDataStrW(tld, wszNewLine);
1163 1164
                tvis.hParent = TreeView_InsertItem(typelib.hTree, &tvis);
                EnumVars(pTypeInfo, pTypeAttr->cVars, tvis.hParent);
1165
                AddChildrenData(tvis.hParent, tld);
1166 1167 1168

                lstrcpyW(wszText, wszMethods);
                tvis.hParent = hParent;
1169 1170 1171 1172 1173
                tld = InitializeTLData();
                U(tvis).item.lParam = (LPARAM) tld;
                AddToTLDataStrW(tld, wszMethods);
                AddToTLDataStrW(tld, wszColon);
                AddToTLDataStrW(tld, wszNewLine);
1174 1175
                tvis.hParent = TreeView_InsertItem(typelib.hTree, &tvis);
                EnumFuncs(pTypeInfo, pTypeAttr->cFuncs, tvis.hParent);
1176
                AddChildrenData(tvis.hParent, tld);
1177 1178 1179 1180 1181 1182 1183 1184

                EnumImplTypes(pTypeInfo, pTypeAttr->cImplTypes, hParent);
                AddChildrenData(hParent, tldDispatch);
                AddToTLDataStrW(tldDispatch, tldDispatch->wszInsertAfter);

                bInsert = FALSE;
                tvis.hParent = hMain;

1185 1186
                if(SUCCEEDED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo, -1, &hRefType)))
                {
1187
                    bInsert = TRUE;
1188

1189
                    ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr);
1190 1191 1192
                    SysFreeString(bstrName);
                    SysFreeString(bstrData);

1193
                    memset(wszText, 0, sizeof(wszText));
1194 1195
                    tld = InitializeTLData();
                    U(tvis).item.lParam = (LPARAM) tld;
1196

1197 1198
                    ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo);
                    ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
1199
                                &bstrData, &ulHelpContext, NULL);
1200
                    ITypeInfo_GetTypeAttr(pRefTypeInfo, &pTypeAttr);
1201 1202

                    CreateInterfaceInfo(pTypeInfo, pTypeAttr->cImplTypes, bstrName,
1203 1204
                            bstrData, ulHelpContext, pTypeAttr, tld);
                    tld->bPredefine = TRUE;
1205

1206 1207 1208 1209 1210
                    AddToStrW(wszText, wszTKIND_INTERFACE);
                    AddToStrW(wszText, bstrName);
                    ITypeInfo_Release(pRefTypeInfo);
                }
                break;
1211 1212
            case TKIND_ALIAS:
                AddToStrW(wszText, wszTKIND_ALIAS);
1213
                CreateTypeInfo(wszText, wszAfter, pTypeAttr->tdescAlias, pTypeInfo);
1214
                AddToStrW(wszText, wszSpace);
1215
                AddToStrW(wszText, bstrName);
1216
                AddToStrW(wszText, wszAfter);
1217

1218 1219 1220 1221
                CreateTypedefHeader(pTypeInfo, pTypeAttr, tld);
                AddToTLDataStrW(tld, &wszText[lstrlenW(wszTKIND_ALIAS)]);
                AddToTLDataStrW(tld, wszSemicolon);
                AddToTLDataStrW(tld, wszNewLine);
1222 1223 1224
                break;
            default:
                lstrcpyW(wszText, bstrName);
1225
                WINE_FIXME("pTypeAttr->typekind == %d not supported\n",
1226
                        pTypeAttr->typekind);
1227
        }
1228

1229 1230 1231 1232 1233 1234 1235
        if(bInsert)
        {
            hParent = TreeView_InsertItem(typelib.hTree, &tvis);

            EnumVars(pTypeInfo, pTypeAttr->cVars, hParent);
            EnumFuncs(pTypeInfo, pTypeAttr->cFuncs, hParent);
            EnumImplTypes(pTypeInfo, pTypeAttr->cImplTypes, hParent);
1236

1237
            if(memcmp(bstrName, wszVT_UNKNOWN, sizeof(wszVT_UNKNOWN)))
1238 1239
                AddChildrenData(hParent, tld);
            AddToTLDataStrW(tld, tld->wszInsertAfter);
1240
        }
1241

1242 1243
        ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr);
        ITypeInfo_Release(pTypeInfo);
1244
        SysFreeString(bstrName);
1245
        SysFreeString(bstrData);
1246 1247 1248
    }
    SendMessage(typelib.hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)tvis.hParent);

1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
    memset(&tvi, 0, sizeof(TVITEM));
    tvi.mask = TVIF_PARAM;
    tvi.hItem = tvis.hParent;

    SendMessage(typelib.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
    AddPredefinitions(tvi.hItem, (TYPELIB_DATA*)(tvi.lParam));
    AddIdlData(tvi.hItem, (TYPELIB_DATA*)(tvi.lParam));
    AddToTLDataStrW((TYPELIB_DATA*)(tvi.lParam),
            ((TYPELIB_DATA*)(tvi.lParam))->wszInsertAfter);

1259
    ITypeLib_Release(pTypeLib);
1260
    return 0;
1261 1262
}

1263 1264 1265 1266 1267 1268 1269 1270 1271
void UpdateData(HTREEITEM item)
{
    TVITEM tvi;

    memset(&tvi, 0, sizeof(TVITEM));
    tvi.mask = TVIF_PARAM;
    tvi.hItem = item;

    SendMessage(typelib.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
1272 1273 1274 1275 1276
    if(!tvi.lParam)
    {
        SetWindowText(typelib.hEdit, wszSpace);
        return;
    }
1277 1278 1279 1280

    SetWindowText(typelib.hEdit, ((TYPELIB_DATA*)tvi.lParam)->idl);
}

1281
static void TypeLibResizeChild(void)
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
{
    RECT client, stat;

    MoveWindow(typelib.hStatusBar, 0, 0, 0, 0, TRUE);

    if(IsWindowVisible(typelib.hStatusBar))
        GetClientRect(typelib.hStatusBar, &stat);
    else stat.bottom = 0;

    GetClientRect(globals.hTypeLibWnd, &client);
    MoveWindow(typelib.hPaneWnd, 0, 0,
            client.right, client.bottom-stat.bottom, TRUE);
}

1296
static void TypeLibMenuCommand(WPARAM wParam, HWND hWnd)
1297 1298 1299 1300 1301
{
    BOOL vis;

    switch(wParam)
    {
1302 1303 1304
        case IDM_SAVEAS:
            GetSaveIdlAsPath();
            break;
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317
        case IDM_STATUSBAR:
            vis = IsWindowVisible(typelib.hStatusBar);
            ShowWindow(typelib.hStatusBar, vis ? SW_HIDE : SW_SHOW);
            CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
                    vis ? MF_UNCHECKED : MF_CHECKED);
            TypeLibResizeChild();
            break;
        case IDM_CLOSE:
            DestroyWindow(hWnd);
            break;
    }
}

1318
static void UpdateTypeLibStatusBar(int itemID)
1319 1320 1321 1322 1323 1324 1325 1326 1327
{
    WCHAR info[MAX_LOAD_STRING];

    if(!LoadString(globals.hMainInst, itemID, info, sizeof(WCHAR[MAX_LOAD_STRING])))
        LoadString(globals.hMainInst, IDS_READY, info, sizeof(WCHAR[MAX_LOAD_STRING]));

    SendMessage(typelib.hStatusBar, SB_SETTEXT, 0, (LPARAM)info);
}

1328
static void EmptyTLTree(void)
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357
{
    HTREEITEM cur, del;
    TVITEM tvi;

    tvi.mask = TVIF_PARAM;
    cur = TreeView_GetChild(typelib.hTree, TVI_ROOT);

    while(TRUE)
    {
        del = cur;
        cur = TreeView_GetChild(typelib.hTree, del);

        if(!cur) cur = TreeView_GetNextSibling(typelib.hTree, del);
        if(!cur) cur = TreeView_GetParent(typelib.hTree, del);

        tvi.hItem = del;
        SendMessage(typelib.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
        if(tvi.lParam)
        {
            HeapFree(GetProcessHeap(), 0, ((TYPELIB_DATA *)tvi.lParam)->idl);
            HeapFree(GetProcessHeap(), 0, (TYPELIB_DATA *)tvi.lParam);
        }

        SendMessage(typelib.hTree, TVM_DELETEITEM, 0, (LPARAM)del);

        if(!cur) break;
    }
}

1358 1359 1360 1361 1362 1363 1364 1365 1366 1367
LRESULT CALLBACK TypeLibProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        case WM_CREATE:
        {
            if(!CreatePanedWindow(hWnd, &typelib.hPaneWnd, globals.hMainInst))
                DestroyWindow(hWnd);
            typelib.hTree = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, NULL,
                    WS_CHILD|WS_VISIBLE|TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT,
1368 1369
                    0, 0, 0, 0, typelib.hPaneWnd, (HMENU)TYPELIB_TREE,
                    globals.hMainInst, NULL);
1370 1371 1372 1373 1374 1375 1376
            typelib.hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, NULL,
                    WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_READONLY|WS_HSCROLL|WS_VSCROLL,
                    0, 0, 0, 0, typelib.hPaneWnd, NULL, globals.hMainInst, NULL);

            SetLeft(typelib.hPaneWnd, typelib.hTree);
            SetRight(typelib.hPaneWnd, typelib.hEdit);

1377 1378
            if(PopulateTree()) DestroyWindow(hWnd);
            else SetFocus(typelib.hTree);
1379 1380
            break;
        }
1381 1382
        case WM_COMMAND:
            TypeLibMenuCommand(LOWORD(wParam), hWnd);
1383 1384 1385 1386 1387 1388
        case WM_MENUSELECT:
            UpdateTypeLibStatusBar(LOWORD(wParam));
            break;
        case WM_SETFOCUS:
            SetFocus(typelib.hTree);
            break;
1389
        case WM_SIZE:
1390 1391
            if(wParam == SIZE_MINIMIZED) break;
            TypeLibResizeChild();
1392 1393
            break;
        case WM_DESTROY:
1394
            EmptyTLTree();
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417
            break;
        default:
            return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
    return 0;
}

BOOL TypeLibRegisterClass(void)
{
    WNDCLASS wcc;

    memset(&wcc, 0, sizeof(WNDCLASS));
    wcc.lpfnWndProc = TypeLibProc;
    wcc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wcc.lpszMenuName = MAKEINTRESOURCE(IDM_TYPELIB);
    wcc.lpszClassName = wszTypeLib;

    if(!RegisterClass(&wcc))
        return FALSE;

    return TRUE;
}

1418
BOOL CreateTypeLibWindow(HINSTANCE hInst, WCHAR *wszFileName)
1419 1420 1421 1422
{
    WCHAR wszTitle[MAX_LOAD_STRING];
    LoadString(hInst, IDS_TYPELIBTITLE, wszTitle, sizeof(WCHAR[MAX_LOAD_STRING]));

1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434
    if(wszFileName) lstrcpyW(typelib.wszFileName, wszFileName);
    else
    {
        TVITEM tvi;

        memset(&tvi, 0, sizeof(TVITEM));
        tvi.hItem = TreeView_GetSelection(globals.hTree);

        SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
        lstrcpyW(typelib.wszFileName, ((ITEM_INFO*)tvi.lParam)->path);
    }

1435 1436 1437 1438
    globals.hTypeLibWnd = CreateWindow(wszTypeLib, wszTitle,
            WS_OVERLAPPEDWINDOW|WS_VISIBLE,
            CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInst, NULL);
    if(!globals.hTypeLibWnd) return FALSE;
1439 1440 1441 1442 1443

    typelib.hStatusBar = CreateStatusWindow(WS_VISIBLE|WS_CHILD,
            (LPWSTR)wszTitle, globals.hTypeLibWnd, 0);

    TypeLibResizeChild();
1444 1445
    return TRUE;
}