oleaut32/tests: Checking null terminator in return value of SysReAllocStringLen.
[wine] / dlls / oleaut32 / tests / typelib.c
1 /*
2  * ITypeLib and ITypeInfo test
3  *
4  * Copyright 2004 Jacek Caban
5  * Copyright 2006 Dmitry Timoshkov
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #define COBJMACROS
23
24 #include <wine/test.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "oleauto.h"
31 #include "ocidl.h"
32 #include "shlwapi.h"
33 #include "tmarshal.h"
34
35 #define expect_eq(expr, value, type, format) { type _ret = (expr); ok((value) == _ret, #expr " expected " format " got " format "\n", value, _ret); }
36 #define expect_int(expr, value) expect_eq(expr, (int)(value), int, "%d")
37 #define expect_hex(expr, value) expect_eq(expr, (int)(value), int, "0x%x")
38 #define expect_null(expr) expect_eq(expr, NULL, const void *, "%p")
39
40 #define expect_wstr_acpval(expr, value) \
41     { \
42         CHAR buf[260]; \
43         expect_eq(!WideCharToMultiByte(CP_ACP, 0, (expr), -1, buf, 260, NULL, NULL), 0, int, "%d"); \
44         ok(lstrcmp(value, buf) == 0, #expr " expected \"%s\" got \"%s\"\n", value, buf); \
45     }
46
47 #define ole_expect(expr, expect) { \
48     HRESULT r = expr; \
49     ok(r == (expect), #expr " returned %x, expected %s (%x)\n", r, #expect, expect); \
50 }
51
52 #define ole_check(expr) ole_expect(expr, S_OK);
53
54 #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%08x\n", hr)
55
56 static const WCHAR wszStdOle2[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
57
58 static void ref_count_test(LPCWSTR type_lib)
59 {
60     ITypeLib *iface;
61     ITypeInfo *iti1, *iti2;
62     HRESULT hRes;
63     int ref_count;
64
65     trace("Loading type library\n");
66     hRes = LoadTypeLib(type_lib, &iface);
67     ok(hRes == S_OK, "Could not load type library\n");
68     if(hRes != S_OK)
69         return;
70
71     hRes = ITypeLib_GetTypeInfo(iface, 1, &iti1);
72     ok(hRes == S_OK, "ITypeLib_GetTypeInfo failed on index = 1\n");
73     ok(ref_count=ITypeLib_Release(iface) > 0, "ITypeLib destroyed while ITypeInfo has back pointer\n");
74     if(!ref_count)
75         return;
76
77     hRes = ITypeLib_GetTypeInfo(iface, 1, &iti2);
78     ok(hRes == S_OK, "ITypeLib_GetTypeInfo failed on index = 1\n");
79     ok(iti1 == iti2, "ITypeLib_GetTypeInfo returned different pointers for same indexes\n");
80
81     ITypeLib_AddRef(iface);
82     ITypeInfo_Release(iti2);
83     ITypeInfo_Release(iti1);
84     ok(ITypeLib_Release(iface) == 0, "ITypeLib should be destroyed here.\n");
85 }
86
87 static void test_TypeComp(void)
88 {
89     ITypeLib *pTypeLib;
90     ITypeComp *pTypeComp;
91     HRESULT hr;
92     ULONG ulHash;
93     DESCKIND desckind;
94     BINDPTR bindptr;
95     ITypeInfo *pTypeInfo;
96     ITypeInfo *pFontTypeInfo;
97     static WCHAR wszStdFunctions[] = {'S','t','d','F','u','n','c','t','i','o','n','s',0};
98     static WCHAR wszSavePicture[] = {'S','a','v','e','P','i','c','t','u','r','e',0};
99     static WCHAR wszOLE_TRISTATE[] = {'O','L','E','_','T','R','I','S','T','A','T','E',0};
100     static WCHAR wszUnchecked[] = {'U','n','c','h','e','c','k','e','d',0};
101     static WCHAR wszIUnknown[] = {'I','U','n','k','n','o','w','n',0};
102     static WCHAR wszFont[] = {'F','o','n','t',0};
103     static WCHAR wszGUID[] = {'G','U','I','D',0};
104     static WCHAR wszStdPicture[] = {'S','t','d','P','i','c','t','u','r','e',0};
105     static WCHAR wszOLE_COLOR[] = {'O','L','E','_','C','O','L','O','R',0};
106     static WCHAR wszClone[] = {'C','l','o','n','e',0};
107     static WCHAR wszclone[] = {'c','l','o','n','e',0};
108
109     hr = LoadTypeLib(wszStdOle2, &pTypeLib);
110     ok_ole_success(hr, LoadTypeLib);
111
112     hr = ITypeLib_GetTypeComp(pTypeLib, &pTypeComp);
113     ok_ole_success(hr, ITypeLib_GetTypeComp);
114
115     /* test getting a TKIND_MODULE */
116     ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdFunctions);
117     hr = ITypeComp_Bind(pTypeComp, wszStdFunctions, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
118     ok_ole_success(hr, ITypeComp_Bind);
119
120     ok(desckind == DESCKIND_TYPECOMP,
121         "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
122         desckind);
123     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
124
125     ITypeComp_Release(bindptr.lptcomp);
126
127     /* test getting a TKIND_MODULE with INVOKE_PROPERTYGET */
128     ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdFunctions);
129     hr = ITypeComp_Bind(pTypeComp, wszStdFunctions, ulHash, INVOKE_PROPERTYGET, &pTypeInfo, &desckind, &bindptr);
130     ok_ole_success(hr, ITypeComp_Bind);
131
132     ok(desckind == DESCKIND_TYPECOMP,
133         "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
134         desckind);
135     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
136     ITypeComp_Release(bindptr.lptcomp);
137
138     /* test getting a function within a TKIND_MODULE */
139     ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszSavePicture);
140     hr = ITypeComp_Bind(pTypeComp, wszSavePicture, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
141     ok_ole_success(hr, ITypeComp_Bind);
142
143     ok(desckind == DESCKIND_FUNCDESC,
144         "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
145         desckind);
146     ok(bindptr.lpfuncdesc != NULL, "bindptr.lpfuncdesc should not have been set to NULL\n");
147     ITypeInfo_ReleaseFuncDesc(pTypeInfo, bindptr.lpfuncdesc);
148     ITypeInfo_Release(pTypeInfo);
149
150     /* test getting a function within a TKIND_MODULE with INVOKE_PROPERTYGET */
151     ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszSavePicture);
152     hr = ITypeComp_Bind(pTypeComp, wszSavePicture, ulHash, INVOKE_PROPERTYGET, &pTypeInfo, &desckind, &bindptr);
153     todo_wine ok(hr == TYPE_E_TYPEMISMATCH,
154         "ITypeComp_Bind should have failed with TYPE_E_TYPEMISMATCH instead of 0x%08x\n",
155         hr);
156
157     ok(desckind == DESCKIND_NONE,
158         "desckind should have been DESCKIND_NONE instead of %d\n",
159         desckind);
160     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
161     ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
162
163     /* test getting a TKIND_ENUM */
164     ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszOLE_TRISTATE);
165     hr = ITypeComp_Bind(pTypeComp, wszOLE_TRISTATE, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
166     ok_ole_success(hr, ITypeComp_Bind);
167
168     ok(desckind == DESCKIND_TYPECOMP,
169         "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
170         desckind);
171     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
172
173     ITypeComp_Release(bindptr.lptcomp);
174
175     /* test getting a value within a TKIND_ENUM */
176     ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszUnchecked);
177     hr = ITypeComp_Bind(pTypeComp, wszUnchecked, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
178     ok_ole_success(hr, ITypeComp_Bind);
179
180     ok(desckind == DESCKIND_VARDESC,
181         "desckind should have been DESCKIND_VARDESC instead of %d\n",
182         desckind);
183     ITypeInfo_ReleaseVarDesc(pTypeInfo, bindptr.lpvardesc);
184     ITypeInfo_Release(pTypeInfo);
185
186     /* test getting a TKIND_INTERFACE */
187     ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszIUnknown);
188     hr = ITypeComp_Bind(pTypeComp, wszIUnknown, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
189     ok_ole_success(hr, ITypeComp_Bind);
190
191     ok(desckind == DESCKIND_NONE,
192         "desckind should have been DESCKIND_NONE instead of %d\n",
193         desckind);
194     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
195     ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
196
197     /* test getting a TKIND_DISPATCH */
198     ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszFont);
199     hr = ITypeComp_Bind(pTypeComp, wszFont, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
200     ok_ole_success(hr, ITypeComp_Bind);
201
202     ok(desckind == DESCKIND_NONE,
203         "desckind should have been DESCKIND_NONE instead of %d\n",
204         desckind);
205     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
206     ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
207
208     /* test getting a TKIND_RECORD/TKIND_ALIAS */
209     ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszGUID);
210     hr = ITypeComp_Bind(pTypeComp, wszGUID, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
211     ok_ole_success(hr, ITypeComp_Bind);
212
213     ok(desckind == DESCKIND_NONE,
214         "desckind should have been DESCKIND_NONE instead of %d\n",
215         desckind);
216     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
217     ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
218
219     /* test getting a TKIND_ALIAS */
220     ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszOLE_COLOR);
221     hr = ITypeComp_Bind(pTypeComp, wszOLE_COLOR, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
222     ok_ole_success(hr, ITypeComp_Bind);
223
224     ok(desckind == DESCKIND_NONE,
225         "desckind should have been DESCKIND_NONE instead of %d\n",
226         desckind);
227     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
228     ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
229
230     /* test getting a TKIND_COCLASS */
231     ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdPicture);
232     hr = ITypeComp_Bind(pTypeComp, wszStdPicture, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
233     ok_ole_success(hr, ITypeComp_Bind);
234
235     ok(desckind == DESCKIND_NONE,
236         "desckind should have been DESCKIND_NONE instead of %d\n",
237         desckind);
238     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
239     ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
240
241     ITypeComp_Release(pTypeComp);
242
243     /* tests for ITypeComp on an interface */
244     hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IFont, &pFontTypeInfo);
245     ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
246
247     hr = ITypeInfo_GetTypeComp(pFontTypeInfo, &pTypeComp);
248     ok_ole_success(hr, ITypeLib_GetTypeComp);
249
250     ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszClone);
251     hr = ITypeComp_Bind(pTypeComp, wszClone, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
252     ok_ole_success(hr, ITypeComp_Bind);
253
254     ok(desckind == DESCKIND_FUNCDESC,
255         "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
256         desckind);
257     ok(bindptr.lpfuncdesc != NULL, "bindptr.lpfuncdesc should not have been set to NULL\n");
258     ITypeInfo_ReleaseFuncDesc(pTypeInfo, bindptr.lpfuncdesc);
259     ITypeInfo_Release(pTypeInfo);
260
261     ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszClone);
262     hr = ITypeComp_Bind(pTypeComp, wszClone, ulHash, INVOKE_PROPERTYGET, &pTypeInfo, &desckind, &bindptr);
263     ok(hr == TYPE_E_TYPEMISMATCH, "ITypeComp_Bind should have failed with TYPE_E_TYPEMISMATCH instead of 0x%08x\n", hr);
264
265     ok(desckind == DESCKIND_NONE,
266         "desckind should have been DESCKIND_NONE instead of %d\n",
267         desckind);
268     ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
269     ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
270
271     /* tests that the compare is case-insensitive */
272     ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszclone);
273     hr = ITypeComp_Bind(pTypeComp, wszclone, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
274     ok_ole_success(hr, ITypeComp_Bind);
275
276     ok(desckind == DESCKIND_FUNCDESC,
277         "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
278         desckind);
279     ok(bindptr.lpfuncdesc != NULL, "bindptr.lpfuncdesc should not have been set to NULL\n");
280     ITypeInfo_ReleaseFuncDesc(pTypeInfo, bindptr.lpfuncdesc);
281     ITypeInfo_Release(pTypeInfo);
282
283     ITypeComp_Release(pTypeComp);
284     ITypeInfo_Release(pFontTypeInfo);
285     ITypeLib_Release(pTypeLib);
286 }
287
288 static void test_CreateDispTypeInfo(void)
289 {
290     ITypeInfo *pTypeInfo, *pTI2;
291     HRESULT hr;
292     INTERFACEDATA ifdata;
293     METHODDATA methdata[4];
294     PARAMDATA parms1[2];
295     PARAMDATA parms3[1];
296     TYPEATTR *pTypeAttr;
297     HREFTYPE href;
298     FUNCDESC *pFuncDesc;
299     MEMBERID memid;
300
301     static WCHAR func1[] = {'f','u','n','c','1',0};
302     static const WCHAR func2[] = {'f','u','n','c','2',0};
303     static const WCHAR func3[] = {'f','u','n','c','3',0};
304     static const WCHAR parm1[] = {'p','a','r','m','1',0};
305     static const WCHAR parm2[] = {'p','a','r','m','2',0};
306     OLECHAR *name = func1;
307
308     ifdata.pmethdata = methdata;
309     ifdata.cMembers = sizeof(methdata) / sizeof(methdata[0]);
310
311     methdata[0].szName = SysAllocString(func1);
312     methdata[0].ppdata = parms1;
313     methdata[0].dispid = 0x123;
314     methdata[0].iMeth = 0;
315     methdata[0].cc = CC_STDCALL;
316     methdata[0].cArgs = 2;
317     methdata[0].wFlags = DISPATCH_METHOD;
318     methdata[0].vtReturn = VT_HRESULT;
319     parms1[0].szName = SysAllocString(parm1);
320     parms1[0].vt = VT_I4;
321     parms1[1].szName = SysAllocString(parm2);
322     parms1[1].vt = VT_BSTR;
323
324     methdata[1].szName = SysAllocString(func2);
325     methdata[1].ppdata = NULL;
326     methdata[1].dispid = 0x124;
327     methdata[1].iMeth = 1;
328     methdata[1].cc = CC_STDCALL;
329     methdata[1].cArgs = 0;
330     methdata[1].wFlags = DISPATCH_PROPERTYGET;
331     methdata[1].vtReturn = VT_I4;
332
333     methdata[2].szName = SysAllocString(func3);
334     methdata[2].ppdata = parms3;
335     methdata[2].dispid = 0x125;
336     methdata[2].iMeth = 3;
337     methdata[2].cc = CC_STDCALL;
338     methdata[2].cArgs = 1;
339     methdata[2].wFlags = DISPATCH_PROPERTYPUT;
340     methdata[2].vtReturn = VT_HRESULT;
341     parms3[0].szName = SysAllocString(parm1);
342     parms3[0].vt = VT_I4;
343
344     methdata[3].szName = SysAllocString(func3);
345     methdata[3].ppdata = NULL;
346     methdata[3].dispid = 0x125;
347     methdata[3].iMeth = 4;
348     methdata[3].cc = CC_STDCALL;
349     methdata[3].cArgs = 0;
350     methdata[3].wFlags = DISPATCH_PROPERTYGET;
351     methdata[3].vtReturn = VT_I4;
352
353     hr = CreateDispTypeInfo(&ifdata, LOCALE_NEUTRAL, &pTypeInfo);
354     ok(hr == S_OK, "hr %08x\n", hr);
355
356     hr = ITypeInfo_GetTypeAttr(pTypeInfo, &pTypeAttr);
357     ok(hr == S_OK, "hr %08x\n", hr);
358
359     ok(pTypeAttr->typekind == TKIND_COCLASS, "typekind %0x\n", pTypeAttr->typekind);
360     ok(pTypeAttr->cImplTypes == 1, "cImplTypes %d\n", pTypeAttr->cImplTypes);
361     ok(pTypeAttr->cFuncs == 0, "cFuncs %d\n", pTypeAttr->cFuncs);
362     ok(pTypeAttr->wTypeFlags == 0, "wTypeFlags %04x\n", pTypeAttr->cFuncs);
363     ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr);
364
365     hr = ITypeInfo_GetRefTypeOfImplType(pTypeInfo, 0, &href);
366     ok(hr == S_OK, "hr %08x\n", hr);
367     ok(href == 0, "href = 0x%x\n", href);
368     hr = ITypeInfo_GetRefTypeInfo(pTypeInfo, href, &pTI2);
369     ok(hr == S_OK, "hr %08x\n", hr);
370     hr = ITypeInfo_GetTypeAttr(pTI2, &pTypeAttr);
371     ok(hr == S_OK, "hr %08x\n", hr);
372     ok(pTypeAttr->typekind == TKIND_INTERFACE, "typekind %0x\n", pTypeAttr->typekind);
373     ok(pTypeAttr->cFuncs == 4, "cFuncs %d\n", pTypeAttr->cFuncs);
374     ok(IsEqualGUID(&pTypeAttr->guid, &GUID_NULL), "guid {%08x-...}\n", pTypeAttr->guid.Data1);
375     ok(pTypeAttr->wTypeFlags == 0, "typeflags %08x\n", pTypeAttr->wTypeFlags);
376
377     ITypeInfo_ReleaseTypeAttr(pTI2, pTypeAttr);
378
379     hr = ITypeInfo_GetFuncDesc(pTI2, 0, &pFuncDesc);
380     ok(hr == S_OK, "hr %08x\n", hr);
381     ok(pFuncDesc->memid == 0x123, "memid %x\n", pFuncDesc->memid);
382     ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind);
383     ok(pFuncDesc->invkind == methdata[0].wFlags, "invkind %d\n", pFuncDesc->invkind);
384     ok(pFuncDesc->callconv == methdata[0].cc, "callconv %d\n", pFuncDesc->callconv);
385     ok(pFuncDesc->cParams == methdata[0].cArgs, "cParams %d\n", pFuncDesc->cParams);
386     ok(pFuncDesc->oVft == 0, "oVft %d\n", pFuncDesc->oVft);
387     ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags);
388     ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_HRESULT, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt);
389     ok(pFuncDesc->lprgelemdescParam[0].tdesc.vt == VT_I4, "parm 0 vt %x\n", pFuncDesc->lprgelemdescParam[0].tdesc.vt);
390     ok(U(pFuncDesc->lprgelemdescParam[0]).paramdesc.wParamFlags == PARAMFLAG_NONE, "parm 0 flags %x\n", U(pFuncDesc->lprgelemdescParam[0]).paramdesc.wParamFlags);
391
392     ok(pFuncDesc->lprgelemdescParam[1].tdesc.vt == VT_BSTR, "parm 1 vt %x\n", pFuncDesc->lprgelemdescParam[1].tdesc.vt);
393     ok(U(pFuncDesc->lprgelemdescParam[1]).paramdesc.wParamFlags == PARAMFLAG_NONE, "parm 1 flags %x\n", U(pFuncDesc->lprgelemdescParam[1]).paramdesc.wParamFlags);
394     ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc);
395
396     hr = ITypeInfo_GetFuncDesc(pTI2, 1, &pFuncDesc);
397     ok(hr == S_OK, "hr %08x\n", hr);
398     ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind);
399     ok(pFuncDesc->invkind == methdata[1].wFlags, "invkind %d\n", pFuncDesc->invkind);
400     ok(pFuncDesc->callconv == methdata[1].cc, "callconv %d\n", pFuncDesc->callconv);
401     ok(pFuncDesc->cParams == methdata[1].cArgs, "cParams %d\n", pFuncDesc->cParams);
402     ok(pFuncDesc->oVft == sizeof(void *), "oVft %d\n", pFuncDesc->oVft);
403     ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags);
404     ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_I4, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt);
405     ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc);
406
407     hr = ITypeInfo_GetFuncDesc(pTI2, 2, &pFuncDesc);
408     ok(hr == S_OK, "hr %08x\n", hr);
409     ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind);
410     ok(pFuncDesc->invkind == methdata[2].wFlags, "invkind %d\n", pFuncDesc->invkind);
411     ok(pFuncDesc->callconv == methdata[2].cc, "callconv %d\n", pFuncDesc->callconv);
412     ok(pFuncDesc->cParams == methdata[2].cArgs, "cParams %d\n", pFuncDesc->cParams);
413     ok(pFuncDesc->oVft == 3 * sizeof(void *), "oVft %d\n", pFuncDesc->oVft);
414     ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags);
415     ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_HRESULT, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt);
416     ok(pFuncDesc->lprgelemdescParam[0].tdesc.vt == VT_I4, "parm 0 vt %x\n", pFuncDesc->lprgelemdescParam[0].tdesc.vt);
417     ok(U(pFuncDesc->lprgelemdescParam[0]).paramdesc.wParamFlags == PARAMFLAG_NONE, "parm 0 flags %x\n", U(pFuncDesc->lprgelemdescParam[0]).paramdesc.wParamFlags);
418     ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc);
419
420     hr = ITypeInfo_GetFuncDesc(pTI2, 3, &pFuncDesc);
421     ok(hr == S_OK, "hr %08x\n", hr);
422     ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind);
423     ok(pFuncDesc->invkind == methdata[3].wFlags, "invkind %d\n", pFuncDesc->invkind);
424     ok(pFuncDesc->callconv == methdata[3].cc, "callconv %d\n", pFuncDesc->callconv);
425     ok(pFuncDesc->cParams == methdata[3].cArgs, "cParams %d\n", pFuncDesc->cParams);
426     ok(pFuncDesc->oVft == 4 * sizeof(void *), "oVft %d\n", pFuncDesc->oVft);
427     ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags);
428     ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_I4, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt);
429     ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc);
430
431     /* test GetIDsOfNames on a coclass to see if it searches its interfaces */
432     hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &name, 1, &memid);
433     ok(hr == S_OK, "hr 0x%08x\n", hr);
434     ok(memid == 0x123, "memid 0x%08x\n", memid);
435
436     ITypeInfo_Release(pTI2);
437     ITypeInfo_Release(pTypeInfo);
438
439     SysFreeString(parms1[0].szName);
440     SysFreeString(parms1[1].szName);
441     SysFreeString(parms3[0].szName);
442     SysFreeString(methdata[0].szName);
443     SysFreeString(methdata[1].szName);
444     SysFreeString(methdata[2].szName);
445     SysFreeString(methdata[3].szName);
446 }
447
448 static void test_TypeInfo(void)
449 {
450     ITypeLib *pTypeLib;
451     ITypeInfo *pTypeInfo;
452     ITypeInfo2 *pTypeInfo2;
453     HRESULT hr;
454     static WCHAR wszBogus[] = { 'b','o','g','u','s',0 };
455     static WCHAR wszGetTypeInfo[] = { 'G','e','t','T','y','p','e','I','n','f','o',0 };
456     static WCHAR wszClone[] = {'C','l','o','n','e',0};
457     OLECHAR* bogus = wszBogus;
458     OLECHAR* pwszGetTypeInfo = wszGetTypeInfo;
459     OLECHAR* pwszClone = wszClone;
460     DISPID dispidMember;
461     DISPPARAMS dispparams;
462     GUID bogusguid = {0x806afb4f,0x13f7,0x42d2,{0x89,0x2c,0x6c,0x97,0xc3,0x6a,0x36,0xc1}};
463     VARIANT var;
464
465     hr = LoadTypeLib(wszStdOle2, &pTypeLib);
466     ok_ole_success(hr, LoadTypeLib);
467
468     hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IFont, &pTypeInfo);
469     ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid); 
470
471     /* test nonexistent method name */
472     hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &bogus, 1, &dispidMember);
473     ok(hr == DISP_E_UNKNOWNNAME,
474        "ITypeInfo_GetIDsOfNames should have returned DISP_E_UNKNOWNNAME instead of 0x%08x\n",
475        hr);
476
477     /* test invalid memberid */
478     dispparams.cNamedArgs = 0;
479     dispparams.cArgs = 0;
480     dispparams.rgdispidNamedArgs = NULL;
481     dispparams.rgvarg = NULL;
482     hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, 0xdeadbeef, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
483     ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
484
485     hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &pwszClone, 1, &dispidMember);
486     ok_ole_success(hr, ITypeInfo_GetIDsOfNames);
487
488     /* test correct memberid, but wrong flags */
489     hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, &dispparams, NULL, NULL, NULL);
490     ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
491
492     /* test NULL dispparams */
493     hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, NULL, NULL, NULL, NULL);
494     ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
495
496     /* test dispparams->cNamedArgs being bigger than dispparams->cArgs */
497     dispparams.cNamedArgs = 1;
498     hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
499     ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
500
501     ITypeInfo_Release(pTypeInfo);
502
503     hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IDispatch, &pTypeInfo);
504     ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid); 
505
506     hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &pwszGetTypeInfo, 1, &dispidMember);
507     ok_ole_success(hr, ITypeInfo_GetIDsOfNames);
508
509     hr = ITypeInfo_QueryInterface(pTypeInfo, &IID_ITypeInfo2, (void**)&pTypeInfo2);
510     ok_ole_success(hr, ITypeInfo_QueryInterface);
511
512     if (SUCCEEDED(hr))
513     {
514         VariantInit(&var);
515
516         V_VT(&var) = VT_I4;
517
518         /* test unknown guid passed to GetCustData */
519         hr = ITypeInfo2_GetCustData(pTypeInfo2, &bogusguid, &var);
520         ok_ole_success(hr, ITypeInfo_GetCustData);
521         ok(V_VT(&var) == VT_EMPTY, "got %i, expected VT_EMPTY\n", V_VT(&var));
522
523         ITypeInfo2_Release(pTypeInfo2);
524
525         VariantClear(&var);
526     }
527
528     /* test invoking a method with a [restricted] keyword */
529     hr = ITypeInfo_Invoke(pTypeInfo, NULL, dispidMember, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
530     todo_wine {
531     ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
532     }
533
534     ITypeInfo_Release(pTypeInfo);
535     ITypeLib_Release(pTypeLib);
536 }
537
538 /* RegDeleteTreeW from dlls/advapi32/registry.c */
539 static LSTATUS myRegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
540 {
541     LONG ret;
542     DWORD dwMaxSubkeyLen, dwMaxValueLen;
543     DWORD dwMaxLen, dwSize;
544     WCHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
545     HKEY hSubKey = hKey;
546
547     if(lpszSubKey)
548     {
549         ret = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
550         if (ret) return ret;
551     }
552
553     ret = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL,
554             &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
555     if (ret) goto cleanup;
556
557     dwMaxSubkeyLen++;
558     dwMaxValueLen++;
559     dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
560     if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR))
561     {
562         /* Name too big: alloc a buffer for it */
563         if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(WCHAR))))
564         {
565             ret = ERROR_NOT_ENOUGH_MEMORY;
566             goto cleanup;
567         }
568     }
569
570     /* Recursively delete all the subkeys */
571     while (TRUE)
572     {
573         dwSize = dwMaxLen;
574         if (RegEnumKeyExW(hSubKey, 0, lpszName, &dwSize, NULL,
575                           NULL, NULL, NULL)) break;
576
577         ret = myRegDeleteTreeW(hSubKey, lpszName);
578         if (ret) goto cleanup;
579     }
580
581     if (lpszSubKey)
582         ret = RegDeleteKeyW(hKey, lpszSubKey);
583     else
584         while (TRUE)
585         {
586             dwSize = dwMaxLen;
587             if (RegEnumValueW(hKey, 0, lpszName, &dwSize,
588                   NULL, NULL, NULL, NULL)) break;
589
590             ret = RegDeleteValueW(hKey, lpszName);
591             if (ret) goto cleanup;
592         }
593
594 cleanup:
595     if (lpszName != szNameBuf)
596         HeapFree(GetProcessHeap(), 0, lpszName);
597     if(lpszSubKey)
598         RegCloseKey(hSubKey);
599     return ret;
600 }
601
602 static BOOL do_typelib_reg_key(GUID *uid, WORD maj, WORD min, LPCWSTR base, BOOL remove)
603 {
604     static const WCHAR typelibW[] = {'T','y','p','e','l','i','b','\\',0};
605     static const WCHAR formatW[] = {'\\','%','u','.','%','u','\\','0','\\','w','i','n','3','2',0};
606     static const WCHAR format2W[] = {'%','s','_','%','u','_','%','u','.','d','l','l',0};
607     WCHAR buf[128];
608     HKEY hkey;
609     BOOL ret = TRUE;
610     DWORD res;
611
612     memcpy(buf, typelibW, sizeof(typelibW));
613     StringFromGUID2(uid, buf + lstrlenW(buf), 40);
614
615     if (remove)
616     {
617         ok(myRegDeleteTreeW(HKEY_CLASSES_ROOT, buf) == ERROR_SUCCESS, "SHDeleteKey failed\n");
618         return TRUE;
619     }
620
621     wsprintfW(buf + lstrlenW(buf), formatW, maj, min );
622
623     SetLastError(0xdeadbeef);
624     res = RegCreateKeyExW(HKEY_CLASSES_ROOT, buf, 0, NULL, 0,
625                           KEY_WRITE, NULL, &hkey, NULL);
626     if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
627     {
628         win_skip("W-calls are not implemented\n");
629         return FALSE;
630     }
631
632     if (res != ERROR_SUCCESS)
633     {
634         trace("RegCreateKeyExW failed\n");
635         return FALSE;
636     }
637
638     wsprintfW(buf, format2W, base, maj, min);
639     if (RegSetValueExW(hkey, NULL, 0, REG_SZ,
640                        (BYTE *)buf, (lstrlenW(buf) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
641     {
642         trace("RegSetValueExW failed\n");
643         ret = FALSE;
644     }
645     RegCloseKey(hkey);
646     return ret;
647 }
648
649 static void test_QueryPathOfRegTypeLib(void)
650 {
651     static const struct test_data
652     {
653         WORD maj, min;
654         HRESULT ret;
655         const WCHAR path[16];
656     } td[] = {
657         { 1, 0, TYPE_E_LIBNOTREGISTERED, { 0 } },
658         { 3, 0, S_OK, {'f','a','k','e','_','3','_','0','.','d','l','l',0 } },
659         { 3, 1, S_OK, {'f','a','k','e','_','3','_','1','.','d','l','l',0 } },
660         { 3, 22, S_OK, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
661         { 3, 37, S_OK, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
662         { 3, 40, S_OK, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
663         { 0xffff, 0xffff, S_OK, {'f','a','k','e','_','5','_','3','7','.','d','l','l',0 } },
664         { 0xffff, 0, TYPE_E_LIBNOTREGISTERED, { 0 } },
665         { 3, 0xffff, TYPE_E_LIBNOTREGISTERED, { 0 } },
666         { 5, 0xffff, TYPE_E_LIBNOTREGISTERED, { 0 } },
667         { 4, 0, TYPE_E_LIBNOTREGISTERED, { 0 } }
668     };
669     static const WCHAR base[] = {'f','a','k','e',0};
670     UINT i;
671     RPC_STATUS status;
672     GUID uid;
673     WCHAR uid_str[40];
674     HRESULT ret;
675     BSTR path;
676
677     status = UuidCreate(&uid);
678     ok(!status || status == RPC_S_UUID_LOCAL_ONLY, "UuidCreate error %08x\n", status);
679
680     StringFromGUID2(&uid, uid_str, 40);
681     /*trace("GUID: %s\n", wine_dbgstr_w(uid_str));*/
682
683     if (!do_typelib_reg_key(&uid, 3, 0, base, 0)) return;
684     if (!do_typelib_reg_key(&uid, 3, 1, base, 0)) return;
685     if (!do_typelib_reg_key(&uid, 3, 37, base, 0)) return;
686     if (!do_typelib_reg_key(&uid, 5, 37, base, 0)) return;
687
688     for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
689     {
690         ret = QueryPathOfRegTypeLib(&uid, td[i].maj, td[i].min, 0, &path);
691         ok(ret == td[i].ret, "QueryPathOfRegTypeLib(%u.%u) returned %08x\n", td[i].maj, td[i].min, ret);
692         if (ret == S_OK)
693         {
694             ok(!lstrcmpW(td[i].path, path), "typelib %u.%u path doesn't match\n", td[i].maj, td[i].min);
695             SysFreeString(path);
696         }
697     }
698
699     do_typelib_reg_key(&uid, 0, 0, NULL, 1);
700 }
701
702 static void test_inheritance(void)
703 {
704     HRESULT hr;
705     ITypeLib *pTL;
706     ITypeInfo *pTI, *pTI_p;
707     TYPEATTR *pTA;
708     HREFTYPE href;
709     FUNCDESC *pFD;
710     WCHAR path[MAX_PATH];
711     CHAR pathA[MAX_PATH];
712     static const WCHAR tl_path[] = {'.','\\','m','i','d','l','_','t','m','a','r','s','h','a','l','.','t','l','b',0};
713
714     BOOL use_midl_tlb = 0;
715
716     GetModuleFileNameA(NULL, pathA, MAX_PATH);
717     MultiByteToWideChar(CP_ACP, 0, pathA, -1, path, MAX_PATH);
718
719     if(use_midl_tlb)
720         memcpy(path, tl_path, sizeof(tl_path));
721
722     hr = LoadTypeLib(path, &pTL);
723     if(FAILED(hr)) return;
724
725
726     /* ItestIF3 is a syntax 2 dispinterface */
727     hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF3, &pTI);
728     ok(hr == S_OK, "hr %08x\n", hr);
729
730     hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
731     ok(hr == S_OK, "hr %08x\n", hr);
732     ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
733     ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
734     ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
735 if(use_midl_tlb) {
736     ok(pTA->cFuncs == 6, "cfuncs %d\n", pTA->cFuncs);
737     ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
738     ITypeInfo_ReleaseTypeAttr(pTI, pTA);
739
740     hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
741     ok(hr == S_OK, "hr %08x\n", hr);
742     hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
743     ok(hr == S_OK, "hr %08x\n", hr);
744     hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
745     ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
746     ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
747     ITypeInfo_Release(pTI_p);
748
749     /* Should have six methods */
750     hr = ITypeInfo_GetFuncDesc(pTI, 6, &pFD);
751     ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
752     hr = ITypeInfo_GetFuncDesc(pTI, 5, &pFD);
753     ok(hr == S_OK, "hr %08x\n", hr);
754     ok(pFD->memid == 0x60020000, "memid %08x\n", pFD->memid);
755     ok(pFD->oVft == 5 * sizeof(void *), "oVft %d\n", pFD->oVft);
756     ITypeInfo_ReleaseFuncDesc(pTI, pFD);
757 }
758     ITypeInfo_Release(pTI);
759
760
761     /* ItestIF4 is a syntax 1 dispinterface */
762     hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF4, &pTI);
763     ok(hr == S_OK, "hr %08x\n", hr);
764
765     hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
766     ok(hr == S_OK, "hr %08x\n", hr);
767     ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
768     ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
769     ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
770     ok(pTA->cFuncs == 1, "cfuncs %d\n", pTA->cFuncs);
771     ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
772     ITypeInfo_ReleaseTypeAttr(pTI, pTA);
773
774     hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
775     ok(hr == S_OK, "hr %08x\n", hr);
776     hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
777     ok(hr == S_OK, "hr %08x\n", hr);
778     hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
779     ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
780     ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
781     ITypeInfo_Release(pTI_p);
782     hr = ITypeInfo_GetFuncDesc(pTI, 1, &pFD);
783     ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
784     hr = ITypeInfo_GetFuncDesc(pTI, 0, &pFD);
785     ok(hr == S_OK, "hr %08x\n", hr);
786     ok(pFD->memid == 0x1c, "memid %08x\n", pFD->memid);
787     ITypeInfo_ReleaseFuncDesc(pTI, pFD);
788     ITypeInfo_Release(pTI);
789
790
791     /* ItestIF5 is dual with inherited ifaces which derive from IUnknown but not IDispatch */
792     hr = ITypeLib_GetTypeInfoOfGuid(pTL, &IID_ItestIF5, &pTI);
793     ok(hr == S_OK, "hr %08x\n", hr);
794
795     hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
796     ok(hr == S_OK, "hr %08x\n", hr);
797     if (hr == S_OK)
798     {
799         ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
800         ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
801         if(use_midl_tlb) {
802             ok(pTA->wTypeFlags == TYPEFLAG_FDUAL, "typeflags %x\n", pTA->wTypeFlags);
803         }
804         ok(pTA->cFuncs == 8, "cfuncs %d\n", pTA->cFuncs);
805         ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
806         ITypeInfo_ReleaseTypeAttr(pTI, pTA);
807     }
808     hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
809     ok(hr == S_OK, "hr %08x\n", hr);
810     hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
811     ok(hr == S_OK, "hr %08x\n", hr);
812     hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
813     ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
814     ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
815     ITypeInfo_Release(pTI_p);
816 if(use_midl_tlb) {
817     hr = ITypeInfo_GetFuncDesc(pTI, 6, &pFD);
818     ok(hr == S_OK, "hr %08x\n", hr);
819     ok(pFD->memid == 0x1234, "memid %08x\n", pFD->memid);
820     ITypeInfo_ReleaseFuncDesc(pTI, pFD);
821 }
822     ITypeInfo_Release(pTI);
823
824     /* ItestIF7 is dual with inherited ifaces which derive from Dispatch */
825     hr = ITypeLib_GetTypeInfoOfGuid(pTL, &IID_ItestIF7, &pTI);
826     ok(hr == S_OK, "hr %08x\n", hr);
827
828     hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
829     ok(hr == S_OK, "hr %08x\n", hr);
830     ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
831     ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
832     ok(pTA->wTypeFlags == (TYPEFLAG_FDISPATCHABLE|TYPEFLAG_FDUAL), "typeflags %x\n", pTA->wTypeFlags);
833     ok(pTA->cFuncs == 10, "cfuncs %d\n", pTA->cFuncs);
834     ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
835     ITypeInfo_ReleaseTypeAttr(pTI, pTA);
836
837     hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
838     ok(hr == S_OK, "hr %08x\n", hr);
839     hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
840     ok(hr == S_OK, "hr %08x\n", hr);
841     hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
842     ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
843     ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
844     ITypeInfo_Release(pTI_p);
845
846     hr = ITypeInfo_GetFuncDesc(pTI, 9, &pFD);
847     ok(hr == S_OK, "hr %08x\n", hr);
848     ok(pFD->memid == 0x1236, "memid %08x\n", pFD->memid);
849     ITypeInfo_ReleaseFuncDesc(pTI, pFD);
850     ITypeInfo_Release(pTI);
851
852     /* ItestIF10 is a syntax 2 dispinterface which doesn't derive from IUnknown */
853     hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF10, &pTI);
854     ok(hr == S_OK, "hr %08x\n", hr);
855
856     hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
857     ok(hr == S_OK, "hr %08x\n", hr);
858     ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
859     ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
860     ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
861 if(use_midl_tlb) {
862     ok(pTA->cFuncs == 3, "cfuncs %d\n", pTA->cFuncs);
863     ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
864     ITypeInfo_ReleaseTypeAttr(pTI, pTA);
865
866     hr = ITypeInfo_GetRefTypeOfImplType(pTI, -1, &href);
867     ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
868     hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
869     ok(hr == S_OK, "hr %08x\n", hr);
870     hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
871     ok(hr == S_OK, "hr %08x\n", hr);
872     hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
873     ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
874     ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
875     ITypeInfo_Release(pTI_p);
876
877     /* Should have three methods */
878     hr = ITypeInfo_GetFuncDesc(pTI, 3, &pFD);
879     ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
880     hr = ITypeInfo_GetFuncDesc(pTI, 2, &pFD);
881     ok(hr == S_OK, "hr %08x\n", hr);
882     ok(pFD->memid == 0x60010000, "memid %08x\n", pFD->memid);
883     ok(pFD->oVft == 2 * sizeof(void *), "oVft %d\n", pFD->oVft);
884     ITypeInfo_ReleaseFuncDesc(pTI, pFD);
885 }
886     ITypeInfo_Release(pTI);
887
888     /* ItestIF11 is a syntax 2 dispinterface which derives from IDispatch */
889     hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF11, &pTI);
890     ok(hr == S_OK, "hr %08x\n", hr);
891
892     hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
893     ok(hr == S_OK, "hr %08x\n", hr);
894     ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
895     ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
896     ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
897 if(use_midl_tlb) {
898     ok(pTA->cFuncs == 10, "cfuncs %d\n", pTA->cFuncs);
899     ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
900     ITypeInfo_ReleaseTypeAttr(pTI, pTA);
901
902     hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
903     ok(hr == S_OK, "hr %08x\n", hr);
904     hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
905     ok(hr == S_OK, "hr %08x\n", hr);
906     hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
907     ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
908     ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
909     ITypeInfo_Release(pTI_p);
910
911     /* Should have ten methods */
912     hr = ITypeInfo_GetFuncDesc(pTI, 10, &pFD);
913     ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
914     hr = ITypeInfo_GetFuncDesc(pTI, 9, &pFD);
915     ok(hr == S_OK, "hr %08x\n", hr);
916     ok(pFD->memid == 0x1236, "memid %08x\n", pFD->memid);
917     ok(pFD->oVft == 9 * sizeof(void *), "oVft %d\n", pFD->oVft);
918
919     /* first argument to 10th function is an HREFTYPE from the impl type */
920     ok(pFD->cParams == 1, "cParams %i\n", pFD->cParams);
921     ok(pFD->lprgelemdescParam[0].tdesc.vt == VT_USERDEFINED,
922         "vt 0x%x\n", pFD->lprgelemdescParam[0].tdesc.vt);
923     href = U(pFD->lprgelemdescParam[0].tdesc).hreftype;
924     ok((href & 0xff000000) == 0x04000000, "href 0x%08x\n", href);
925     hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
926     ok(SUCCEEDED(hr), "hr %08x\n", hr);
927     if (SUCCEEDED(hr)) ITypeInfo_Release(pTI_p);
928     ITypeInfo_ReleaseFuncDesc(pTI, pFD);
929 }
930     ITypeInfo_Release(pTI);
931
932
933     /* ItestIF2 is an interface which derives from IUnknown */
934     hr = ITypeLib_GetTypeInfoOfGuid(pTL, &IID_ItestIF2, &pTI);
935     ok(hr == S_OK, "hr %08x\n", hr);
936
937     hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
938     ok(hr == S_OK, "hr %08x\n", hr);
939     ok(pTA->typekind == TKIND_INTERFACE, "kind %04x\n", pTA->typekind);
940     ok(pTA->cbSizeVft == 6 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
941     ok(pTA->wTypeFlags == 0, "typeflags %x\n", pTA->wTypeFlags);
942 if(use_midl_tlb) {
943     ok(pTA->cFuncs == 1, "cfuncs %d\n", pTA->cFuncs);
944     ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
945     ITypeInfo_ReleaseTypeAttr(pTI, pTA);
946
947     /* Should have one method */
948     hr = ITypeInfo_GetFuncDesc(pTI, 1, &pFD);
949     ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
950     hr = ITypeInfo_GetFuncDesc(pTI, 0, &pFD);
951     ok(hr == S_OK, "hr %08x\n", hr);
952     ok(pFD->memid == 0x60020000, "memid %08x\n", pFD->memid);
953     ok(pFD->oVft == 5 * sizeof(void *), "oVft %d\n", pFD->oVft);
954     ITypeInfo_ReleaseFuncDesc(pTI, pFD);
955 }
956     ITypeInfo_Release(pTI);
957
958     ITypeLib_Release(pTL);
959
960     return;
961 }
962
963 #if 0       /* use this to generate more tests */
964
965 #define OLE_CHECK(x) { HRESULT hr = x; if (FAILED(hr)) { printf(#x "failed - %x\n", hr); return; } }
966
967 static char *dump_string(LPWSTR wstr)
968 {
969     int size = lstrlenW(wstr)+3;
970     char *out = CoTaskMemAlloc(size);
971     WideCharToMultiByte(20127, 0, wstr, -1, out+1, size, NULL, NULL);
972     out[0] = '\"';
973     strcat(out, "\"");
974     return out;
975 }
976
977 struct map_entry
978 {
979     DWORD value;
980     const char *name;
981 };
982
983 #define MAP_ENTRY(x) { x, #x }
984 static const struct map_entry tkind_map[] = {
985     MAP_ENTRY(TKIND_ENUM),
986     MAP_ENTRY(TKIND_RECORD),
987     MAP_ENTRY(TKIND_MODULE),
988     MAP_ENTRY(TKIND_INTERFACE),
989     MAP_ENTRY(TKIND_DISPATCH),
990     MAP_ENTRY(TKIND_COCLASS),
991     MAP_ENTRY(TKIND_ALIAS),
992     MAP_ENTRY(TKIND_UNION),
993     MAP_ENTRY(TKIND_MAX),
994     {0, NULL}
995 };
996
997 static const struct map_entry funckind_map[] = {
998     MAP_ENTRY(FUNC_VIRTUAL),
999     MAP_ENTRY(FUNC_PUREVIRTUAL),
1000     MAP_ENTRY(FUNC_NONVIRTUAL),
1001     MAP_ENTRY(FUNC_STATIC),
1002     MAP_ENTRY(FUNC_DISPATCH),
1003     {0, NULL}
1004 };
1005
1006 static const struct map_entry invkind_map[] = {
1007     MAP_ENTRY(INVOKE_FUNC),
1008     MAP_ENTRY(INVOKE_PROPERTYGET),
1009     MAP_ENTRY(INVOKE_PROPERTYPUT),
1010     MAP_ENTRY(INVOKE_PROPERTYPUTREF),
1011     {0, NULL}
1012 };
1013
1014 #undef MAP_ENTRY
1015
1016 static const char *map_value(DWORD val, const struct map_entry *map)
1017 {
1018     static int map_id;
1019     static char bufs[16][256];
1020     char *buf;
1021
1022     while (map->name)
1023     {
1024         if (map->value == val)
1025             return map->name;
1026         map++;
1027     }
1028
1029     buf = bufs[(map_id++)%16];
1030     sprintf(buf, "0x%x", val);
1031     return buf;
1032 }
1033
1034 static void test_dump_typelib(const char *name)
1035 {
1036     WCHAR wszString[260];
1037     ITypeInfo *info;
1038     ITypeLib *lib;
1039     int count;
1040     int i;
1041
1042     MultiByteToWideChar(CP_ACP, 0, name, -1, wszString, 260);
1043     OLE_CHECK(LoadTypeLib(wszString, &lib));
1044     count = ITypeLib_GetTypeInfoCount(lib);
1045     printf("/* interfaces count: %d */\n", count);
1046     for (i = 0; i < count; i++)
1047     {
1048         TYPEATTR *attr;
1049         BSTR name;
1050         int f = 0;
1051
1052         OLE_CHECK(ITypeLib_GetDocumentation(lib, i, &name, NULL, NULL, NULL));
1053         printf("{\n"
1054                "  %s,\n", dump_string(name));
1055         SysFreeString(name);
1056
1057         OLE_CHECK(ITypeLib_GetTypeInfo(lib, i, &info));
1058         ITypeInfo_GetTypeAttr(info, &attr);
1059         printf("  /*kind*/ %s, /*flags*/ 0x%x, /*align*/ %d, /*size*/ %d,\n"
1060                "  /*#vtbl*/ %d, /*#func*/ %d,\n"
1061                "  {\n",
1062             map_value(attr->typekind, tkind_map), attr->wTypeFlags, attr->cbAlignment, attr->cbSizeInstance, attr->cbSizeVft,
1063             attr->cFuncs);
1064         ITypeInfo_ReleaseTypeAttr(info, attr);
1065         while (1)
1066         {
1067             FUNCDESC *desc;
1068             BSTR tab[256];
1069             UINT cNames;
1070             int p;
1071
1072             if (FAILED(ITypeInfo_GetFuncDesc(info, f, &desc)))
1073                 break;
1074             printf("    {\n"
1075                    "      0x%x, /*func*/ %s, /*inv*/ %s, /*call*/ 0x%x,\n",
1076                 desc->memid, map_value(desc->funckind, funckind_map), map_value(desc->invkind, invkind_map),
1077                 desc->callconv);
1078             printf("      /*#param*/ %d, /*#opt*/ %d, /*vtbl*/ %d, /*#scodes*/ %d, /*flags*/ 0x%x,\n",
1079                 desc->cParams, desc->cParamsOpt, desc->oVft, desc->cScodes, desc->wFuncFlags);
1080             printf("      {%d, %x}, /* ret */\n", desc->elemdescFunc.tdesc.vt, desc->elemdescFunc.paramdesc.wParamFlags);
1081             printf("      { /* params */\n");
1082             for (p = 0; p < desc->cParams; p++)
1083             {
1084                 ELEMDESC e = desc->lprgelemdescParam[p];
1085                 printf("        {%d, %x},\n", e.tdesc.vt, e.paramdesc.wParamFlags);
1086             }
1087             printf("        {-1, -1}\n");
1088             printf("      },\n");
1089             printf("      { /* names */\n");
1090             OLE_CHECK(ITypeInfo_GetNames(info, desc->memid, tab, 256, &cNames));
1091             for (p = 0; p < cNames; p++)
1092             {
1093                 printf("        %s,\n", dump_string(tab[p]));
1094                 SysFreeString(tab[p]);
1095             }
1096             printf("        NULL,\n");
1097             printf("      },\n");
1098             printf("    },\n");
1099             ITypeInfo_ReleaseFuncDesc(info, desc);
1100             f++;
1101         }
1102         printf("  }\n");
1103         printf("},\n");
1104         ITypeInfo_Release(info);
1105     }
1106     ITypeLib_Release(lib);
1107 }
1108
1109 #else
1110
1111 typedef struct _element_info
1112 {
1113     VARTYPE vt;
1114     USHORT wParamFlags;
1115 } element_info;
1116
1117 typedef struct _function_info
1118 {
1119     MEMBERID memid;
1120     FUNCKIND funckind;
1121     INVOKEKIND invkind;
1122     CALLCONV callconv;
1123     short cParams;
1124     short cParamsOpt;
1125     short vtbl_index;
1126     short cScodes;
1127     WORD wFuncFlags;
1128     element_info ret_type;
1129     element_info params[15];
1130     LPCSTR names[15];
1131 } function_info;
1132
1133 typedef struct _interface_info
1134 {
1135     LPCSTR name;
1136     TYPEKIND type;
1137     WORD wTypeFlags;
1138     USHORT cbAlignment;
1139     USHORT cbSizeInstance;
1140     USHORT cbSizeVft;
1141     USHORT cFuncs;
1142     function_info funcs[20];
1143 } interface_info;
1144
1145 static const interface_info info[] = {
1146 /* interfaces count: 2 */
1147 {
1148   "IDualIface",
1149   /*kind*/ TKIND_DISPATCH, /*flags*/ 0x1040, /*align*/ 4, /*size*/ 4,
1150   /*#vtbl*/ 7, /*#func*/ 8,
1151   {
1152     {
1153       0x60000000, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1154       /*#param*/ 2, /*#opt*/ 0, /*vtbl*/ 0, /*#scodes*/ 0, /*flags*/ 0x1,
1155       {24, 0}, /* ret */
1156       { /* params */
1157         {26, 1},
1158         {26, 2},
1159         {-1, -1}
1160       },
1161       { /* names */
1162         "QueryInterface",
1163         "riid",
1164         "ppvObj",
1165         NULL,
1166       },
1167     },
1168     {
1169       0x60000001, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1170       /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 1, /*#scodes*/ 0, /*flags*/ 0x1,
1171       {19, 0}, /* ret */
1172       { /* params */
1173         {-1, -1}
1174       },
1175       { /* names */
1176         "AddRef",
1177         NULL,
1178       },
1179     },
1180     {
1181       0x60000002, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1182       /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 2, /*#scodes*/ 0, /*flags*/ 0x1,
1183       {19, 0}, /* ret */
1184       { /* params */
1185         {-1, -1}
1186       },
1187       { /* names */
1188         "Release",
1189         NULL,
1190       },
1191     },
1192     {
1193       0x60010000, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1194       /*#param*/ 1, /*#opt*/ 0, /*vtbl*/ 3, /*#scodes*/ 0, /*flags*/ 0x1,
1195       {24, 0}, /* ret */
1196       { /* params */
1197         {26, 2},
1198         {-1, -1}
1199       },
1200       { /* names */
1201         "GetTypeInfoCount",
1202         "pctinfo",
1203         NULL,
1204       },
1205     },
1206     {
1207       0x60010001, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1208       /*#param*/ 3, /*#opt*/ 0, /*vtbl*/ 4, /*#scodes*/ 0, /*flags*/ 0x1,
1209       {24, 0}, /* ret */
1210       { /* params */
1211         {23, 1},
1212         {19, 1},
1213         {26, 2},
1214         {-1, -1}
1215       },
1216       { /* names */
1217         "GetTypeInfo",
1218         "itinfo",
1219         "lcid",
1220         "pptinfo",
1221         NULL,
1222       },
1223     },
1224     {
1225       0x60010002, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1226       /*#param*/ 5, /*#opt*/ 0, /*vtbl*/ 5, /*#scodes*/ 0, /*flags*/ 0x1,
1227       {24, 0}, /* ret */
1228       { /* params */
1229         {26, 1},
1230         {26, 1},
1231         {23, 1},
1232         {19, 1},
1233         {26, 2},
1234         {-1, -1}
1235       },
1236       { /* names */
1237         "GetIDsOfNames",
1238         "riid",
1239         "rgszNames",
1240         "cNames",
1241         "lcid",
1242         "rgdispid",
1243         NULL,
1244       },
1245     },
1246     {
1247       0x60010003, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1248       /*#param*/ 8, /*#opt*/ 0, /*vtbl*/ 6, /*#scodes*/ 0, /*flags*/ 0x1,
1249       {24, 0}, /* ret */
1250       { /* params */
1251         {3, 1},
1252         {26, 1},
1253         {19, 1},
1254         {18, 1},
1255         {26, 1},
1256         {26, 2},
1257         {26, 2},
1258         {26, 2},
1259         {-1, -1}
1260       },
1261       { /* names */
1262         "Invoke",
1263         "dispidMember",
1264         "riid",
1265         "lcid",
1266         "wFlags",
1267         "pdispparams",
1268         "pvarResult",
1269         "pexcepinfo",
1270         "puArgErr",
1271         NULL,
1272       },
1273     },
1274     {
1275       0x60020000, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1276       /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 7, /*#scodes*/ 0, /*flags*/ 0x0,
1277       {24, 0}, /* ret */
1278       { /* params */
1279         {-1, -1}
1280       },
1281       { /* names */
1282         "Test",
1283         NULL,
1284       },
1285     },
1286   }
1287 },
1288 {
1289   "ISimpleIface",
1290   /*kind*/ TKIND_INTERFACE, /*flags*/ 0x1000, /*align*/ 4, /*size*/ 4,
1291   /*#vtbl*/ 8, /*#func*/ 1,
1292   {
1293     {
1294       0x60020000, /*func*/ FUNC_PUREVIRTUAL, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1295       /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 7, /*#scodes*/ 0, /*flags*/ 0x0,
1296       {25, 0}, /* ret */
1297       { /* params */
1298         {-1, -1}
1299       },
1300       { /* names */
1301         "Test",
1302         NULL,
1303       },
1304     },
1305   }
1306 },
1307 };
1308
1309 #define check_type(elem, info) { \
1310       expect_int((elem)->tdesc.vt, (info)->vt);                     \
1311       expect_hex(U(*(elem)).paramdesc.wParamFlags, (info)->wParamFlags); \
1312   }
1313
1314 static void test_dump_typelib(const char *name)
1315 {
1316     WCHAR wszName[MAX_PATH];
1317     ITypeLib *typelib;
1318     int ifcount = sizeof(info)/sizeof(info[0]);
1319     int iface, func;
1320
1321     MultiByteToWideChar(CP_ACP, 0, name, -1, wszName, MAX_PATH);
1322     ole_check(LoadTypeLibEx(wszName, REGKIND_NONE, &typelib));
1323     expect_eq(ITypeLib_GetTypeInfoCount(typelib), ifcount, UINT, "%d");
1324     for (iface = 0; iface < ifcount; iface++)
1325     {
1326         const interface_info *if_info = &info[iface];
1327         ITypeInfo *typeinfo;
1328         TYPEATTR *typeattr;
1329         BSTR bstrIfName;
1330
1331         trace("Interface %s\n", if_info->name);
1332         ole_check(ITypeLib_GetTypeInfo(typelib, iface, &typeinfo));
1333         ole_check(ITypeLib_GetDocumentation(typelib, iface, &bstrIfName, NULL, NULL, NULL));
1334         expect_wstr_acpval(bstrIfName, if_info->name);
1335         SysFreeString(bstrIfName);
1336
1337         ole_check(ITypeInfo_GetTypeAttr(typeinfo, &typeattr));
1338         expect_int(typeattr->typekind, if_info->type);
1339         expect_hex(typeattr->wTypeFlags, if_info->wTypeFlags);
1340         expect_int(typeattr->cbAlignment, if_info->cbAlignment);
1341         expect_int(typeattr->cbSizeInstance, if_info->cbSizeInstance);
1342         expect_int(typeattr->cbSizeVft, if_info->cbSizeVft * sizeof(void*));
1343         expect_int(typeattr->cFuncs, if_info->cFuncs);
1344
1345         for (func = 0; func < typeattr->cFuncs; func++)
1346         {
1347             function_info *fn_info = (function_info *)&if_info->funcs[func];
1348             FUNCDESC *desc;
1349             BSTR namesTab[256];
1350             UINT cNames;
1351             int i;
1352
1353             trace("Function %s\n", fn_info->names[0]);
1354             ole_check(ITypeInfo_GetFuncDesc(typeinfo, func, &desc));
1355             expect_int(desc->memid, fn_info->memid);
1356             expect_int(desc->funckind, fn_info->funckind);
1357             expect_int(desc->invkind, fn_info->invkind);
1358             expect_int(desc->callconv, fn_info->callconv);
1359             expect_int(desc->cParams, fn_info->cParams);
1360             expect_int(desc->cParamsOpt, fn_info->cParamsOpt);
1361             ok( desc->oVft == fn_info->vtbl_index * sizeof(void*) ||
1362                 broken(desc->oVft == fn_info->vtbl_index * 4), /* xp64 */
1363                 "desc->oVft got %u\n", desc->oVft );
1364             expect_int(desc->cScodes, fn_info->cScodes);
1365             expect_int(desc->wFuncFlags, fn_info->wFuncFlags);
1366             ole_check(ITypeInfo_GetNames(typeinfo, desc->memid, namesTab, 256, &cNames));
1367             for (i = 0; i < cNames; i++)
1368             {
1369                 expect_wstr_acpval(namesTab[i], fn_info->names[i]);
1370                 SysFreeString(namesTab[i]);
1371             }
1372             expect_null(fn_info->names[cNames]);
1373
1374             check_type(&desc->elemdescFunc, &fn_info->ret_type);
1375             for (i = 0 ; i < desc->cParams; i++)
1376             {
1377                 check_type(&desc->lprgelemdescParam[i], &fn_info->params[i]);
1378             }
1379             expect_int(fn_info->params[desc->cParams].vt, (VARTYPE)-1);
1380
1381             ITypeInfo_ReleaseFuncDesc(typeinfo, desc);
1382         }
1383
1384         ITypeInfo_ReleaseTypeAttr(typeinfo, typeattr);
1385         ITypeInfo_Release(typeinfo);
1386     }
1387     ITypeLib_Release(typelib);
1388 }
1389
1390 #endif
1391
1392 static const char *create_test_typelib(void)
1393 {
1394     static char filename[MAX_PATH];
1395     HANDLE file;
1396     HRSRC res;
1397     void *ptr;
1398     DWORD written;
1399
1400     GetTempFileNameA( ".", "tlb", 0, filename );
1401     file = CreateFile( filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
1402     ok( file != INVALID_HANDLE_VALUE, "file creation failed\n" );
1403     if (file == INVALID_HANDLE_VALUE) return NULL;
1404     res = FindResource( GetModuleHandle(0), MAKEINTRESOURCE(2), "TYPELIB" );
1405     ok( res != 0, "couldn't find resource\n" );
1406     ptr = LockResource( LoadResource( GetModuleHandle(0), res ));
1407     WriteFile( file, ptr, SizeofResource( GetModuleHandle(0), res ), &written, NULL );
1408     ok( written == SizeofResource( GetModuleHandle(0), res ), "couldn't write resource\n" );
1409     CloseHandle( file );
1410     return filename;
1411 }
1412
1413 static void test_create_typelib_lcid(LCID lcid)
1414 {
1415     char filename[MAX_PATH];
1416     WCHAR name[MAX_PATH];
1417     HRESULT hr;
1418     ICreateTypeLib2 *tl;
1419     HANDLE file;
1420     DWORD msft_header[5]; /* five is enough for now */
1421     DWORD read;
1422
1423     GetTempFileNameA( ".", "tlb", 0, filename );
1424     MultiByteToWideChar(CP_ACP, 0, filename, -1, name, MAX_PATH);
1425
1426     hr = CreateTypeLib2(SYS_WIN32, name, &tl);
1427     ok(hr == S_OK, "got %08x\n", hr);
1428
1429     hr = ICreateTypeLib2_SetLcid(tl, lcid);
1430     ok(hr == S_OK, "got %08x\n", hr);
1431
1432     hr = ICreateTypeLib2_SaveAllChanges(tl);
1433     ICreateTypeLib2_Release(tl);
1434
1435     file = CreateFileA( filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0 );
1436     ok( file != INVALID_HANDLE_VALUE, "file creation failed\n" );
1437
1438     ReadFile( file, msft_header, sizeof(msft_header), &read, NULL );
1439     ok(read == sizeof(msft_header), "read %d\n", read);
1440     CloseHandle( file );
1441
1442     ok(msft_header[0] == 0x5446534d, "got %08x\n", msft_header[0]);
1443     ok(msft_header[1] == 0x00010002, "got %08x\n", msft_header[1]);
1444     ok(msft_header[2] == 0xffffffff, "got %08x\n", msft_header[2]);
1445     ok(msft_header[3] == (lcid ? lcid : 0x409), "got %08x (lcid %08x)\n", msft_header[3], lcid);
1446     ok(msft_header[4] == lcid, "got %08x (lcid %08x)\n", msft_header[4], lcid);
1447
1448     DeleteFileA(filename);
1449 }
1450
1451 static void test_create_typelibs(void)
1452 {
1453     test_create_typelib_lcid(LOCALE_SYSTEM_DEFAULT);
1454     test_create_typelib_lcid(LOCALE_USER_DEFAULT);
1455     test_create_typelib_lcid(LOCALE_NEUTRAL);
1456
1457     test_create_typelib_lcid(0x009);
1458     test_create_typelib_lcid(0x409);
1459     test_create_typelib_lcid(0x809);
1460
1461     test_create_typelib_lcid(0x007);
1462     test_create_typelib_lcid(0x407);
1463 }
1464
1465 START_TEST(typelib)
1466 {
1467     const char *filename;
1468
1469     ref_count_test(wszStdOle2);
1470     test_TypeComp();
1471     test_CreateDispTypeInfo();
1472     test_TypeInfo();
1473     test_QueryPathOfRegTypeLib();
1474     test_inheritance();
1475
1476     if ((filename = create_test_typelib()))
1477     {
1478         test_dump_typelib( filename );
1479         DeleteFile( filename );
1480     }
1481
1482     test_create_typelibs();
1483
1484 }