- Sync ole32 and oleaut32 regtests to Wine-1.3.
[reactos.git] / rostests / winetests / oleaut32 / 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 #include "initguid.h"
35
36 #include "test_reg.h"
37
38 #define expect_eq(expr, value, type, format) { type _ret = (expr); ok((value) == _ret, #expr " expected " format " got " format "\n", value, _ret); }
39 #define expect_int(expr, value) expect_eq(expr, (int)(value), int, "%d")
40 #define expect_hex(expr, value) expect_eq(expr, (int)(value), int, "0x%x")
41 #define expect_null(expr) expect_eq(expr, NULL, const void *, "%p")
42
43 #define expect_wstr_acpval(expr, value) \
44 { \
45 CHAR buf[260]; \
46 expect_eq(!WideCharToMultiByte(CP_ACP, 0, (expr), -1, buf, 260, NULL, NULL), 0, int, "%d"); \
47 ok(lstrcmp(value, buf) == 0, #expr " expected \"%s\" got \"%s\"\n", value, buf); \
48 }
49
50 #define ole_expect(expr, expect) { \
51 HRESULT r = expr; \
52 ok(r == (expect), #expr " returned %x, expected %s (%x)\n", r, #expect, expect); \
53 }
54
55 #define ole_check(expr) ole_expect(expr, S_OK);
56
57 #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%08x\n", hr)
58
59 static HRESULT WINAPI (*pRegisterTypeLibForUser)(ITypeLib*,OLECHAR*,OLECHAR*);
60 static HRESULT WINAPI (*pUnRegisterTypeLibForUser)(REFGUID,WORD,WORD,LCID,SYSKIND);
61
62 static const WCHAR wszStdOle2[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
63
64 static void init_function_pointers(void)
65 {
66 HMODULE hmod = GetModuleHandleA("oleaut32.dll");
67
68 pRegisterTypeLibForUser = (void *)GetProcAddress(hmod, "RegisterTypeLibForUser");
69 pUnRegisterTypeLibForUser = (void *)GetProcAddress(hmod, "UnRegisterTypeLibForUser");
70 }
71
72 static void ref_count_test(LPCWSTR type_lib)
73 {
74 ITypeLib *iface;
75 ITypeInfo *iti1, *iti2;
76 HRESULT hRes;
77 int ref_count;
78
79 trace("Loading type library\n");
80 hRes = LoadTypeLib(type_lib, &iface);
81 ok(hRes == S_OK, "Could not load type library\n");
82 if(hRes != S_OK)
83 return;
84
85 hRes = ITypeLib_GetTypeInfo(iface, 1, &iti1);
86 ok(hRes == S_OK, "ITypeLib_GetTypeInfo failed on index = 1\n");
87 ok(ref_count=ITypeLib_Release(iface) > 0, "ITypeLib destroyed while ITypeInfo has back pointer\n");
88 if(!ref_count)
89 return;
90
91 hRes = ITypeLib_GetTypeInfo(iface, 1, &iti2);
92 ok(hRes == S_OK, "ITypeLib_GetTypeInfo failed on index = 1\n");
93 ok(iti1 == iti2, "ITypeLib_GetTypeInfo returned different pointers for same indexes\n");
94
95 ITypeLib_AddRef(iface);
96 ITypeInfo_Release(iti2);
97 ITypeInfo_Release(iti1);
98 ok(ITypeLib_Release(iface) == 0, "ITypeLib should be destroyed here.\n");
99 }
100
101 static void test_TypeComp(void)
102 {
103 ITypeLib *pTypeLib;
104 ITypeComp *pTypeComp;
105 HRESULT hr;
106 ULONG ulHash;
107 DESCKIND desckind;
108 BINDPTR bindptr;
109 ITypeInfo *pTypeInfo;
110 ITypeInfo *pFontTypeInfo;
111 static WCHAR wszStdFunctions[] = {'S','t','d','F','u','n','c','t','i','o','n','s',0};
112 static WCHAR wszSavePicture[] = {'S','a','v','e','P','i','c','t','u','r','e',0};
113 static WCHAR wszOLE_TRISTATE[] = {'O','L','E','_','T','R','I','S','T','A','T','E',0};
114 static WCHAR wszUnchecked[] = {'U','n','c','h','e','c','k','e','d',0};
115 static WCHAR wszIUnknown[] = {'I','U','n','k','n','o','w','n',0};
116 static WCHAR wszFont[] = {'F','o','n','t',0};
117 static WCHAR wszGUID[] = {'G','U','I','D',0};
118 static WCHAR wszStdPicture[] = {'S','t','d','P','i','c','t','u','r','e',0};
119 static WCHAR wszOLE_COLOR[] = {'O','L','E','_','C','O','L','O','R',0};
120 static WCHAR wszClone[] = {'C','l','o','n','e',0};
121 static WCHAR wszclone[] = {'c','l','o','n','e',0};
122 static WCHAR wszJunk[] = {'J','u','n','k',0};
123
124 hr = LoadTypeLib(wszStdOle2, &pTypeLib);
125 ok_ole_success(hr, LoadTypeLib);
126
127 hr = ITypeLib_GetTypeComp(pTypeLib, &pTypeComp);
128 ok_ole_success(hr, ITypeLib_GetTypeComp);
129
130 /* test getting a TKIND_MODULE */
131 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdFunctions);
132 hr = ITypeComp_Bind(pTypeComp, wszStdFunctions, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
133 ok_ole_success(hr, ITypeComp_Bind);
134
135 ok(desckind == DESCKIND_TYPECOMP,
136 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
137 desckind);
138 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
139
140 ITypeComp_Release(bindptr.lptcomp);
141
142 /* test getting a TKIND_MODULE with INVOKE_PROPERTYGET */
143 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdFunctions);
144 hr = ITypeComp_Bind(pTypeComp, wszStdFunctions, ulHash, INVOKE_PROPERTYGET, &pTypeInfo, &desckind, &bindptr);
145 ok_ole_success(hr, ITypeComp_Bind);
146
147 ok(desckind == DESCKIND_TYPECOMP,
148 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
149 desckind);
150 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
151 ITypeComp_Release(bindptr.lptcomp);
152
153 /* test getting a function within a TKIND_MODULE */
154 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszSavePicture);
155 hr = ITypeComp_Bind(pTypeComp, wszSavePicture, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
156 ok_ole_success(hr, ITypeComp_Bind);
157
158 ok(desckind == DESCKIND_FUNCDESC,
159 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
160 desckind);
161 ok(bindptr.lpfuncdesc != NULL, "bindptr.lpfuncdesc should not have been set to NULL\n");
162 ITypeInfo_ReleaseFuncDesc(pTypeInfo, bindptr.lpfuncdesc);
163 ITypeInfo_Release(pTypeInfo);
164
165 /* test getting a function within a TKIND_MODULE with INVOKE_PROPERTYGET */
166 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszSavePicture);
167 hr = ITypeComp_Bind(pTypeComp, wszSavePicture, ulHash, INVOKE_PROPERTYGET, &pTypeInfo, &desckind, &bindptr);
168 ok(hr == TYPE_E_TYPEMISMATCH,
169 "ITypeComp_Bind should have failed with TYPE_E_TYPEMISMATCH instead of 0x%08x\n",
170 hr);
171
172 ok(desckind == DESCKIND_NONE,
173 "desckind should have been DESCKIND_NONE instead of %d\n",
174 desckind);
175 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
176 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
177
178 /* test getting a TKIND_ENUM */
179 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszOLE_TRISTATE);
180 hr = ITypeComp_Bind(pTypeComp, wszOLE_TRISTATE, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
181 ok_ole_success(hr, ITypeComp_Bind);
182
183 ok(desckind == DESCKIND_TYPECOMP,
184 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
185 desckind);
186 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
187
188 ITypeComp_Release(bindptr.lptcomp);
189
190 /* test getting a value within a TKIND_ENUM */
191 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszUnchecked);
192 hr = ITypeComp_Bind(pTypeComp, wszUnchecked, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
193 ok_ole_success(hr, ITypeComp_Bind);
194
195 ok(desckind == DESCKIND_VARDESC,
196 "desckind should have been DESCKIND_VARDESC instead of %d\n",
197 desckind);
198 ITypeInfo_ReleaseVarDesc(pTypeInfo, bindptr.lpvardesc);
199 ITypeInfo_Release(pTypeInfo);
200
201 /* test getting a TKIND_INTERFACE */
202 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszIUnknown);
203 hr = ITypeComp_Bind(pTypeComp, wszIUnknown, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
204 ok_ole_success(hr, ITypeComp_Bind);
205
206 ok(desckind == DESCKIND_NONE,
207 "desckind should have been DESCKIND_NONE instead of %d\n",
208 desckind);
209 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
210 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
211
212 /* test getting a TKIND_DISPATCH */
213 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszFont);
214 hr = ITypeComp_Bind(pTypeComp, wszFont, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
215 ok_ole_success(hr, ITypeComp_Bind);
216
217 ok(desckind == DESCKIND_NONE,
218 "desckind should have been DESCKIND_NONE instead of %d\n",
219 desckind);
220 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
221 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
222
223 /* test getting a TKIND_RECORD/TKIND_ALIAS */
224 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszGUID);
225 hr = ITypeComp_Bind(pTypeComp, wszGUID, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
226 ok_ole_success(hr, ITypeComp_Bind);
227
228 ok(desckind == DESCKIND_NONE,
229 "desckind should have been DESCKIND_NONE instead of %d\n",
230 desckind);
231 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
232 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
233
234 /* test getting a TKIND_ALIAS */
235 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszOLE_COLOR);
236 hr = ITypeComp_Bind(pTypeComp, wszOLE_COLOR, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
237 ok_ole_success(hr, ITypeComp_Bind);
238
239 ok(desckind == DESCKIND_NONE,
240 "desckind should have been DESCKIND_NONE instead of %d\n",
241 desckind);
242 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
243 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
244
245 /* test getting a TKIND_COCLASS */
246 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdPicture);
247 hr = ITypeComp_Bind(pTypeComp, wszStdPicture, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
248 ok_ole_success(hr, ITypeComp_Bind);
249
250 ok(desckind == DESCKIND_NONE,
251 "desckind should have been DESCKIND_NONE instead of %d\n",
252 desckind);
253 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
254 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
255
256 ITypeComp_Release(pTypeComp);
257
258 /* tests for ITypeComp on an interface */
259 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IFont, &pFontTypeInfo);
260 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
261
262 hr = ITypeInfo_GetTypeComp(pFontTypeInfo, &pTypeComp);
263 ok_ole_success(hr, ITypeLib_GetTypeComp);
264
265 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszClone);
266 hr = ITypeComp_Bind(pTypeComp, wszClone, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
267 ok_ole_success(hr, ITypeComp_Bind);
268
269 ok(desckind == DESCKIND_FUNCDESC,
270 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
271 desckind);
272 ok(bindptr.lpfuncdesc != NULL, "bindptr.lpfuncdesc should not have been set to NULL\n");
273 ITypeInfo_ReleaseFuncDesc(pTypeInfo, bindptr.lpfuncdesc);
274 ITypeInfo_Release(pTypeInfo);
275
276 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszClone);
277 hr = ITypeComp_Bind(pTypeComp, wszClone, ulHash, INVOKE_PROPERTYGET, &pTypeInfo, &desckind, &bindptr);
278 ok(hr == TYPE_E_TYPEMISMATCH, "ITypeComp_Bind should have failed with TYPE_E_TYPEMISMATCH instead of 0x%08x\n", hr);
279
280 ok(desckind == DESCKIND_NONE,
281 "desckind should have been DESCKIND_NONE instead of %d\n",
282 desckind);
283 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
284 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
285
286 /* tests that the compare is case-insensitive */
287 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszclone);
288 hr = ITypeComp_Bind(pTypeComp, wszclone, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
289 ok_ole_success(hr, ITypeComp_Bind);
290
291 ok(desckind == DESCKIND_FUNCDESC,
292 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
293 desckind);
294 ok(bindptr.lpfuncdesc != NULL, "bindptr.lpfuncdesc should not have been set to NULL\n");
295 ITypeInfo_ReleaseFuncDesc(pTypeInfo, bindptr.lpfuncdesc);
296 ITypeInfo_Release(pTypeInfo);
297
298 /* tests non-existent members */
299 desckind = 0xdeadbeef;
300 bindptr.lptcomp = (ITypeComp*)0xdeadbeef;
301 pTypeInfo = (ITypeInfo*)0xdeadbeef;
302 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszJunk);
303 hr = ITypeComp_Bind(pTypeComp, wszJunk, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
304 ok_ole_success(hr, ITypeComp_Bind);
305 ok(desckind == DESCKIND_NONE, "desckind should have been DESCKIND_NONE, was: %d\n", desckind);
306 ok(pTypeInfo == NULL, "pTypeInfo should have been NULL, was: %p\n", pTypeInfo);
307 ok(bindptr.lptcomp == NULL, "bindptr should have been NULL, was: %p\n", bindptr.lptcomp);
308
309 ITypeComp_Release(pTypeComp);
310 ITypeInfo_Release(pFontTypeInfo);
311 ITypeLib_Release(pTypeLib);
312 }
313
314 static void test_CreateDispTypeInfo(void)
315 {
316 ITypeInfo *pTypeInfo, *pTI2;
317 HRESULT hr;
318 INTERFACEDATA ifdata;
319 METHODDATA methdata[4];
320 PARAMDATA parms1[2];
321 PARAMDATA parms3[1];
322 TYPEATTR *pTypeAttr;
323 HREFTYPE href;
324 FUNCDESC *pFuncDesc;
325 MEMBERID memid;
326
327 static WCHAR func1[] = {'f','u','n','c','1',0};
328 static const WCHAR func2[] = {'f','u','n','c','2',0};
329 static const WCHAR func3[] = {'f','u','n','c','3',0};
330 static const WCHAR parm1[] = {'p','a','r','m','1',0};
331 static const WCHAR parm2[] = {'p','a','r','m','2',0};
332 OLECHAR *name = func1;
333
334 ifdata.pmethdata = methdata;
335 ifdata.cMembers = sizeof(methdata) / sizeof(methdata[0]);
336
337 methdata[0].szName = SysAllocString(func1);
338 methdata[0].ppdata = parms1;
339 methdata[0].dispid = 0x123;
340 methdata[0].iMeth = 0;
341 methdata[0].cc = CC_STDCALL;
342 methdata[0].cArgs = 2;
343 methdata[0].wFlags = DISPATCH_METHOD;
344 methdata[0].vtReturn = VT_HRESULT;
345 parms1[0].szName = SysAllocString(parm1);
346 parms1[0].vt = VT_I4;
347 parms1[1].szName = SysAllocString(parm2);
348 parms1[1].vt = VT_BSTR;
349
350 methdata[1].szName = SysAllocString(func2);
351 methdata[1].ppdata = NULL;
352 methdata[1].dispid = 0x124;
353 methdata[1].iMeth = 1;
354 methdata[1].cc = CC_STDCALL;
355 methdata[1].cArgs = 0;
356 methdata[1].wFlags = DISPATCH_PROPERTYGET;
357 methdata[1].vtReturn = VT_I4;
358
359 methdata[2].szName = SysAllocString(func3);
360 methdata[2].ppdata = parms3;
361 methdata[2].dispid = 0x125;
362 methdata[2].iMeth = 3;
363 methdata[2].cc = CC_STDCALL;
364 methdata[2].cArgs = 1;
365 methdata[2].wFlags = DISPATCH_PROPERTYPUT;
366 methdata[2].vtReturn = VT_HRESULT;
367 parms3[0].szName = SysAllocString(parm1);
368 parms3[0].vt = VT_I4;
369
370 methdata[3].szName = SysAllocString(func3);
371 methdata[3].ppdata = NULL;
372 methdata[3].dispid = 0x125;
373 methdata[3].iMeth = 4;
374 methdata[3].cc = CC_STDCALL;
375 methdata[3].cArgs = 0;
376 methdata[3].wFlags = DISPATCH_PROPERTYGET;
377 methdata[3].vtReturn = VT_I4;
378
379 hr = CreateDispTypeInfo(&ifdata, LOCALE_NEUTRAL, &pTypeInfo);
380 ok(hr == S_OK, "hr %08x\n", hr);
381
382 hr = ITypeInfo_GetTypeAttr(pTypeInfo, &pTypeAttr);
383 ok(hr == S_OK, "hr %08x\n", hr);
384
385 ok(pTypeAttr->typekind == TKIND_COCLASS, "typekind %0x\n", pTypeAttr->typekind);
386 ok(pTypeAttr->cImplTypes == 1, "cImplTypes %d\n", pTypeAttr->cImplTypes);
387 ok(pTypeAttr->cFuncs == 0, "cFuncs %d\n", pTypeAttr->cFuncs);
388 ok(pTypeAttr->wTypeFlags == 0, "wTypeFlags %04x\n", pTypeAttr->cFuncs);
389 ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr);
390
391 hr = ITypeInfo_GetRefTypeOfImplType(pTypeInfo, 0, &href);
392 ok(hr == S_OK, "hr %08x\n", hr);
393 ok(href == 0, "href = 0x%x\n", href);
394 hr = ITypeInfo_GetRefTypeInfo(pTypeInfo, href, &pTI2);
395 ok(hr == S_OK, "hr %08x\n", hr);
396 hr = ITypeInfo_GetTypeAttr(pTI2, &pTypeAttr);
397 ok(hr == S_OK, "hr %08x\n", hr);
398 ok(pTypeAttr->typekind == TKIND_INTERFACE, "typekind %0x\n", pTypeAttr->typekind);
399 ok(pTypeAttr->cFuncs == 4, "cFuncs %d\n", pTypeAttr->cFuncs);
400 ok(IsEqualGUID(&pTypeAttr->guid, &GUID_NULL), "guid {%08x-...}\n", pTypeAttr->guid.Data1);
401 ok(pTypeAttr->wTypeFlags == 0, "typeflags %08x\n", pTypeAttr->wTypeFlags);
402
403 ITypeInfo_ReleaseTypeAttr(pTI2, pTypeAttr);
404
405 hr = ITypeInfo_GetFuncDesc(pTI2, 0, &pFuncDesc);
406 ok(hr == S_OK, "hr %08x\n", hr);
407 ok(pFuncDesc->memid == 0x123, "memid %x\n", pFuncDesc->memid);
408 ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind);
409 ok(pFuncDesc->invkind == methdata[0].wFlags, "invkind %d\n", pFuncDesc->invkind);
410 ok(pFuncDesc->callconv == methdata[0].cc, "callconv %d\n", pFuncDesc->callconv);
411 ok(pFuncDesc->cParams == methdata[0].cArgs, "cParams %d\n", pFuncDesc->cParams);
412 ok(pFuncDesc->oVft == 0, "oVft %d\n", pFuncDesc->oVft);
413 ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags);
414 ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_HRESULT, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt);
415 ok(pFuncDesc->lprgelemdescParam[0].tdesc.vt == VT_I4, "parm 0 vt %x\n", pFuncDesc->lprgelemdescParam[0].tdesc.vt);
416 ok(U(pFuncDesc->lprgelemdescParam[0]).paramdesc.wParamFlags == PARAMFLAG_NONE, "parm 0 flags %x\n", U(pFuncDesc->lprgelemdescParam[0]).paramdesc.wParamFlags);
417
418 ok(pFuncDesc->lprgelemdescParam[1].tdesc.vt == VT_BSTR, "parm 1 vt %x\n", pFuncDesc->lprgelemdescParam[1].tdesc.vt);
419 ok(U(pFuncDesc->lprgelemdescParam[1]).paramdesc.wParamFlags == PARAMFLAG_NONE, "parm 1 flags %x\n", U(pFuncDesc->lprgelemdescParam[1]).paramdesc.wParamFlags);
420 ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc);
421
422 hr = ITypeInfo_GetFuncDesc(pTI2, 1, &pFuncDesc);
423 ok(hr == S_OK, "hr %08x\n", hr);
424 ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind);
425 ok(pFuncDesc->invkind == methdata[1].wFlags, "invkind %d\n", pFuncDesc->invkind);
426 ok(pFuncDesc->callconv == methdata[1].cc, "callconv %d\n", pFuncDesc->callconv);
427 ok(pFuncDesc->cParams == methdata[1].cArgs, "cParams %d\n", pFuncDesc->cParams);
428 ok(pFuncDesc->oVft == sizeof(void *), "oVft %d\n", pFuncDesc->oVft);
429 ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags);
430 ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_I4, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt);
431 ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc);
432
433 hr = ITypeInfo_GetFuncDesc(pTI2, 2, &pFuncDesc);
434 ok(hr == S_OK, "hr %08x\n", hr);
435 ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind);
436 ok(pFuncDesc->invkind == methdata[2].wFlags, "invkind %d\n", pFuncDesc->invkind);
437 ok(pFuncDesc->callconv == methdata[2].cc, "callconv %d\n", pFuncDesc->callconv);
438 ok(pFuncDesc->cParams == methdata[2].cArgs, "cParams %d\n", pFuncDesc->cParams);
439 ok(pFuncDesc->oVft == 3 * sizeof(void *), "oVft %d\n", pFuncDesc->oVft);
440 ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags);
441 ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_HRESULT, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt);
442 ok(pFuncDesc->lprgelemdescParam[0].tdesc.vt == VT_I4, "parm 0 vt %x\n", pFuncDesc->lprgelemdescParam[0].tdesc.vt);
443 ok(U(pFuncDesc->lprgelemdescParam[0]).paramdesc.wParamFlags == PARAMFLAG_NONE, "parm 0 flags %x\n", U(pFuncDesc->lprgelemdescParam[0]).paramdesc.wParamFlags);
444 ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc);
445
446 hr = ITypeInfo_GetFuncDesc(pTI2, 3, &pFuncDesc);
447 ok(hr == S_OK, "hr %08x\n", hr);
448 ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind);
449 ok(pFuncDesc->invkind == methdata[3].wFlags, "invkind %d\n", pFuncDesc->invkind);
450 ok(pFuncDesc->callconv == methdata[3].cc, "callconv %d\n", pFuncDesc->callconv);
451 ok(pFuncDesc->cParams == methdata[3].cArgs, "cParams %d\n", pFuncDesc->cParams);
452 ok(pFuncDesc->oVft == 4 * sizeof(void *), "oVft %d\n", pFuncDesc->oVft);
453 ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags);
454 ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_I4, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt);
455 ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc);
456
457 /* test GetIDsOfNames on a coclass to see if it searches its interfaces */
458 hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &name, 1, &memid);
459 ok(hr == S_OK, "hr 0x%08x\n", hr);
460 ok(memid == 0x123, "memid 0x%08x\n", memid);
461
462 ITypeInfo_Release(pTI2);
463 ITypeInfo_Release(pTypeInfo);
464
465 SysFreeString(parms1[0].szName);
466 SysFreeString(parms1[1].szName);
467 SysFreeString(parms3[0].szName);
468 SysFreeString(methdata[0].szName);
469 SysFreeString(methdata[1].szName);
470 SysFreeString(methdata[2].szName);
471 SysFreeString(methdata[3].szName);
472 }
473
474 static void test_TypeInfo(void)
475 {
476 ITypeLib *pTypeLib;
477 ITypeInfo *pTypeInfo;
478 ITypeInfo2 *pTypeInfo2;
479 HRESULT hr;
480 static WCHAR wszBogus[] = { 'b','o','g','u','s',0 };
481 static WCHAR wszGetTypeInfo[] = { 'G','e','t','T','y','p','e','I','n','f','o',0 };
482 static WCHAR wszClone[] = {'C','l','o','n','e',0};
483 OLECHAR* bogus = wszBogus;
484 OLECHAR* pwszGetTypeInfo = wszGetTypeInfo;
485 OLECHAR* pwszClone = wszClone;
486 DISPID dispidMember;
487 DISPPARAMS dispparams;
488 GUID bogusguid = {0x806afb4f,0x13f7,0x42d2,{0x89,0x2c,0x6c,0x97,0xc3,0x6a,0x36,0xc1}};
489 VARIANT var;
490
491 hr = LoadTypeLib(wszStdOle2, &pTypeLib);
492 ok_ole_success(hr, LoadTypeLib);
493
494 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IFont, &pTypeInfo);
495 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
496
497 /* test nonexistent method name */
498 hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &bogus, 1, &dispidMember);
499 ok(hr == DISP_E_UNKNOWNNAME,
500 "ITypeInfo_GetIDsOfNames should have returned DISP_E_UNKNOWNNAME instead of 0x%08x\n",
501 hr);
502
503 dispparams.cArgs = 0;
504 dispparams.rgdispidNamedArgs = NULL;
505 dispparams.rgvarg = NULL;
506
507 /* test dispparams not NULL */
508
509 /* invalid member id -- wrong flags -- cNamedArgs not bigger than cArgs */
510 dispparams.cNamedArgs = 0;
511 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, 0xdeadbeef, DISPATCH_PROPERTYGET, &dispparams, NULL, NULL, NULL);
512 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
513 /* invalid member id -- correct flags -- cNamedArgs not bigger than cArgs */
514 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, 0xdeadbeef, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
515 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
516
517 /* invalid member id -- wrong flags -- cNamedArgs bigger than cArgs */
518 dispparams.cNamedArgs = 1;
519 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, 0xdeadbeef, DISPATCH_PROPERTYGET, &dispparams, NULL, NULL, NULL);
520 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
521 /* invalid member id -- correct flags -- cNamedArgs bigger than cArgs */
522 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, 0xdeadbeef, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
523 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
524
525
526 hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &pwszClone, 1, &dispidMember);
527 ok_ole_success(hr, ITypeInfo_GetIDsOfNames);
528
529 /* correct member id -- wrong flags -- cNamedArgs not bigger than cArgs */
530 dispparams.cNamedArgs = 0;
531 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, &dispparams, NULL, NULL, NULL);
532 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
533 /* correct member id -- correct flags -- cNamedArgs not bigger than cArgs
534 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
535 ok(hr == 0x8002000e, "ITypeInfo_Invoke should have returned 0x8002000e instead of 0x%08x\n", hr); */
536
537 /* correct member id -- wrong flags -- cNamedArgs bigger than cArgs */
538 dispparams.cNamedArgs = 1;
539 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, &dispparams, NULL, NULL, NULL);
540 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
541 /* correct member id -- correct flags -- cNamedArgs bigger than cArgs */
542 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
543 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
544
545 /* test NULL dispparams */
546
547 /* correct member id -- wrong flags -- cNamedArgs not bigger than cArgs */
548 dispparams.cNamedArgs = 0;
549 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
550 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
551 /* correct member id -- correct flags -- cNamedArgs not bigger than cArgs */
552 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, NULL, NULL, NULL, NULL);
553 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
554
555 /* correct member id -- wrong flags -- cNamedArgs bigger than cArgs */
556 dispparams.cNamedArgs = 1;
557 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
558 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
559 /* correct member id -- correct flags -- cNamedArgs bigger than cArgs */
560 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, NULL, NULL, NULL, NULL);
561 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
562
563 ITypeInfo_Release(pTypeInfo);
564
565
566
567 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IDispatch, &pTypeInfo);
568 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
569
570 hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &pwszGetTypeInfo, 1, &dispidMember);
571 ok_ole_success(hr, ITypeInfo_GetIDsOfNames);
572
573 hr = ITypeInfo_QueryInterface(pTypeInfo, &IID_ITypeInfo2, (void**)&pTypeInfo2);
574 ok_ole_success(hr, ITypeInfo_QueryInterface);
575
576 if (SUCCEEDED(hr))
577 {
578 VariantInit(&var);
579
580 V_VT(&var) = VT_I4;
581
582 /* test unknown guid passed to GetCustData */
583 hr = ITypeInfo2_GetCustData(pTypeInfo2, &bogusguid, &var);
584 ok_ole_success(hr, ITypeInfo_GetCustData);
585 ok(V_VT(&var) == VT_EMPTY, "got %i, expected VT_EMPTY\n", V_VT(&var));
586
587 ITypeInfo2_Release(pTypeInfo2);
588
589 VariantClear(&var);
590 }
591
592 /* test invoking a method with a [restricted] keyword */
593
594 /* correct member id -- wrong flags -- cNamedArgs not bigger than cArgs */
595 dispparams.cNamedArgs = 0;
596 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, &dispparams, NULL, NULL, NULL);
597 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
598 /* correct member id -- correct flags -- cNamedArgs not bigger than cArgs */
599 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
600 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
601
602 /* correct member id -- wrong flags -- cNamedArgs bigger than cArgs */
603 dispparams.cNamedArgs = 1;
604 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, &dispparams, NULL, NULL, NULL);
605 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
606 /* correct member id -- correct flags -- cNamedArgs bigger than cArgs */
607 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
608 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
609
610 /* test NULL dispparams */
611
612 /* correct member id -- wrong flags -- cNamedArgs not bigger than cArgs */
613 dispparams.cNamedArgs = 0;
614 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
615 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
616 /* correct member id -- correct flags -- cNamedArgs not bigger than cArgs */
617 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, NULL, NULL, NULL, NULL);
618 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
619
620 /* correct member id -- wrong flags -- cNamedArgs bigger than cArgs */
621 dispparams.cNamedArgs = 1;
622 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
623 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
624 /* correct member id -- correct flags -- cNamedArgs bigger than cArgs */
625 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, NULL, NULL, NULL, NULL);
626 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
627
628 ITypeInfo_Release(pTypeInfo);
629 ITypeLib_Release(pTypeLib);
630 }
631
632 /* RegDeleteTreeW from dlls/advapi32/registry.c */
633 static LSTATUS myRegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
634 {
635 LONG ret;
636 DWORD dwMaxSubkeyLen, dwMaxValueLen;
637 DWORD dwMaxLen, dwSize;
638 WCHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
639 HKEY hSubKey = hKey;
640
641 if(lpszSubKey)
642 {
643 ret = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
644 if (ret) return ret;
645 }
646
647 ret = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL,
648 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
649 if (ret) goto cleanup;
650
651 dwMaxSubkeyLen++;
652 dwMaxValueLen++;
653 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
654 if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR))
655 {
656 /* Name too big: alloc a buffer for it */
657 if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(WCHAR))))
658 {
659 ret = ERROR_NOT_ENOUGH_MEMORY;
660 goto cleanup;
661 }
662 }
663
664 /* Recursively delete all the subkeys */
665 while (TRUE)
666 {
667 dwSize = dwMaxLen;
668 if (RegEnumKeyExW(hSubKey, 0, lpszName, &dwSize, NULL,
669 NULL, NULL, NULL)) break;
670
671 ret = myRegDeleteTreeW(hSubKey, lpszName);
672 if (ret) goto cleanup;
673 }
674
675 if (lpszSubKey)
676 ret = RegDeleteKeyW(hKey, lpszSubKey);
677 else
678 while (TRUE)
679 {
680 dwSize = dwMaxLen;
681 if (RegEnumValueW(hKey, 0, lpszName, &dwSize,
682 NULL, NULL, NULL, NULL)) break;
683
684 ret = RegDeleteValueW(hKey, lpszName);
685 if (ret) goto cleanup;
686 }
687
688 cleanup:
689 if (lpszName != szNameBuf)
690 HeapFree(GetProcessHeap(), 0, lpszName);
691 if(lpszSubKey)
692 RegCloseKey(hSubKey);
693 return ret;
694 }
695
696 static BOOL do_typelib_reg_key(GUID *uid, WORD maj, WORD min, LPCWSTR base, BOOL remove)
697 {
698 static const WCHAR typelibW[] = {'T','y','p','e','l','i','b','\\',0};
699 static const WCHAR formatW[] = {'\\','%','u','.','%','u','\\','0','\\','w','i','n','3','2',0};
700 static const WCHAR format2W[] = {'%','s','_','%','u','_','%','u','.','d','l','l',0};
701 WCHAR buf[128];
702 HKEY hkey;
703 BOOL ret = TRUE;
704 DWORD res;
705
706 memcpy(buf, typelibW, sizeof(typelibW));
707 StringFromGUID2(uid, buf + lstrlenW(buf), 40);
708
709 if (remove)
710 {
711 ok(myRegDeleteTreeW(HKEY_CLASSES_ROOT, buf) == ERROR_SUCCESS, "SHDeleteKey failed\n");
712 return TRUE;
713 }
714
715 wsprintfW(buf + lstrlenW(buf), formatW, maj, min );
716
717 SetLastError(0xdeadbeef);
718 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, buf, 0, NULL, 0,
719 KEY_WRITE, NULL, &hkey, NULL);
720 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
721 {
722 win_skip("W-calls are not implemented\n");
723 return FALSE;
724 }
725
726 if (res != ERROR_SUCCESS)
727 {
728 trace("RegCreateKeyExW failed\n");
729 return FALSE;
730 }
731
732 wsprintfW(buf, format2W, base, maj, min);
733 if (RegSetValueExW(hkey, NULL, 0, REG_SZ,
734 (BYTE *)buf, (lstrlenW(buf) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
735 {
736 trace("RegSetValueExW failed\n");
737 ret = FALSE;
738 }
739 RegCloseKey(hkey);
740 return ret;
741 }
742
743 static void test_QueryPathOfRegTypeLib(void)
744 {
745 static const struct test_data
746 {
747 WORD maj, min;
748 HRESULT ret;
749 const WCHAR path[16];
750 } td[] = {
751 { 1, 0, TYPE_E_LIBNOTREGISTERED, { 0 } },
752 { 3, 0, S_OK, {'f','a','k','e','_','3','_','0','.','d','l','l',0 } },
753 { 3, 1, S_OK, {'f','a','k','e','_','3','_','1','.','d','l','l',0 } },
754 { 3, 22, S_OK, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
755 { 3, 37, S_OK, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
756 { 3, 40, S_OK, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
757 { 0xffff, 0xffff, S_OK, {'f','a','k','e','_','5','_','3','7','.','d','l','l',0 } },
758 { 0xffff, 0, TYPE_E_LIBNOTREGISTERED, { 0 } },
759 { 3, 0xffff, TYPE_E_LIBNOTREGISTERED, { 0 } },
760 { 5, 0xffff, TYPE_E_LIBNOTREGISTERED, { 0 } },
761 { 4, 0, TYPE_E_LIBNOTREGISTERED, { 0 } }
762 };
763 static const WCHAR base[] = {'f','a','k','e',0};
764 UINT i;
765 RPC_STATUS status;
766 GUID uid;
767 WCHAR uid_str[40];
768 HRESULT ret;
769 BSTR path;
770
771 status = UuidCreate(&uid);
772 ok(!status || status == RPC_S_UUID_LOCAL_ONLY, "UuidCreate error %08x\n", status);
773
774 StringFromGUID2(&uid, uid_str, 40);
775 /*trace("GUID: %s\n", wine_dbgstr_w(uid_str));*/
776
777 if (!do_typelib_reg_key(&uid, 3, 0, base, 0)) return;
778 if (!do_typelib_reg_key(&uid, 3, 1, base, 0)) return;
779 if (!do_typelib_reg_key(&uid, 3, 37, base, 0)) return;
780 if (!do_typelib_reg_key(&uid, 5, 37, base, 0)) return;
781
782 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
783 {
784 ret = QueryPathOfRegTypeLib(&uid, td[i].maj, td[i].min, 0, &path);
785 ok(ret == td[i].ret, "QueryPathOfRegTypeLib(%u.%u) returned %08x\n", td[i].maj, td[i].min, ret);
786 if (ret == S_OK)
787 {
788 ok(!lstrcmpW(td[i].path, path), "typelib %u.%u path doesn't match\n", td[i].maj, td[i].min);
789 SysFreeString(path);
790 }
791 }
792
793 do_typelib_reg_key(&uid, 0, 0, NULL, 1);
794 }
795
796 static void test_inheritance(void)
797 {
798 HRESULT hr;
799 ITypeLib *pTL;
800 ITypeInfo *pTI, *pTI_p;
801 TYPEATTR *pTA;
802 HREFTYPE href;
803 FUNCDESC *pFD;
804 WCHAR path[MAX_PATH];
805 CHAR pathA[MAX_PATH];
806 static const WCHAR tl_path[] = {'.','\\','m','i','d','l','_','t','m','a','r','s','h','a','l','.','t','l','b',0};
807
808 BOOL use_midl_tlb = 0;
809
810 GetModuleFileNameA(NULL, pathA, MAX_PATH);
811 MultiByteToWideChar(CP_ACP, 0, pathA, -1, path, MAX_PATH);
812
813 if(use_midl_tlb)
814 memcpy(path, tl_path, sizeof(tl_path));
815
816 hr = LoadTypeLib(path, &pTL);
817 if(FAILED(hr)) return;
818
819
820 /* ItestIF3 is a syntax 2 dispinterface */
821 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF3, &pTI);
822 ok(hr == S_OK, "hr %08x\n", hr);
823
824 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
825 ok(hr == S_OK, "hr %08x\n", hr);
826 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
827 ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
828 ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
829 if(use_midl_tlb) {
830 ok(pTA->cFuncs == 6, "cfuncs %d\n", pTA->cFuncs);
831 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
832 }
833 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
834
835 if(use_midl_tlb) {
836 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
837 ok(hr == S_OK, "hr %08x\n", hr);
838 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
839 ok(hr == S_OK, "hr %08x\n", hr);
840 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
841 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
842 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
843 ITypeInfo_Release(pTI_p);
844
845 /* Should have six methods */
846 hr = ITypeInfo_GetFuncDesc(pTI, 6, &pFD);
847 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
848 hr = ITypeInfo_GetFuncDesc(pTI, 5, &pFD);
849 ok(hr == S_OK, "hr %08x\n", hr);
850 ok(pFD->memid == 0x60020000, "memid %08x\n", pFD->memid);
851 ok(pFD->oVft == 5 * sizeof(void *), "oVft %d\n", pFD->oVft);
852 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
853 }
854 ITypeInfo_Release(pTI);
855
856
857 /* ItestIF4 is a syntax 1 dispinterface */
858 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF4, &pTI);
859 ok(hr == S_OK, "hr %08x\n", hr);
860
861 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
862 ok(hr == S_OK, "hr %08x\n", hr);
863 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
864 ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
865 ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
866 ok(pTA->cFuncs == 1, "cfuncs %d\n", pTA->cFuncs);
867 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
868 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
869
870 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
871 ok(hr == S_OK, "hr %08x\n", hr);
872 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
873 ok(hr == S_OK, "hr %08x\n", hr);
874 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
875 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
876 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
877 ITypeInfo_Release(pTI_p);
878 hr = ITypeInfo_GetFuncDesc(pTI, 1, &pFD);
879 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
880 hr = ITypeInfo_GetFuncDesc(pTI, 0, &pFD);
881 ok(hr == S_OK, "hr %08x\n", hr);
882 ok(pFD->memid == 0x1c, "memid %08x\n", pFD->memid);
883 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
884 ITypeInfo_Release(pTI);
885
886
887 /* ItestIF5 is dual with inherited ifaces which derive from IUnknown but not IDispatch */
888 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &IID_ItestIF5, &pTI);
889 ok(hr == S_OK, "hr %08x\n", hr);
890
891 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
892 ok(hr == S_OK, "hr %08x\n", hr);
893 if (hr == S_OK)
894 {
895 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
896 ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
897 if(use_midl_tlb) {
898 ok(pTA->wTypeFlags == TYPEFLAG_FDUAL, "typeflags %x\n", pTA->wTypeFlags);
899 }
900 ok(pTA->cFuncs == 8, "cfuncs %d\n", pTA->cFuncs);
901 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
902 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
903 }
904 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
905 ok(hr == S_OK, "hr %08x\n", hr);
906 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
907 ok(hr == S_OK, "hr %08x\n", hr);
908 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
909 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
910 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
911 ITypeInfo_Release(pTI_p);
912 if(use_midl_tlb) {
913 hr = ITypeInfo_GetFuncDesc(pTI, 6, &pFD);
914 ok(hr == S_OK, "hr %08x\n", hr);
915 ok(pFD->memid == 0x1234, "memid %08x\n", pFD->memid);
916 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
917 }
918 ITypeInfo_Release(pTI);
919
920 /* ItestIF7 is dual with inherited ifaces which derive from Dispatch */
921 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &IID_ItestIF7, &pTI);
922 ok(hr == S_OK, "hr %08x\n", hr);
923
924 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
925 ok(hr == S_OK, "hr %08x\n", hr);
926 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
927 ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
928 ok(pTA->wTypeFlags == (TYPEFLAG_FDISPATCHABLE|TYPEFLAG_FDUAL), "typeflags %x\n", pTA->wTypeFlags);
929 ok(pTA->cFuncs == 10, "cfuncs %d\n", pTA->cFuncs);
930 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
931 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
932
933 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
934 ok(hr == S_OK, "hr %08x\n", hr);
935 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
936 ok(hr == S_OK, "hr %08x\n", hr);
937 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
938 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
939 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
940 ITypeInfo_Release(pTI_p);
941
942 hr = ITypeInfo_GetFuncDesc(pTI, 9, &pFD);
943 ok(hr == S_OK, "hr %08x\n", hr);
944 ok(pFD->memid == 0x1236, "memid %08x\n", pFD->memid);
945 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
946 ITypeInfo_Release(pTI);
947
948 /* ItestIF10 is a syntax 2 dispinterface which doesn't derive from IUnknown */
949 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF10, &pTI);
950 ok(hr == S_OK, "hr %08x\n", hr);
951
952 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
953 ok(hr == S_OK, "hr %08x\n", hr);
954 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
955 ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
956 ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
957 if(use_midl_tlb) {
958 ok(pTA->cFuncs == 3, "cfuncs %d\n", pTA->cFuncs);
959 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
960 }
961 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
962
963 if(use_midl_tlb) {
964 hr = ITypeInfo_GetRefTypeOfImplType(pTI, -1, &href);
965 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
966 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
967 ok(hr == S_OK, "hr %08x\n", hr);
968 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
969 ok(hr == S_OK, "hr %08x\n", hr);
970 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
971 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
972 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
973 ITypeInfo_Release(pTI_p);
974
975 /* Should have three methods */
976 hr = ITypeInfo_GetFuncDesc(pTI, 3, &pFD);
977 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
978 hr = ITypeInfo_GetFuncDesc(pTI, 2, &pFD);
979 ok(hr == S_OK, "hr %08x\n", hr);
980 ok(pFD->memid == 0x60010000, "memid %08x\n", pFD->memid);
981 ok(pFD->oVft == 2 * sizeof(void *), "oVft %d\n", pFD->oVft);
982 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
983 }
984 ITypeInfo_Release(pTI);
985
986 /* ItestIF11 is a syntax 2 dispinterface which derives from IDispatch */
987 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF11, &pTI);
988 ok(hr == S_OK, "hr %08x\n", hr);
989
990 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
991 ok(hr == S_OK, "hr %08x\n", hr);
992 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
993 ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
994 ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
995 if(use_midl_tlb) {
996 ok(pTA->cFuncs == 10, "cfuncs %d\n", pTA->cFuncs);
997 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
998 }
999 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
1000
1001 if(use_midl_tlb) {
1002 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
1003 ok(hr == S_OK, "hr %08x\n", hr);
1004 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
1005 ok(hr == S_OK, "hr %08x\n", hr);
1006 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
1007 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
1008 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
1009 ITypeInfo_Release(pTI_p);
1010
1011 /* Should have ten methods */
1012 hr = ITypeInfo_GetFuncDesc(pTI, 10, &pFD);
1013 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
1014 hr = ITypeInfo_GetFuncDesc(pTI, 9, &pFD);
1015 ok(hr == S_OK, "hr %08x\n", hr);
1016 ok(pFD->memid == 0x1236, "memid %08x\n", pFD->memid);
1017 ok(pFD->oVft == 9 * sizeof(void *), "oVft %d\n", pFD->oVft);
1018
1019 /* first argument to 10th function is an HREFTYPE from the impl type */
1020 ok(pFD->cParams == 1, "cParams %i\n", pFD->cParams);
1021 ok(pFD->lprgelemdescParam[0].tdesc.vt == VT_USERDEFINED,
1022 "vt 0x%x\n", pFD->lprgelemdescParam[0].tdesc.vt);
1023 href = U(pFD->lprgelemdescParam[0].tdesc).hreftype;
1024 ok((href & 0xff000000) == 0x04000000, "href 0x%08x\n", href);
1025 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
1026 ok(SUCCEEDED(hr), "hr %08x\n", hr);
1027 if (SUCCEEDED(hr)) ITypeInfo_Release(pTI_p);
1028 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
1029 }
1030 ITypeInfo_Release(pTI);
1031
1032
1033 /* ItestIF2 is an interface which derives from IUnknown */
1034 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &IID_ItestIF2, &pTI);
1035 ok(hr == S_OK, "hr %08x\n", hr);
1036
1037 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
1038 ok(hr == S_OK, "hr %08x\n", hr);
1039 ok(pTA->typekind == TKIND_INTERFACE, "kind %04x\n", pTA->typekind);
1040 ok(pTA->cbSizeVft == 6 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
1041 ok(pTA->wTypeFlags == 0, "typeflags %x\n", pTA->wTypeFlags);
1042 if(use_midl_tlb) {
1043 ok(pTA->cFuncs == 1, "cfuncs %d\n", pTA->cFuncs);
1044 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
1045 }
1046 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
1047
1048 if(use_midl_tlb) {
1049 /* Should have one method */
1050 hr = ITypeInfo_GetFuncDesc(pTI, 1, &pFD);
1051 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
1052 hr = ITypeInfo_GetFuncDesc(pTI, 0, &pFD);
1053 ok(hr == S_OK, "hr %08x\n", hr);
1054 ok(pFD->memid == 0x60020000, "memid %08x\n", pFD->memid);
1055 ok(pFD->oVft == 5 * sizeof(void *), "oVft %d\n", pFD->oVft);
1056 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
1057 }
1058 ITypeInfo_Release(pTI);
1059
1060 ITypeLib_Release(pTL);
1061
1062 return;
1063 }
1064
1065 static void test_CreateTypeLib(void) {
1066 static const WCHAR stdoleW[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1067 static OLECHAR typelibW[] = {'t','y','p','e','l','i','b',0};
1068 static OLECHAR helpfileW[] = {'C',':','\\','b','o','g','u','s','.','h','l','p',0};
1069 static OLECHAR interface1W[] = {'i','n','t','e','r','f','a','c','e','1',0};
1070 static OLECHAR interface2W[] = {'i','n','t','e','r','f','a','c','e','2',0};
1071 static OLECHAR interface3W[] = {'i','n','t','e','r','f','a','c','e','3',0};
1072 static OLECHAR dualW[] = {'d','u','a','l',0};
1073 static OLECHAR coclassW[] = {'c','o','c','l','a','s','s',0};
1074 static WCHAR defaultW[] = {'d','e','f','a','u','l','t',0x3213,0};
1075 static OLECHAR func1W[] = {'f','u','n','c','1',0};
1076 static OLECHAR func2W[] = {'f','u','n','c','2',0};
1077 static OLECHAR prop1W[] = {'P','r','o','p','1',0};
1078 static OLECHAR param1W[] = {'p','a','r','a','m','1',0};
1079 static OLECHAR param2W[] = {'p','a','r','a','m','2',0};
1080 static OLECHAR *names1[] = {func1W, param1W, param2W};
1081 static OLECHAR *names2[] = {func2W, param1W, param2W};
1082 static OLECHAR *propname[] = {prop1W, param1W};
1083 static const GUID custguid = {0xbf611abe,0x5b38,0x11df,{0x91,0x5c,0x08,0x02,0x79,0x79,0x94,0x70}};
1084
1085 char filename[MAX_PATH];
1086 WCHAR filenameW[MAX_PATH];
1087 ICreateTypeLib2 *createtl;
1088 ICreateTypeInfo *createti;
1089 ICreateTypeInfo2 *createti2;
1090 ITypeLib *tl, *stdole;
1091 ITypeInfo *interface1, *interface2, *dual, *unknown, *dispatch, *ti;
1092 ITypeInfo2 *ti2;
1093 FUNCDESC funcdesc;
1094 ELEMDESC elemdesc[5];
1095 PARAMDESCEX paramdescex;
1096 TYPEDESC typedesc1, typedesc2;
1097 TYPEATTR *typeattr;
1098 TLIBATTR *libattr;
1099 HREFTYPE hreftype;
1100 BSTR name, docstring, helpfile;
1101 DWORD helpcontext;
1102 int impltypeflags;
1103 VARIANT cust_data;
1104 HRESULT hres;
1105
1106 trace("CreateTypeLib tests\n");
1107
1108 hres = LoadTypeLib(stdoleW, &stdole);
1109 ok(hres == S_OK, "got %08x\n", hres);
1110
1111 hres = ITypeLib_GetTypeInfoOfGuid(stdole, &IID_IUnknown, &unknown);
1112 ok(hres == S_OK, "got %08x\n", hres);
1113
1114 hres = ITypeLib_GetTypeInfoOfGuid(stdole, &IID_IDispatch, &dispatch);
1115 ok(hres == S_OK, "got %08x\n", hres);
1116
1117 GetTempFileNameA(".", "tlb", 0, filename);
1118 MultiByteToWideChar(CP_ACP, 0, filename, -1, filenameW, MAX_PATH);
1119
1120 hres = CreateTypeLib2(SYS_WIN32, filenameW, &createtl);
1121 ok(hres == S_OK, "got %08x\n", hres);
1122
1123 hres = ICreateTypeLib_QueryInterface(createtl, &IID_ITypeLib, (void**)&tl);
1124 ok(hres == S_OK, "got %08x\n", hres);
1125
1126 hres = ITypeLib_GetLibAttr(tl, &libattr);
1127 ok(hres == S_OK, "got %08x\n", hres);
1128
1129 ok(libattr->syskind == SYS_WIN32, "syskind = %d\n", libattr->syskind);
1130 ok(libattr->wMajorVerNum == 0, "wMajorVer = %d\n", libattr->wMajorVerNum);
1131 ok(libattr->wMinorVerNum == 0, "wMinorVerNum = %d\n", libattr->wMinorVerNum);
1132 ok(libattr->wLibFlags == 0, "wLibFlags = %d\n", libattr->wLibFlags);
1133
1134 ITypeLib_ReleaseTLibAttr(tl, libattr);
1135
1136 name = (BSTR)0xdeadbeef;
1137 hres = ITypeLib_GetDocumentation(tl, -1, &name, &docstring, &helpcontext, &helpfile);
1138 ok(hres == S_OK, "got %08x\n", hres);
1139 ok(name == NULL, "name != NULL\n");
1140 ok(docstring == NULL, "docstring != NULL\n");
1141 ok(helpcontext == 0, "helpcontext != 0\n");
1142 ok(helpfile == NULL, "helpfile != NULL\n");
1143
1144 hres = ITypeLib_GetDocumentation(tl, 0, &name, NULL, NULL, NULL);
1145 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1146
1147 hres = ICreateTypeLib_SetName(createtl, typelibW);
1148 ok(hres == S_OK, "got %08x\n", hres);
1149
1150 hres = ICreateTypeLib_SetHelpFileName(createtl, helpfileW);
1151 ok(hres == S_OK, "got %08x\n", hres);
1152
1153 hres = ITypeLib_GetDocumentation(tl, -1, NULL, NULL, NULL, NULL);
1154 ok(hres == S_OK, "got %08x\n", hres);
1155
1156 hres = ITypeLib_GetDocumentation(tl, -1, &name, NULL, NULL, &helpfile);
1157 ok(hres == S_OK, "got %08x\n", hres);
1158 ok(!memcmp(name, typelibW, sizeof(typelibW)), "name = %s\n", wine_dbgstr_w(name));
1159 ok(!memcmp(helpfile, helpfileW, sizeof(helpfileW)), "helpfile = %s\n", wine_dbgstr_w(helpfile));
1160
1161 SysFreeString(name);
1162 SysFreeString(helpfile);
1163
1164 hres = ICreateTypeLib_CreateTypeInfo(createtl, interface1W, TKIND_INTERFACE, &createti);
1165 ok(hres == S_OK, "got %08x\n", hres);
1166
1167 hres = ICreateTypeInfo_QueryInterface(createti, &IID_ITypeInfo, (void**)&interface1);
1168 ok(hres == S_OK, "got %08x\n", hres);
1169
1170 hres = ITypeLib_GetDocumentation(tl, 0, &name, NULL, NULL, NULL);
1171 ok(hres == S_OK, "got %08x\n", hres);
1172 ok(!memcmp(name, interface1W, sizeof(interface1W)), "name = %s\n", wine_dbgstr_w(name));
1173
1174 SysFreeString(name);
1175
1176 ITypeLib_Release(tl);
1177
1178 name = (BSTR)0xdeadbeef;
1179 helpfile = (BSTR)0xdeadbeef;
1180 hres = ITypeInfo_GetDocumentation(interface1, -1, &name, &docstring, &helpcontext, &helpfile);
1181 ok(hres == S_OK, "got %08x\n", hres);
1182 ok(!memcmp(name, interface1W, sizeof(interface1W)), "name = %s\n", wine_dbgstr_w(name));
1183 ok(docstring == NULL, "docstring != NULL\n");
1184 ok(helpcontext == 0, "helpcontext != 0\n");
1185 ok(!memcmp(helpfile, helpfileW, sizeof(helpfileW)), "helpfile = %s\n", wine_dbgstr_w(helpfile));
1186
1187 SysFreeString(name);
1188 SysFreeString(helpfile);
1189
1190 hres = ITypeInfo_GetDocumentation(interface1, 0, &name, NULL, NULL, NULL);
1191 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1192
1193 hres = ITypeInfo_GetRefTypeInfo(interface1, 0, NULL);
1194 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1195
1196
1197 hres = ICreateTypeInfo_LayOut(createti);
1198 ok(hres == S_OK, "got %08x\n", hres);
1199
1200 hres = ICreateTypeInfo_AddRefTypeInfo(createti, NULL, &hreftype);
1201 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1202
1203 hres = ICreateTypeInfo_AddRefTypeInfo(createti, unknown, NULL);
1204 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1205
1206 hres = ICreateTypeInfo_AddRefTypeInfo(createti, unknown, &hreftype);
1207 ok(hres == S_OK, "got %08x\n", hres);
1208 if(hres != S_OK) {
1209 skip("Skipping some tests\n");
1210 return;
1211 }
1212
1213 hres = ICreateTypeInfo_AddImplType(createti, 1, hreftype);
1214 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1215
1216 hres = ICreateTypeInfo_AddImplType(createti, 0, hreftype);
1217 ok(hres == S_OK, "got %08x\n", hres);
1218
1219 hres = ITypeInfo_GetRefTypeOfImplType(interface1, 0, &hreftype);
1220 ok(hres == S_OK, "got %08x\n", hres);
1221 ok(hreftype == 3, "hreftype = %d\n", hreftype);
1222
1223 hres = ITypeInfo_GetRefTypeOfImplType(interface1, -1, &hreftype);
1224 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1225
1226 memset(&funcdesc, 0, sizeof(FUNCDESC));
1227 funcdesc.funckind = FUNC_PUREVIRTUAL;
1228 funcdesc.invkind = INVOKE_PROPERTYGET;
1229 funcdesc.callconv = CC_STDCALL;
1230 funcdesc.elemdescFunc.tdesc.vt = VT_BSTR;
1231 U(funcdesc.elemdescFunc).idldesc.wIDLFlags = IDLFLAG_NONE;
1232
1233 hres = ICreateTypeInfo_AddFuncDesc(createti, 0, NULL);
1234 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1235
1236 hres = ICreateTypeInfo_AddFuncDesc(createti, 1, &funcdesc);
1237 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1238
1239 hres = ICreateTypeInfo_AddFuncDesc(createti, 0, &funcdesc);
1240 ok(hres == S_OK, "got %08x\n", hres);
1241
1242 hres = ICreateTypeInfo_SetFuncHelpContext(createti, 0, 0xabcdefab);
1243 ok(hres == S_OK, "got %08x\n", hres);
1244
1245 funcdesc.invkind = INVOKE_PROPERTYPUT;
1246 hres = ICreateTypeInfo_AddFuncDesc(createti, 1, &funcdesc);
1247 ok(hres == TYPE_E_INCONSISTENTPROPFUNCS, "got %08x\n", hres);
1248
1249 funcdesc.invkind = INVOKE_PROPERTYPUTREF;
1250 hres = ICreateTypeInfo_AddFuncDesc(createti, 1, &funcdesc);
1251 ok(hres == TYPE_E_INCONSISTENTPROPFUNCS, "got %08x\n", hres);
1252
1253 elemdesc[0].tdesc.vt = VT_BSTR;
1254 U(elemdesc[0]).idldesc.dwReserved = 0;
1255 U(elemdesc[0]).idldesc.wIDLFlags = IDLFLAG_FIN;
1256
1257 funcdesc.lprgelemdescParam = elemdesc;
1258 funcdesc.invkind = INVOKE_PROPERTYPUT;
1259 funcdesc.cParams = 1;
1260 funcdesc.elemdescFunc.tdesc.vt = VT_VOID;
1261
1262 hres = ICreateTypeInfo_AddFuncDesc(createti, 1, &funcdesc);
1263 ok(hres == S_OK, "got %08x\n", hres);
1264
1265 hres = ICreateTypeInfo_SetFuncHelpContext(createti, 1, 0xabcdefab);
1266 ok(hres == S_OK, "got %08x\n", hres);
1267
1268 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 0, propname, 1);
1269 ok(hres == S_OK, "got %08x\n", hres);
1270
1271 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 1, propname, 1);
1272 ok(hres == S_OK, "got %08x\n", hres);
1273
1274 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 1, propname, 2);
1275 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1276
1277
1278 funcdesc.invkind = INVOKE_PROPERTYPUTREF;
1279 hres = ICreateTypeInfo_AddFuncDesc(createti, 0, &funcdesc);
1280 ok(hres == S_OK, "got %08x\n", hres);
1281
1282 hres = ICreateTypeInfo_SetFuncHelpContext(createti, 0, 0xabcdefab);
1283 ok(hres == S_OK, "got %08x\n", hres);
1284
1285 hres = ICreateTypeInfo_SetFuncHelpContext(createti, 0, 0x201);
1286 ok(hres == S_OK, "got %08x\n", hres);
1287
1288 funcdesc.memid = 1;
1289 funcdesc.lprgelemdescParam = NULL;
1290 funcdesc.invkind = INVOKE_FUNC;
1291 funcdesc.cParams = 0;
1292 hres = ICreateTypeInfo_AddFuncDesc(createti, 1, &funcdesc);
1293 ok(hres == S_OK, "got %08x\n", hres);
1294
1295 funcdesc.memid = MEMBERID_NIL;
1296 hres = ICreateTypeInfo_AddFuncDesc(createti, 1, &funcdesc);
1297 ok(hres == S_OK, "got %08x\n", hres);
1298
1299 elemdesc[0].tdesc.vt = VT_PTR;
1300 U(elemdesc[0].tdesc).lptdesc = &typedesc1;
1301 typedesc1.vt = VT_BSTR;
1302 funcdesc.cParams = 1;
1303 funcdesc.lprgelemdescParam = elemdesc;
1304 hres = ICreateTypeInfo_AddFuncDesc(createti, 4, &funcdesc);
1305 ok(hres == S_OK, "got %08x\n", hres);
1306
1307 U(elemdesc[0].tdesc).lptdesc = &typedesc2;
1308 typedesc2.vt = VT_PTR;
1309 U(typedesc2).lptdesc = &typedesc1;
1310 hres = ICreateTypeInfo_AddFuncDesc(createti, 4, &funcdesc);
1311 ok(hres == S_OK, "got %08x\n", hres);
1312
1313 elemdesc[0].tdesc.vt = VT_INT;
1314 U(elemdesc[0]).paramdesc.wParamFlags = PARAMFLAG_FHASDEFAULT;
1315 U(elemdesc[0]).paramdesc.pparamdescex = &paramdescex;
1316 V_VT(&paramdescex.varDefaultValue) = VT_INT;
1317 V_INT(&paramdescex.varDefaultValue) = 0x123;
1318 hres = ICreateTypeInfo_AddFuncDesc(createti, 3, &funcdesc);
1319 ok(hres == S_OK, "got %08x\n", hres);
1320
1321 U(elemdesc[0]).idldesc.dwReserved = 0;
1322 U(elemdesc[0]).idldesc.wIDLFlags = IDLFLAG_FIN;
1323 elemdesc[1].tdesc.vt = VT_UI2;
1324 U(elemdesc[1]).paramdesc.wParamFlags = PARAMFLAG_FHASDEFAULT;
1325 U(elemdesc[1]).paramdesc.pparamdescex = &paramdescex;
1326 V_VT(&paramdescex.varDefaultValue) = VT_UI2;
1327 V_UI2(&paramdescex.varDefaultValue) = 0xffff;
1328 funcdesc.cParams = 2;
1329 hres = ICreateTypeInfo_AddFuncDesc(createti, 3, &funcdesc);
1330 ok(hres == S_OK, "got %08x\n", hres);
1331
1332 U(elemdesc[0]).paramdesc.wParamFlags = PARAMFLAG_FHASDEFAULT;
1333 U(elemdesc[0]).paramdesc.pparamdescex = &paramdescex;
1334 elemdesc[1].tdesc.vt = VT_INT;
1335 V_VT(&paramdescex.varDefaultValue) = VT_INT;
1336 V_INT(&paramdescex.varDefaultValue) = 0xffffffff;
1337 hres = ICreateTypeInfo_AddFuncDesc(createti, 3, &funcdesc);
1338 ok(hres == S_OK, "got %08x\n", hres);
1339
1340 elemdesc[0].tdesc.vt = VT_BSTR;
1341 elemdesc[1].tdesc.vt = VT_BSTR;
1342 V_VT(&paramdescex.varDefaultValue) = VT_BSTR;
1343 V_BSTR(&paramdescex.varDefaultValue) = SysAllocString(defaultW);
1344 hres = ICreateTypeInfo_AddFuncDesc(createti, 3, &funcdesc);
1345 ok(hres == S_OK, "got %08x\n", hres);
1346
1347 hres = ITypeInfo_GetDocumentation(interface1, 0, &name, &docstring, &helpcontext, &helpfile);
1348 ok(hres == S_OK, "got %08x\n", hres);
1349 ok(name == NULL, "name != NULL\n");
1350 ok(docstring == NULL, "docstring != NULL\n");
1351 ok(helpcontext == 0x201, "helpcontext != 0x201\n");
1352 ok(!memcmp(helpfile, helpfileW, sizeof(helpfileW)), "helpfile = %s\n", wine_dbgstr_w(helpfile));
1353
1354 SysFreeString(helpfile);
1355
1356 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 1000, NULL, 1);
1357 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1358
1359 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 1000, names1, 1);
1360 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1361
1362 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 0, names1, 2);
1363 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1364
1365 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 0, names2, 1);
1366 ok(hres == S_OK, "got %08x\n", hres);
1367
1368 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 0, names1, 1);
1369 ok(hres == S_OK, "got %08x\n", hres);
1370
1371 hres = ITypeInfo_GetDocumentation(interface1, 0, &name, NULL, NULL, NULL);
1372 ok(hres == S_OK, "got %08x\n", hres);
1373 ok(!memcmp(name, func1W, sizeof(func1W)), "name = %s\n", wine_dbgstr_w(name));
1374
1375 SysFreeString(name);
1376
1377 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 3, names2, 3);
1378 ok(hres == S_OK, "got %08x\n", hres);
1379
1380 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 3, names1, 3);
1381 ok(hres == TYPE_E_AMBIGUOUSNAME, "got %08x\n", hres);
1382
1383 ICreateTypeInfo_Release(createti);
1384
1385 hres = ICreateTypeLib_CreateTypeInfo(createtl, interface1W, TKIND_INTERFACE, &createti);
1386 ok(hres == TYPE_E_NAMECONFLICT, "got %08x\n", hres);
1387
1388 hres = ICreateTypeLib_CreateTypeInfo(createtl, interface2W, TKIND_INTERFACE, &createti);
1389 ok(hres == S_OK, "got %08x\n", hres);
1390
1391 hres = ICreateTypeInfo_QueryInterface(createti, &IID_ITypeInfo, (void**)&interface2);
1392 ok(hres == S_OK, "got %08x\n", hres);
1393
1394 hres = ITypeInfo_GetRefTypeOfImplType(interface2, 0, &hreftype);
1395 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1396
1397 hres = ICreateTypeInfo_AddRefTypeInfo(createti, interface1, &hreftype);
1398 ok(hres == S_OK, "got %08x\n", hres);
1399
1400 hres = ITypeInfo_GetRefTypeInfo(interface2, 0, &ti);
1401 ok(hres == S_OK, "got %08x\n", hres);
1402 ok(ti == interface1, "Received and added interfaces are different\n");
1403
1404 ITypeInfo_Release(ti);
1405
1406 hres = ICreateTypeInfo_AddImplType(createti, 0, hreftype);
1407 ok(hres == S_OK, "got %08x\n", hres);
1408
1409 hres = ITypeInfo_GetRefTypeOfImplType(interface2, 0, &hreftype);
1410 ok(hres == S_OK, "got %08x\n", hres);
1411 ok(hreftype == 2, "hreftype = %d\n", hreftype);
1412
1413 hres = ITypeInfo_GetRefTypeOfImplType(interface2, -1, &hreftype);
1414 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1415
1416 hres = ICreateTypeInfo_SetImplTypeFlags(createti, 0, IMPLTYPEFLAG_FDEFAULT);
1417 ok(hres == TYPE_E_BADMODULEKIND, "got %08x\n", hres);
1418
1419 hres = ITypeInfo_GetImplTypeFlags(interface2, 0, &impltypeflags);
1420 ok(hres == S_OK, "got %08x\n", hres);
1421 ok(impltypeflags == 0, "impltypeflags = %x\n", impltypeflags);
1422
1423 hres = ITypeInfo_GetImplTypeFlags(interface2, 1, &impltypeflags);
1424 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1425
1426 funcdesc.oVft = 0xaaac;
1427 hres = ICreateTypeInfo_AddFuncDesc(createti, 0, &funcdesc);
1428 ok(hres == S_OK, "got %08x\n", hres);
1429 funcdesc.oVft = 0xaaa8;
1430 hres = ICreateTypeInfo_AddFuncDesc(createti, 0, &funcdesc);
1431 ok(hres == S_OK, "got %08x\n", hres);
1432 funcdesc.oVft = 0;
1433
1434 ICreateTypeInfo_Release(createti);
1435
1436 VariantInit(&cust_data);
1437
1438 hres = ICreateTypeLib_CreateTypeInfo(createtl, interface3W, TKIND_INTERFACE, &createti);
1439 ok(hres == S_OK, "got %08x\n", hres);
1440
1441 hres = ICreateTypeInfo_QueryInterface(createti, &IID_ICreateTypeInfo2, (void**)&createti2);
1442 ok(hres == S_OK, "got %08x\n", hres);
1443
1444 hres = ICreateTypeInfo2_QueryInterface(createti2, &IID_ITypeInfo2, (void**)&ti2);
1445 ok(hres == S_OK, "got %08x\n", hres);
1446
1447 hres = ITypeInfo2_GetCustData(ti2, NULL, NULL);
1448 todo_wine
1449 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1450
1451 hres = ITypeInfo2_GetCustData(ti2, &custguid, NULL);
1452 todo_wine
1453 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1454
1455 hres = ITypeInfo2_GetCustData(ti2, &custguid, &cust_data);
1456 todo_wine
1457 ok(hres == S_OK, "got %08x\n", hres);
1458
1459 hres = ICreateTypeInfo2_SetCustData(createti2, NULL, NULL);
1460 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1461
1462 hres = ICreateTypeInfo2_SetCustData(createti2, &custguid, NULL);
1463 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1464
1465 hres = ICreateTypeInfo2_SetCustData(createti2, &custguid, &cust_data);
1466 ok(hres == DISP_E_BADVARTYPE, "got %08x\n", hres);
1467
1468 V_VT(&cust_data) = VT_UI4;
1469 V_I4(&cust_data) = 0xdeadbeef;
1470
1471 hres = ICreateTypeInfo2_SetCustData(createti2, &custguid, &cust_data);
1472 ok(hres == S_OK, "got %08x\n", hres);
1473
1474 V_I4(&cust_data) = 0;
1475 V_VT(&cust_data) = VT_EMPTY;
1476
1477 hres = ITypeInfo2_GetCustData(ti2, &custguid, &cust_data);
1478 todo_wine
1479 ok(hres == S_OK, "got %08x\n", hres);
1480
1481 todo_wine
1482 ok(V_VT(&cust_data) == VT_UI4, "got %d\n", V_VT(&cust_data));
1483 todo_wine
1484 ok(V_I4(&cust_data) == 0xdeadbeef, "got 0x%08x\n", V_I4(&cust_data));
1485
1486 V_VT(&cust_data) = VT_UI4;
1487 V_I4(&cust_data) = 12345678;
1488
1489 hres = ICreateTypeInfo2_SetCustData(createti2, &custguid, &cust_data);
1490 ok(hres == S_OK, "got %08x\n", hres);
1491
1492 V_I4(&cust_data) = 0;
1493 V_VT(&cust_data) = VT_EMPTY;
1494
1495 hres = ITypeInfo2_GetCustData(ti2, &custguid, &cust_data);
1496 todo_wine
1497 ok(hres == S_OK, "got %08x\n", hres);
1498
1499 todo_wine
1500 ok(V_VT(&cust_data) == VT_UI4, "got %d\n", V_VT(&cust_data));
1501 todo_wine
1502 ok(V_I4(&cust_data) == 12345678, "got 0x%08x\n", V_I4(&cust_data));
1503
1504 ITypeInfo2_Release(ti2);
1505 ICreateTypeInfo2_Release(createti2);
1506 ICreateTypeInfo_Release(createti);
1507
1508 hres = ICreateTypeLib_CreateTypeInfo(createtl, coclassW, TKIND_COCLASS, &createti);
1509 ok(hres == S_OK, "got %08x\n", hres);
1510
1511 hres = ICreateTypeInfo_AddRefTypeInfo(createti, interface1, &hreftype);
1512 ok(hres == S_OK, "got %08x\n", hres);
1513
1514 hres = ICreateTypeInfo_AddImplType(createti, 0, hreftype);
1515 ok(hres == S_OK, "got %08x\n", hres);
1516
1517 hres = ICreateTypeInfo_AddImplType(createti, 0, hreftype);
1518 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1519
1520 hres = ICreateTypeInfo_AddRefTypeInfo(createti, unknown, &hreftype);
1521 ok(hres == S_OK, "got %08x\n", hres);
1522
1523 hres = ICreateTypeInfo_AddImplType(createti, 1, hreftype);
1524 ok(hres == S_OK, "got %08x\n", hres);
1525
1526 hres = ICreateTypeInfo_AddImplType(createti, 1, hreftype);
1527 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1528
1529 hres = ICreateTypeInfo_AddImplType(createti, 2, hreftype);
1530 ok(hres == S_OK, "got %08x\n", hres);
1531
1532 hres = ICreateTypeInfo_SetImplTypeFlags(createti, 0, IMPLTYPEFLAG_FDEFAULT);
1533 ok(hres == S_OK, "got %08x\n", hres);
1534
1535 hres = ICreateTypeInfo_SetImplTypeFlags(createti, 1, IMPLTYPEFLAG_FRESTRICTED);
1536 ok(hres == S_OK, "got %08x\n", hres);
1537
1538 hres = ICreateTypeInfo_QueryInterface(createti, &IID_ITypeInfo, (void**)&ti);
1539 ok(hres == S_OK, "got %08x\n", hres);
1540
1541 hres = ITypeInfo_GetImplTypeFlags(ti, 0, NULL);
1542 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1543
1544 hres = ITypeInfo_GetImplTypeFlags(ti, 0, &impltypeflags);
1545 ok(hres == S_OK, "got %08x\n", hres);
1546 ok(impltypeflags == IMPLTYPEFLAG_FDEFAULT, "impltypeflags = %x\n", impltypeflags);
1547
1548 hres = ITypeInfo_GetImplTypeFlags(ti, 1, &impltypeflags);
1549 ok(hres == S_OK, "got %08x\n", hres);
1550 ok(impltypeflags == IMPLTYPEFLAG_FRESTRICTED, "impltypeflags = %x\n", impltypeflags);
1551
1552 hres = ITypeInfo_GetImplTypeFlags(ti, 2, &impltypeflags);
1553 ok(hres == S_OK, "got %08x\n", hres);
1554 ok(impltypeflags == 0, "impltypeflags = %x\n", impltypeflags);
1555
1556 hres = ITypeInfo_GetRefTypeOfImplType(ti, 0, &hreftype);
1557 ok(hres == S_OK, "got %08x\n", hres);
1558 ok(hreftype == 0, "hreftype = %d\n", hreftype);
1559
1560 hres = ITypeInfo_GetRefTypeOfImplType(ti, 1, &hreftype);
1561 ok(hres == S_OK, "got %08x\n", hres);
1562 ok(hreftype == 1, "hreftype = %d\n", hreftype);
1563
1564 hres = ITypeInfo_GetRefTypeOfImplType(ti, 2, &hreftype);
1565 ok(hres == S_OK, "got %08x\n", hres);
1566 ok(hreftype == 1, "hreftype = %d\n", hreftype);
1567
1568 hres = ITypeInfo_GetRefTypeOfImplType(ti, -1, &hreftype);
1569 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1570
1571 ITypeInfo_Release(ti);
1572
1573 ICreateTypeInfo_Release(createti);
1574
1575 hres = ICreateTypeLib_CreateTypeInfo(createtl, dualW, TKIND_INTERFACE, &createti);
1576 ok(hres == S_OK, "got %08x\n", hres);
1577
1578 hres = ICreateTypeInfo_SetTypeFlags(createti, TYPEFLAG_FDUAL);
1579 ok(hres == S_OK, "got %08x\n", hres);
1580
1581 hres = ICreateTypeInfo_AddFuncDesc(createti, 0, &funcdesc);
1582 ok(hres == S_OK, "got %08x\n", hres);
1583
1584 hres = ICreateTypeInfo_AddRefTypeInfo(createti, dispatch, &hreftype);
1585 ok(hres == S_OK, "got %08x\n", hres);
1586
1587 hres = ICreateTypeInfo_AddImplType(createti, 0, hreftype);
1588 ok(hres == S_OK, "got %08x\n", hres);
1589
1590 hres = ICreateTypeInfo_QueryInterface(createti, &IID_ITypeInfo, (void**)&dual);
1591 ok(hres == S_OK, "got %08x\n", hres);
1592
1593 hres = ITypeInfo_GetTypeAttr(dual, &typeattr);
1594 ok(hres == S_OK, "got %08x\n", hres);
1595 ok(typeattr->cbSizeInstance == 4, "cbSizeInstance = %d\n", typeattr->cbSizeInstance);
1596 ok(typeattr->typekind == 3, "typekind = %d\n", typeattr->typekind);
1597 ok(typeattr->cFuncs == 1, "cFuncs = %d\n", typeattr->cFuncs);
1598 ok(typeattr->cVars == 0, "cVars = %d\n", typeattr->cVars);
1599 ok(typeattr->cImplTypes == 1, "cImplTypes = %d\n", typeattr->cImplTypes);
1600 ok(typeattr->cbSizeVft == 32 || broken(typeattr->cbSizeVft == 7 * sizeof(void *) + 4), /* xp64 */
1601 "cbSizeVft = %d\n", typeattr->cbSizeVft);
1602 ok(typeattr->cbAlignment == 4, "cbAlignment = %d\n", typeattr->cbAlignment);
1603 ok(typeattr->wTypeFlags == (TYPEFLAG_FDISPATCHABLE|TYPEFLAG_FDUAL), "wTypeFlags = %d\n", typeattr->wTypeFlags);
1604 ok(typeattr->wMajorVerNum == 0, "wMajorVerNum = %d\n", typeattr->wMajorVerNum);
1605 ok(typeattr->wMinorVerNum == 0, "wMinorVerNum = %d\n", typeattr->wMinorVerNum);
1606
1607 ITypeInfo_ReleaseTypeAttr(dual, typeattr);
1608
1609 hres = ITypeInfo_GetRefTypeOfImplType(dual, -1, &hreftype);
1610 ok(hres == S_OK, "got %08x\n", hres);
1611 ok(hreftype == -2, "got %08x\n", hreftype);
1612
1613 hres = ITypeInfo_GetRefTypeInfo(dual, -2, &ti);
1614 ok(hres == S_OK, "got %08x\n", hres);
1615
1616 hres = ITypeInfo_GetTypeAttr(ti, &typeattr);
1617 ok(hres == S_OK, "got %08x\n", hres);
1618 ok(typeattr->cbSizeInstance == 4, "cbSizeInstance = %d\n", typeattr->cbSizeInstance);
1619 ok(typeattr->typekind == 4, "typekind = %d\n", typeattr->typekind);
1620 ok(typeattr->cFuncs == 8, "cFuncs = %d\n", typeattr->cFuncs);
1621 ok(typeattr->cVars == 0, "cVars = %d\n", typeattr->cVars);
1622 ok(typeattr->cImplTypes == 1, "cImplTypes = %d\n", typeattr->cImplTypes);
1623 ok(typeattr->cbSizeVft == 7 * sizeof(void *), "cbSizeVft = %d\n", typeattr->cbSizeVft);
1624 ok(typeattr->cbAlignment == 4, "cbAlignment = %d\n", typeattr->cbAlignment);
1625 ok(typeattr->wTypeFlags == (TYPEFLAG_FDISPATCHABLE|TYPEFLAG_FDUAL), "wTypeFlags = %d\n", typeattr->wTypeFlags);
1626 ok(typeattr->wMajorVerNum == 0, "wMajorVerNum = %d\n", typeattr->wMajorVerNum);
1627 ok(typeattr->wMinorVerNum == 0, "wMinorVerNum = %d\n", typeattr->wMinorVerNum);
1628
1629 ITypeInfo_ReleaseTypeAttr(ti, typeattr);
1630
1631 ITypeInfo_Release(ti);
1632
1633 ICreateTypeInfo_Release(createti);
1634
1635 hres = ITypeInfo_GetTypeAttr(interface1, &typeattr);
1636 ok(hres == S_OK, "got %08x\n", hres);
1637 ok(typeattr->cbSizeInstance == 4, "cbSizeInstance = %d\n", typeattr->cbSizeInstance);
1638 ok(typeattr->typekind == 3, "typekind = %d\n", typeattr->typekind);
1639 ok(typeattr->cFuncs == 11, "cFuncs = %d\n", typeattr->cFuncs);
1640 ok(typeattr->cVars == 0, "cVars = %d\n", typeattr->cVars);
1641 ok(typeattr->cImplTypes == 1, "cImplTypes = %d\n", typeattr->cImplTypes);
1642 ok(typeattr->cbSizeVft == 56 || broken(typeattr->cbSizeVft == 3 * sizeof(void *) + 44), /* xp64 */
1643 "cbSizeVft = %d\n", typeattr->cbSizeVft);
1644 ok(typeattr->cbAlignment == 4, "cbAlignment = %d\n", typeattr->cbAlignment);
1645 ok(typeattr->wTypeFlags == 0, "wTypeFlags = %d\n", typeattr->wTypeFlags);
1646 ok(typeattr->wMajorVerNum == 0, "wMajorVerNum = %d\n", typeattr->wMajorVerNum);
1647 ok(typeattr->wMinorVerNum == 0, "wMinorVerNum = %d\n", typeattr->wMinorVerNum);
1648
1649 ITypeInfo_ReleaseTypeAttr(interface1, typeattr);
1650
1651 hres = ITypeInfo_GetTypeAttr(interface2, &typeattr);
1652 ok(hres == S_OK, "got %08x\n", hres);
1653 ok(typeattr->cbSizeInstance == 4, "cbSizeInstance = %d\n", typeattr->cbSizeInstance);
1654 ok(typeattr->typekind == 3, "typekind = %d\n", typeattr->typekind);
1655 ok(typeattr->cFuncs == 2, "cFuncs = %d\n", typeattr->cFuncs);
1656 ok(typeattr->cVars == 0, "cVars = %d\n", typeattr->cVars);
1657 ok(typeattr->cImplTypes == 1, "cImplTypes = %d\n", typeattr->cImplTypes);
1658 ok(typeattr->cbSizeVft == 43696, "cbSizeVft = %d\n", typeattr->cbSizeVft);
1659 ok(typeattr->cbAlignment == 4, "cbAlignment = %d\n", typeattr->cbAlignment);
1660 ok(typeattr->wTypeFlags == 0, "wTypeFlags = %d\n", typeattr->wTypeFlags);
1661 ok(typeattr->wMajorVerNum == 0, "wMajorVerNum = %d\n", typeattr->wMajorVerNum);
1662 ok(typeattr->wMinorVerNum == 0, "wMinorVerNum = %d\n", typeattr->wMinorVerNum);
1663
1664 ITypeInfo_ReleaseTypeAttr(interface2, typeattr);
1665
1666 hres = ICreateTypeLib2_SaveAllChanges(createtl);
1667 ok(hres == S_OK, "got %08x\n", hres);
1668
1669 ok(ITypeInfo_Release(interface2)==0, "Object should be freed\n");
1670 ok(ITypeInfo_Release(interface1)==0, "Object should be freed\n");
1671 ok(ITypeInfo_Release(dual)==0, "Object should be freed\n");
1672 ok(ICreateTypeLib2_Release(createtl)==0, "Object should be freed\n");
1673
1674 ok(ITypeInfo_Release(dispatch)==0, "Object should be freed\n");
1675 ok(ITypeInfo_Release(unknown)==0, "Object should be freed\n");
1676 ok(ITypeLib_Release(stdole)==0, "Object should be freed\n");
1677
1678 hres = LoadTypeLibEx(filenameW, REGKIND_NONE, &tl);
1679 ok(hres == S_OK, "got %08x\n", hres);
1680 ok(ITypeLib_Release(tl)==0, "Object should be freed\n");
1681
1682 DeleteFileA(filename);
1683 }
1684
1685 #if 0 /* use this to generate more tests */
1686
1687 #define OLE_CHECK(x) { HRESULT hr = x; if (FAILED(hr)) { printf(#x "failed - %x\n", hr); return; } }
1688
1689 static char *dump_string(LPWSTR wstr)
1690 {
1691 int size = lstrlenW(wstr)+3;
1692 char *out = CoTaskMemAlloc(size);
1693 WideCharToMultiByte(20127, 0, wstr, -1, out+1, size, NULL, NULL);
1694 out[0] = '\"';
1695 strcat(out, "\"");
1696 return out;
1697 }
1698
1699 struct map_entry
1700 {
1701 DWORD value;
1702 const char *name;
1703 };
1704
1705 #define MAP_ENTRY(x) { x, #x }
1706 static const struct map_entry tkind_map[] = {
1707 MAP_ENTRY(TKIND_ENUM),
1708 MAP_ENTRY(TKIND_RECORD),
1709 MAP_ENTRY(TKIND_MODULE),
1710 MAP_ENTRY(TKIND_INTERFACE),
1711 MAP_ENTRY(TKIND_DISPATCH),
1712 MAP_ENTRY(TKIND_COCLASS),
1713 MAP_ENTRY(TKIND_ALIAS),
1714 MAP_ENTRY(TKIND_UNION),
1715 MAP_ENTRY(TKIND_MAX),
1716 {0, NULL}
1717 };
1718
1719 static const struct map_entry funckind_map[] = {
1720 MAP_ENTRY(FUNC_VIRTUAL),
1721 MAP_ENTRY(FUNC_PUREVIRTUAL),
1722 MAP_ENTRY(FUNC_NONVIRTUAL),
1723 MAP_ENTRY(FUNC_STATIC),
1724 MAP_ENTRY(FUNC_DISPATCH),
1725 {0, NULL}
1726 };
1727
1728 static const struct map_entry invkind_map[] = {
1729 MAP_ENTRY(INVOKE_FUNC),
1730 MAP_ENTRY(INVOKE_PROPERTYGET),
1731 MAP_ENTRY(INVOKE_PROPERTYPUT),
1732 MAP_ENTRY(INVOKE_PROPERTYPUTREF),
1733 {0, NULL}
1734 };
1735
1736 #undef MAP_ENTRY
1737
1738 static const char *map_value(DWORD val, const struct map_entry *map)
1739 {
1740 static int map_id;
1741 static char bufs[16][256];
1742 char *buf;
1743
1744 while (map->name)
1745 {
1746 if (map->value == val)
1747 return map->name;
1748 map++;
1749 }
1750
1751 buf = bufs[(map_id++)%16];
1752 sprintf(buf, "0x%x", val);
1753 return buf;
1754 }
1755
1756 static void test_dump_typelib(const char *name)
1757 {
1758 WCHAR wszString[260];
1759 ITypeInfo *info;
1760 ITypeLib *lib;
1761 int count;
1762 int i;
1763
1764 MultiByteToWideChar(CP_ACP, 0, name, -1, wszString, 260);
1765 OLE_CHECK(LoadTypeLib(wszString, &lib));
1766 count = ITypeLib_GetTypeInfoCount(lib);
1767 printf("/* interfaces count: %d */\n", count);
1768 for (i = 0; i < count; i++)
1769 {
1770 TYPEATTR *attr;
1771 BSTR name;
1772 int f = 0;
1773
1774 OLE_CHECK(ITypeLib_GetDocumentation(lib, i, &name, NULL, NULL, NULL));
1775 printf("{\n"
1776 " %s,\n", dump_string(name));
1777 SysFreeString(name);
1778
1779 OLE_CHECK(ITypeLib_GetTypeInfo(lib, i, &info));
1780 ITypeInfo_GetTypeAttr(info, &attr);
1781 printf(" /*kind*/ %s, /*flags*/ 0x%x, /*align*/ %d, /*size*/ %d,\n"
1782 " /*#vtbl*/ %d, /*#func*/ %d,\n"
1783 " {\n",
1784 map_value(attr->typekind, tkind_map), attr->wTypeFlags, attr->cbAlignment, attr->cbSizeInstance, attr->cbSizeVft,
1785 attr->cFuncs);
1786 ITypeInfo_ReleaseTypeAttr(info, attr);
1787 while (1)
1788 {
1789 FUNCDESC *desc;
1790 BSTR tab[256];
1791 UINT cNames;
1792 int p;
1793
1794 if (FAILED(ITypeInfo_GetFuncDesc(info, f, &desc)))
1795 break;
1796 printf(" {\n"
1797 " 0x%x, /*func*/ %s, /*inv*/ %s, /*call*/ 0x%x,\n",
1798 desc->memid, map_value(desc->funckind, funckind_map), map_value(desc->invkind, invkind_map),
1799 desc->callconv);
1800 printf(" /*#param*/ %d, /*#opt*/ %d, /*vtbl*/ %d, /*#scodes*/ %d, /*flags*/ 0x%x,\n",
1801 desc->cParams, desc->cParamsOpt, desc->oVft, desc->cScodes, desc->wFuncFlags);
1802 printf(" {%d, %x}, /* ret */\n", desc->elemdescFunc.tdesc.vt, desc->elemdescFunc.paramdesc.wParamFlags);
1803 printf(" { /* params */\n");
1804 for (p = 0; p < desc->cParams; p++)
1805 {
1806 ELEMDESC e = desc->lprgelemdescParam[p];
1807 printf(" {%d, %x},\n", e.tdesc.vt, e.paramdesc.wParamFlags);
1808 }
1809 printf(" {-1, -1}\n");
1810 printf(" },\n");
1811 printf(" { /* names */\n");
1812 OLE_CHECK(ITypeInfo_GetNames(info, desc->memid, tab, 256, &cNames));
1813 for (p = 0; p < cNames; p++)
1814 {
1815 printf(" %s,\n", dump_string(tab[p]));
1816 SysFreeString(tab[p]);
1817 }
1818 printf(" NULL,\n");
1819 printf(" },\n");
1820 printf(" },\n");
1821 ITypeInfo_ReleaseFuncDesc(info, desc);
1822 f++;
1823 }
1824 printf(" }\n");
1825 printf("},\n");
1826 ITypeInfo_Release(info);
1827 }
1828 ITypeLib_Release(lib);
1829 }
1830
1831 #else
1832
1833 typedef struct _element_info
1834 {
1835 VARTYPE vt;
1836 USHORT wParamFlags;
1837 } element_info;
1838
1839 typedef struct _function_info
1840 {
1841 MEMBERID memid;
1842 FUNCKIND funckind;
1843 INVOKEKIND invkind;
1844 CALLCONV callconv;
1845 short cParams;
1846 short cParamsOpt;
1847 short vtbl_index;
1848 short cScodes;
1849 WORD wFuncFlags;
1850 element_info ret_type;
1851 element_info params[15];
1852 LPCSTR names[15];
1853 } function_info;
1854
1855 typedef struct _interface_info
1856 {
1857 LPCSTR name;
1858 TYPEKIND type;
1859 WORD wTypeFlags;
1860 USHORT cbAlignment;
1861 USHORT cbSizeInstance;
1862 USHORT cbSizeVft;
1863 USHORT cFuncs;
1864 function_info funcs[20];
1865 } interface_info;
1866
1867 static const interface_info info[] = {
1868 /* interfaces count: 2 */
1869 {
1870 "IDualIface",
1871 /*kind*/ TKIND_DISPATCH, /*flags*/ 0x1040, /*align*/ 4, /*size*/ 4,
1872 /*#vtbl*/ 7, /*#func*/ 8,
1873 {
1874 {
1875 0x60000000, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1876 /*#param*/ 2, /*#opt*/ 0, /*vtbl*/ 0, /*#scodes*/ 0, /*flags*/ 0x1,
1877 {24, 0}, /* ret */
1878 { /* params */
1879 {26, 1},
1880 {26, 2},
1881 {-1, -1}
1882 },
1883 { /* names */
1884 "QueryInterface",
1885 "riid",
1886 "ppvObj",
1887 NULL,
1888 },
1889 },
1890 {
1891 0x60000001, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1892 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 1, /*#scodes*/ 0, /*flags*/ 0x1,
1893 {19, 0}, /* ret */
1894 { /* params */
1895 {-1, -1}
1896 },
1897 { /* names */
1898 "AddRef",
1899 NULL,
1900 },
1901 },
1902 {
1903 0x60000002, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1904 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 2, /*#scodes*/ 0, /*flags*/ 0x1,
1905 {19, 0}, /* ret */
1906 { /* params */
1907 {-1, -1}
1908 },
1909 { /* names */
1910 "Release",
1911 NULL,
1912 },
1913 },
1914 {
1915 0x60010000, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1916 /*#param*/ 1, /*#opt*/ 0, /*vtbl*/ 3, /*#scodes*/ 0, /*flags*/ 0x1,
1917 {24, 0}, /* ret */
1918 { /* params */
1919 {26, 2},
1920 {-1, -1}
1921 },
1922 { /* names */
1923 "GetTypeInfoCount",
1924 "pctinfo",
1925 NULL,
1926 },
1927 },
1928 {
1929 0x60010001, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1930 /*#param*/ 3, /*#opt*/ 0, /*vtbl*/ 4, /*#scodes*/ 0, /*flags*/ 0x1,
1931 {24, 0}, /* ret */
1932 { /* params */
1933 {23, 1},
1934 {19, 1},
1935 {26, 2},
1936 {-1, -1}
1937 },
1938 { /* names */
1939 "GetTypeInfo",
1940 "itinfo",
1941 "lcid",
1942 "pptinfo",
1943 NULL,
1944 },
1945 },
1946 {
1947 0x60010002, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1948 /*#param*/ 5, /*#opt*/ 0, /*vtbl*/ 5, /*#scodes*/ 0, /*flags*/ 0x1,
1949 {24, 0}, /* ret */
1950 { /* params */
1951 {26, 1},
1952 {26, 1},
1953 {23, 1},
1954 {19, 1},
1955 {26, 2},
1956 {-1, -1}
1957 },
1958 { /* names */
1959 "GetIDsOfNames",
1960 "riid",
1961 "rgszNames",
1962 "cNames",
1963 "lcid",
1964 "rgdispid",
1965 NULL,
1966 },
1967 },
1968 {
1969 0x60010003, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1970 /*#param*/ 8, /*#opt*/ 0, /*vtbl*/ 6, /*#scodes*/ 0, /*flags*/ 0x1,
1971 {24, 0}, /* ret */
1972 { /* params */
1973 {3, 1},
1974 {26, 1},
1975 {19, 1},
1976 {18, 1},
1977 {26, 1},
1978 {26, 2},
1979 {26, 2},
1980 {26, 2},
1981 {-1, -1}
1982 },
1983 { /* names */
1984 "Invoke",
1985 "dispidMember",
1986 "riid",
1987 "lcid",
1988 "wFlags",
1989 "pdispparams",
1990 "pvarResult",
1991 "pexcepinfo",
1992 "puArgErr",
1993 NULL,
1994 },
1995 },
1996 {
1997 0x60020000, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
1998 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 7, /*#scodes*/ 0, /*flags*/ 0x0,
1999 {24, 0}, /* ret */
2000 { /* params */
2001 {-1, -1}
2002 },
2003 { /* names */
2004 "Test",
2005 NULL,
2006 },
2007 },
2008 }
2009 },
2010 {
2011 "ISimpleIface",
2012 /*kind*/ TKIND_INTERFACE, /*flags*/ 0x1000, /*align*/ 4, /*size*/ 4,
2013 /*#vtbl*/ 8, /*#func*/ 1,
2014 {
2015 {
2016 0x60020000, /*func*/ FUNC_PUREVIRTUAL, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
2017 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 7, /*#scodes*/ 0, /*flags*/ 0x0,
2018 {25, 0}, /* ret */
2019 { /* params */
2020 {-1, -1}
2021 },
2022 { /* names */
2023 "Test",
2024 NULL,
2025 },
2026 },
2027 }
2028 },
2029 };
2030
2031 #define check_type(elem, info) { \
2032 expect_int((elem)->tdesc.vt, (info)->vt); \
2033 expect_hex(U(*(elem)).paramdesc.wParamFlags, (info)->wParamFlags); \
2034 }
2035
2036 static void test_dump_typelib(const char *name)
2037 {
2038 WCHAR wszName[MAX_PATH];
2039 ITypeLib *typelib;
2040 int ifcount = sizeof(info)/sizeof(info[0]);
2041 int iface, func;
2042
2043 MultiByteToWideChar(CP_ACP, 0, name, -1, wszName, MAX_PATH);
2044 ole_check(LoadTypeLibEx(wszName, REGKIND_NONE, &typelib));
2045 expect_eq(ITypeLib_GetTypeInfoCount(typelib), ifcount, UINT, "%d");
2046 for (iface = 0; iface < ifcount; iface++)
2047 {
2048 const interface_info *if_info = &info[iface];
2049 ITypeInfo *typeinfo;
2050 TYPEATTR *typeattr;
2051 BSTR bstrIfName;
2052
2053 trace("Interface %s\n", if_info->name);
2054 ole_check(ITypeLib_GetTypeInfo(typelib, iface, &typeinfo));
2055 ole_check(ITypeLib_GetDocumentation(typelib, iface, &bstrIfName, NULL, NULL, NULL));
2056 expect_wstr_acpval(bstrIfName, if_info->name);
2057 SysFreeString(bstrIfName);
2058
2059 ole_check(ITypeInfo_GetTypeAttr(typeinfo, &typeattr));
2060 expect_int(typeattr->typekind, if_info->type);
2061 expect_hex(typeattr->wTypeFlags, if_info->wTypeFlags);
2062 expect_int(typeattr->cbAlignment, if_info->cbAlignment);
2063 expect_int(typeattr->cbSizeInstance, if_info->cbSizeInstance);
2064 expect_int(typeattr->cbSizeVft, if_info->cbSizeVft * sizeof(void*));
2065 expect_int(typeattr->cFuncs, if_info->cFuncs);
2066
2067 for (func = 0; func < typeattr->cFuncs; func++)
2068 {
2069 function_info *fn_info = (function_info *)&if_info->funcs[func];
2070 FUNCDESC *desc;
2071 BSTR namesTab[256];
2072 UINT cNames;
2073 int i;
2074
2075 trace("Function %s\n", fn_info->names[0]);
2076 ole_check(ITypeInfo_GetFuncDesc(typeinfo, func, &desc));
2077 expect_int(desc->memid, fn_info->memid);
2078 expect_int(desc->funckind, fn_info->funckind);
2079 expect_int(desc->invkind, fn_info->invkind);
2080 expect_int(desc->callconv, fn_info->callconv);
2081 expect_int(desc->cParams, fn_info->cParams);
2082 expect_int(desc->cParamsOpt, fn_info->cParamsOpt);
2083 ok( desc->oVft == fn_info->vtbl_index * sizeof(void*) ||
2084 broken(desc->oVft == fn_info->vtbl_index * 4), /* xp64 */
2085 "desc->oVft got %u\n", desc->oVft );
2086 expect_int(desc->cScodes, fn_info->cScodes);
2087 expect_int(desc->wFuncFlags, fn_info->wFuncFlags);
2088 ole_check(ITypeInfo_GetNames(typeinfo, desc->memid, namesTab, 256, &cNames));
2089 for (i = 0; i < cNames; i++)
2090 {
2091 expect_wstr_acpval(namesTab[i], fn_info->names[i]);
2092 SysFreeString(namesTab[i]);
2093 }
2094 expect_null(fn_info->names[cNames]);
2095
2096 check_type(&desc->elemdescFunc, &fn_info->ret_type);
2097 for (i = 0 ; i < desc->cParams; i++)
2098 {
2099 check_type(&desc->lprgelemdescParam[i], &fn_info->params[i]);
2100 }
2101 expect_int(fn_info->params[desc->cParams].vt, (VARTYPE)-1);
2102
2103 ITypeInfo_ReleaseFuncDesc(typeinfo, desc);
2104 }
2105
2106 ITypeInfo_ReleaseTypeAttr(typeinfo, typeattr);
2107 ITypeInfo_Release(typeinfo);
2108 }
2109 ITypeLib_Release(typelib);
2110 }
2111
2112 #endif
2113
2114 static const char *create_test_typelib(int res_no)
2115 {
2116 static char filename[MAX_PATH];
2117 HANDLE file;
2118 HRSRC res;
2119 void *ptr;
2120 DWORD written;
2121
2122 GetTempFileNameA( ".", "tlb", 0, filename );
2123 file = CreateFile( filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
2124 ok( file != INVALID_HANDLE_VALUE, "file creation failed\n" );
2125 if (file == INVALID_HANDLE_VALUE) return NULL;
2126 res = FindResource( GetModuleHandle(0), MAKEINTRESOURCE(res_no), "TYPELIB" );
2127 ok( res != 0, "couldn't find resource\n" );
2128 ptr = LockResource( LoadResource( GetModuleHandle(0), res ));
2129 WriteFile( file, ptr, SizeofResource( GetModuleHandle(0), res ), &written, NULL );
2130 ok( written == SizeofResource( GetModuleHandle(0), res ), "couldn't write resource\n" );
2131 CloseHandle( file );
2132 return filename;
2133 }
2134
2135 static void test_create_typelib_lcid(LCID lcid)
2136 {
2137 char filename[MAX_PATH];
2138 WCHAR name[MAX_PATH];
2139 HRESULT hr;
2140 ICreateTypeLib2 *tl;
2141 HANDLE file;
2142 DWORD msft_header[5]; /* five is enough for now */
2143 DWORD read;
2144
2145 GetTempFileNameA( ".", "tlb", 0, filename );
2146 MultiByteToWideChar(CP_ACP, 0, filename, -1, name, MAX_PATH);
2147
2148 hr = CreateTypeLib2(SYS_WIN32, name, &tl);
2149 ok(hr == S_OK, "got %08x\n", hr);
2150
2151 hr = ICreateTypeLib2_SetLcid(tl, lcid);
2152 ok(hr == S_OK, "got %08x\n", hr);
2153
2154 hr = ICreateTypeLib2_SaveAllChanges(tl);
2155 ICreateTypeLib2_Release(tl);
2156
2157 file = CreateFileA( filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0 );
2158 ok( file != INVALID_HANDLE_VALUE, "file creation failed\n" );
2159
2160 ReadFile( file, msft_header, sizeof(msft_header), &read, NULL );
2161 ok(read == sizeof(msft_header), "read %d\n", read);
2162 CloseHandle( file );
2163
2164 ok(msft_header[0] == 0x5446534d, "got %08x\n", msft_header[0]);
2165 ok(msft_header[1] == 0x00010002, "got %08x\n", msft_header[1]);
2166 ok(msft_header[2] == 0xffffffff, "got %08x\n", msft_header[2]);
2167 ok(msft_header[3] == (lcid ? lcid : 0x409), "got %08x (lcid %08x)\n", msft_header[3], lcid);
2168 ok(msft_header[4] == lcid, "got %08x (lcid %08x)\n", msft_header[4], lcid);
2169
2170 DeleteFileA(filename);
2171 }
2172
2173 static void test_create_typelibs(void)
2174 {
2175 test_create_typelib_lcid(LOCALE_SYSTEM_DEFAULT);
2176 test_create_typelib_lcid(LOCALE_USER_DEFAULT);
2177 test_create_typelib_lcid(LOCALE_NEUTRAL);
2178
2179 test_create_typelib_lcid(0x009);
2180 test_create_typelib_lcid(0x409);
2181 test_create_typelib_lcid(0x809);
2182
2183 test_create_typelib_lcid(0x007);
2184 test_create_typelib_lcid(0x407);
2185 }
2186
2187
2188 static void test_register_typelib(BOOL system_registration)
2189 {
2190 HRESULT hr;
2191 WCHAR filename[MAX_PATH];
2192 const char *filenameA;
2193 ITypeLib *typelib;
2194 WCHAR uuidW[40];
2195 char key_name[MAX_PATH], uuid[40];
2196 LONG ret, expect_ret;
2197 UINT count, i;
2198 HKEY hkey;
2199 struct
2200 {
2201 TYPEKIND kind;
2202 WORD flags;
2203 } attrs[11] =
2204 {
2205 { TKIND_INTERFACE, 0 },
2206 { TKIND_INTERFACE, TYPEFLAG_FDISPATCHABLE },
2207 { TKIND_INTERFACE, TYPEFLAG_FOLEAUTOMATION },
2208 { TKIND_INTERFACE, TYPEFLAG_FDISPATCHABLE | TYPEFLAG_FOLEAUTOMATION },
2209 { TKIND_DISPATCH, 0 /* TYPEFLAG_FDUAL - widl clears this flag for non-IDispatch derived interfaces */ },
2210 { TKIND_DISPATCH, 0 /* TYPEFLAG_FDUAL - widl clears this flag for non-IDispatch derived interfaces */ },
2211 { TKIND_DISPATCH, TYPEFLAG_FDISPATCHABLE | TYPEFLAG_FDUAL },
2212 { TKIND_DISPATCH, TYPEFLAG_FDISPATCHABLE | TYPEFLAG_FDUAL },
2213 { TKIND_DISPATCH, TYPEFLAG_FDISPATCHABLE },
2214 { TKIND_DISPATCH, TYPEFLAG_FDISPATCHABLE },
2215 { TKIND_DISPATCH, TYPEFLAG_FDISPATCHABLE }
2216 };
2217
2218 trace("Starting %s typelib registration tests\n",
2219 system_registration ? "system" : "user");
2220
2221 if (!system_registration && (!pRegisterTypeLibForUser || !pUnRegisterTypeLibForUser))
2222 {
2223 win_skip("User typelib registration functions are not available\n");
2224 return;
2225 }
2226
2227 filenameA = create_test_typelib(3);
2228 MultiByteToWideChar(CP_ACP, 0, filenameA, -1, filename, MAX_PATH);
2229
2230 hr = LoadTypeLibEx(filename, REGKIND_NONE, &typelib);
2231 ok(SUCCEEDED(hr), "got %08x\n", hr);
2232
2233 if (system_registration)
2234 hr = RegisterTypeLib(typelib, filename, NULL);
2235 else
2236 hr = pRegisterTypeLibForUser(typelib, filename, NULL);
2237 if (hr == TYPE_E_REGISTRYACCESS)
2238 {
2239 win_skip("Insufficient privileges to register typelib in the registry\n");
2240 ITypeLib_Release(typelib);
2241 DeleteFileA(filenameA);
2242 return;
2243 }
2244 ok(SUCCEEDED(hr), "got %08x\n", hr);
2245
2246 count = ITypeLib_GetTypeInfoCount(typelib);
2247 ok(count == 11, "got %d\n", count);
2248
2249 for(i = 0; i < count; i++)
2250 {
2251 ITypeInfo *typeinfo;
2252 TYPEATTR *attr;
2253
2254 hr = ITypeLib_GetTypeInfo(typelib, i, &typeinfo);
2255 ok(SUCCEEDED(hr), "got %08x\n", hr);
2256
2257 hr = ITypeInfo_GetTypeAttr(typeinfo, &attr);
2258 ok(SUCCEEDED(hr), "got %08x\n", hr);
2259
2260 ok(attr->typekind == attrs[i].kind, "%d: got kind %d\n", i, attr->typekind);
2261 ok(attr->wTypeFlags == attrs[i].flags, "%d: got flags %04x\n", i, attr->wTypeFlags);
2262
2263 if(attr->typekind == TKIND_DISPATCH && (attr->wTypeFlags & TYPEFLAG_FDUAL))
2264 {
2265 HREFTYPE reftype;
2266 ITypeInfo *dual_info;
2267 TYPEATTR *dual_attr;
2268
2269 hr = ITypeInfo_GetRefTypeOfImplType(typeinfo, -1, &reftype);
2270 ok(SUCCEEDED(hr), "got %08x\n", hr);
2271
2272 hr = ITypeInfo_GetRefTypeInfo(typeinfo, reftype, &dual_info);
2273 ok(SUCCEEDED(hr), "got %08x\n", hr);
2274
2275 hr = ITypeInfo_GetTypeAttr(dual_info, &dual_attr);
2276 ok(SUCCEEDED(hr), "got %08x\n", hr);
2277
2278 ok(dual_attr->typekind == TKIND_INTERFACE, "%d: got kind %d\n", i, dual_attr->typekind);
2279 ok(dual_attr->wTypeFlags == (TYPEFLAG_FDISPATCHABLE | TYPEFLAG_FOLEAUTOMATION | TYPEFLAG_FDUAL), "%d: got flags %04x\n", i, dual_attr->wTypeFlags);
2280
2281 ITypeInfo_ReleaseTypeAttr(dual_info, dual_attr);
2282 ITypeInfo_Release(dual_info);
2283
2284 }
2285
2286 StringFromGUID2(&attr->guid, uuidW, sizeof(uuidW) / sizeof(uuidW[0]));
2287 WideCharToMultiByte(CP_ACP, 0, uuidW, -1, uuid, sizeof(uuid), NULL, NULL);
2288 sprintf(key_name, "Interface\\%s", uuid);
2289
2290 /* All dispinterfaces will be registered (this includes dual interfaces) as well
2291 as oleautomation interfaces */
2292 if((attr->typekind == TKIND_INTERFACE && (attr->wTypeFlags & TYPEFLAG_FOLEAUTOMATION)) ||
2293 attr->typekind == TKIND_DISPATCH)
2294 expect_ret = ERROR_SUCCESS;
2295 else
2296 expect_ret = ERROR_FILE_NOT_FOUND;
2297
2298 ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, key_name, 0, KEY_READ, &hkey);
2299 ok(ret == expect_ret, "%d: got %d\n", i, ret);
2300 if(ret == ERROR_SUCCESS) RegCloseKey(hkey);
2301
2302 ITypeInfo_ReleaseTypeAttr(typeinfo, attr);
2303 ITypeInfo_Release(typeinfo);
2304 }
2305
2306 if (system_registration)
2307 hr = UnRegisterTypeLib(&LIBID_register_test, 1, 0, LOCALE_NEUTRAL, sizeof(void*) == 8 ? SYS_WIN64 : SYS_WIN32);
2308 else
2309 hr = pUnRegisterTypeLibForUser(&LIBID_register_test, 1, 0, LOCALE_NEUTRAL, sizeof(void*) == 8 ? SYS_WIN64 : SYS_WIN32);
2310 ok(SUCCEEDED(hr), "got %08x\n", hr);
2311
2312 ITypeLib_Release(typelib);
2313 DeleteFileA( filenameA );
2314 }
2315
2316 START_TEST(typelib)
2317 {
2318 const char *filename;
2319
2320 init_function_pointers();
2321
2322 ref_count_test(wszStdOle2);
2323 test_TypeComp();
2324 test_CreateDispTypeInfo();
2325 test_TypeInfo();
2326 test_QueryPathOfRegTypeLib();
2327 test_inheritance();
2328 test_CreateTypeLib();
2329
2330 if ((filename = create_test_typelib(2)))
2331 {
2332 test_dump_typelib( filename );
2333 DeleteFile( filename );
2334 }
2335
2336 test_register_typelib(TRUE);
2337 test_register_typelib(FALSE);
2338 test_create_typelibs();
2339
2340 }