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