Release 1.6-rc2.
[wine/testsucceed.git] / dlls / oleaut32 / tests / typelib.c
blob1919ea8df41fd3ad5df9c9f2962ea450b5ebd16d
1 /*
2 * ITypeLib and ITypeInfo test
4 * Copyright 2004 Jacek Caban
5 * Copyright 2006 Dmitry Timoshkov
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.
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.
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
22 #define COBJMACROS
23 #define CONST_VTABLE
25 #include <wine/test.h>
26 #include <stdarg.h>
27 #include <stdio.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "oleauto.h"
32 #include "ocidl.h"
33 #include "shlwapi.h"
34 #include "tmarshal.h"
36 #include "test_reg.h"
38 #define expect_eq(expr, value, type, format) { type _ret = (expr); ok((value) == _ret, #expr " expected " format " got " format "\n", value, _ret); }
39 #define expect_int(expr, value) expect_eq(expr, (int)(value), int, "%d")
40 #define expect_hex(expr, value) expect_eq(expr, (int)(value), int, "0x%x")
41 #define expect_null(expr) expect_eq(expr, NULL, const void *, "%p")
43 #define expect_wstr_acpval(expr, value) \
44 { \
45 CHAR buf[260]; \
46 expect_eq(!WideCharToMultiByte(CP_ACP, 0, (expr), -1, buf, 260, NULL, NULL), 0, int, "%d"); \
47 ok(lstrcmp(value, buf) == 0, #expr " expected \"%s\" got \"%s\"\n", value, buf); \
50 #define ole_expect(expr, expect) { \
51 HRESULT r = expr; \
52 ok(r == (expect), #expr " returned %x, expected %s (%x)\n", r, #expect, expect); \
55 #define ole_check(expr) ole_expect(expr, S_OK);
57 #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%08x\n", hr)
59 static HRESULT WINAPI (*pRegisterTypeLibForUser)(ITypeLib*,OLECHAR*,OLECHAR*);
60 static HRESULT WINAPI (*pUnRegisterTypeLibForUser)(REFGUID,WORD,WORD,LCID,SYSKIND);
62 static const WCHAR wszStdOle2[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
63 static WCHAR wszGUID[] = {'G','U','I','D',0};
64 static WCHAR wszguid[] = {'g','u','i','d',0};
66 static const int is_win64 = sizeof(void *) > sizeof(int);
68 static HRESULT WINAPI invoketest_QueryInterface(IInvokeTest *iface, REFIID riid, void **ret)
70 if (IsEqualIID(riid, &IID_IUnknown) ||
71 IsEqualIID(riid, &IID_IDispatch) ||
72 IsEqualIID(riid, &IID_IInvokeTest))
74 *ret = iface;
75 return S_OK;
78 return E_NOINTERFACE;
81 static ULONG WINAPI invoketest_AddRef(IInvokeTest *iface)
83 return 2;
86 static ULONG WINAPI invoketest_Release(IInvokeTest *iface)
88 return 1;
91 static HRESULT WINAPI invoketest_GetTypeInfoCount(IInvokeTest *iface, UINT *cnt)
93 ok(0, "unexpected call\n");
94 *cnt = 0;
95 return E_NOTIMPL;
98 static HRESULT WINAPI invoketest_GetTypeInfo(IInvokeTest *iface, UINT index, LCID lcid, ITypeInfo **ti)
100 ok(0, "unexpected call\n");
101 return E_NOTIMPL;
104 static HRESULT WINAPI invoketest_GetIDsOfNames(IInvokeTest *iface, REFIID riid, LPOLESTR *names,
105 UINT cnt, LCID lcid, DISPID *dispid)
107 ok(0, "unexpected call\n");
108 return E_NOTIMPL;
111 static HRESULT WINAPI invoketest_Invoke(IInvokeTest *iface, DISPID dispid, REFIID riid,
112 LCID lcid, WORD flags, DISPPARAMS *dispparams, VARIANT *res, EXCEPINFO *ei, UINT *argerr)
114 ok(0, "unexpected call\n");
115 return E_NOTIMPL;
118 static LONG WINAPI invoketest_get_test(IInvokeTest *iface, LONG i)
120 return i+1;
123 static const IInvokeTestVtbl invoketestvtbl = {
124 invoketest_QueryInterface,
125 invoketest_AddRef,
126 invoketest_Release,
127 invoketest_GetTypeInfoCount,
128 invoketest_GetTypeInfo,
129 invoketest_GetIDsOfNames,
130 invoketest_Invoke,
131 invoketest_get_test
134 static IInvokeTest invoketest = { &invoketestvtbl };
136 static void init_function_pointers(void)
138 HMODULE hmod = GetModuleHandleA("oleaut32.dll");
140 pRegisterTypeLibForUser = (void *)GetProcAddress(hmod, "RegisterTypeLibForUser");
141 pUnRegisterTypeLibForUser = (void *)GetProcAddress(hmod, "UnRegisterTypeLibForUser");
144 static void ref_count_test(LPCWSTR type_lib)
146 ITypeLib *iface;
147 ITypeInfo *iti1, *iti2;
148 HRESULT hRes;
149 int ref_count;
151 trace("Loading type library\n");
152 hRes = LoadTypeLib(type_lib, &iface);
153 ok(hRes == S_OK, "Could not load type library\n");
154 if(hRes != S_OK)
155 return;
157 hRes = ITypeLib_GetTypeInfo(iface, 1, &iti1);
158 ok(hRes == S_OK, "ITypeLib_GetTypeInfo failed on index = 1\n");
159 ok(ref_count=ITypeLib_Release(iface) > 0, "ITypeLib destroyed while ITypeInfo has back pointer\n");
160 if(!ref_count)
161 return;
163 hRes = ITypeLib_GetTypeInfo(iface, 1, &iti2);
164 ok(hRes == S_OK, "ITypeLib_GetTypeInfo failed on index = 1\n");
165 ok(iti1 == iti2, "ITypeLib_GetTypeInfo returned different pointers for same indexes\n");
167 ITypeLib_AddRef(iface);
168 ITypeInfo_Release(iti2);
169 ITypeInfo_Release(iti1);
170 ok(ITypeLib_Release(iface) == 0, "ITypeLib should be destroyed here.\n");
173 static void test_TypeComp(void)
175 ITypeLib *pTypeLib;
176 ITypeComp *pTypeComp;
177 HRESULT hr;
178 ULONG ulHash;
179 DESCKIND desckind;
180 BINDPTR bindptr;
181 ITypeInfo *pTypeInfo;
182 ITypeInfo *pFontTypeInfo;
183 ITypeComp *pTypeComp_tmp;
184 static WCHAR wszStdFunctions[] = {'S','t','d','F','u','n','c','t','i','o','n','s',0};
185 static WCHAR wszSavePicture[] = {'S','a','v','e','P','i','c','t','u','r','e',0};
186 static WCHAR wszOLE_TRISTATE[] = {'O','L','E','_','T','R','I','S','T','A','T','E',0};
187 static WCHAR wszUnchecked[] = {'U','n','c','h','e','c','k','e','d',0};
188 static WCHAR wszIUnknown[] = {'I','U','n','k','n','o','w','n',0};
189 static WCHAR wszFont[] = {'F','o','n','t',0};
190 static WCHAR wszStdPicture[] = {'S','t','d','P','i','c','t','u','r','e',0};
191 static WCHAR wszOLE_COLOR[] = {'O','L','E','_','C','O','L','O','R',0};
192 static WCHAR wszClone[] = {'C','l','o','n','e',0};
193 static WCHAR wszclone[] = {'c','l','o','n','e',0};
194 static WCHAR wszJunk[] = {'J','u','n','k',0};
195 static WCHAR wszAddRef[] = {'A','d','d','R','e','f',0};
197 hr = LoadTypeLib(wszStdOle2, &pTypeLib);
198 ok_ole_success(hr, LoadTypeLib);
200 hr = ITypeLib_GetTypeComp(pTypeLib, &pTypeComp);
201 ok_ole_success(hr, ITypeLib_GetTypeComp);
203 /* test getting a TKIND_MODULE */
204 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdFunctions);
205 hr = ITypeComp_Bind(pTypeComp, wszStdFunctions, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
206 ok_ole_success(hr, ITypeComp_Bind);
208 ok(desckind == DESCKIND_TYPECOMP,
209 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
210 desckind);
211 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
213 ITypeComp_Release(bindptr.lptcomp);
215 /* test getting a TKIND_MODULE with INVOKE_PROPERTYGET */
216 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdFunctions);
217 hr = ITypeComp_Bind(pTypeComp, wszStdFunctions, ulHash, INVOKE_PROPERTYGET, &pTypeInfo, &desckind, &bindptr);
218 ok_ole_success(hr, ITypeComp_Bind);
220 ok(desckind == DESCKIND_TYPECOMP,
221 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
222 desckind);
223 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
224 ITypeComp_Release(bindptr.lptcomp);
226 /* test getting a function within a TKIND_MODULE */
227 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszSavePicture);
228 hr = ITypeComp_Bind(pTypeComp, wszSavePicture, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
229 ok_ole_success(hr, ITypeComp_Bind);
231 ok(desckind == DESCKIND_FUNCDESC,
232 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
233 desckind);
234 ok(bindptr.lpfuncdesc != NULL, "bindptr.lpfuncdesc should not have been set to NULL\n");
235 ITypeInfo_ReleaseFuncDesc(pTypeInfo, bindptr.lpfuncdesc);
236 ITypeInfo_Release(pTypeInfo);
238 /* test getting a function within a TKIND_MODULE with INVOKE_PROPERTYGET */
239 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszSavePicture);
240 hr = ITypeComp_Bind(pTypeComp, wszSavePicture, ulHash, INVOKE_PROPERTYGET, &pTypeInfo, &desckind, &bindptr);
241 ok(hr == TYPE_E_TYPEMISMATCH,
242 "ITypeComp_Bind should have failed with TYPE_E_TYPEMISMATCH instead of 0x%08x\n",
243 hr);
245 ok(desckind == DESCKIND_NONE,
246 "desckind should have been DESCKIND_NONE instead of %d\n",
247 desckind);
248 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
249 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
251 /* test getting a TKIND_ENUM */
252 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszOLE_TRISTATE);
253 hr = ITypeComp_Bind(pTypeComp, wszOLE_TRISTATE, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
254 ok_ole_success(hr, ITypeComp_Bind);
256 ok(desckind == DESCKIND_TYPECOMP,
257 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
258 desckind);
259 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
261 ITypeComp_Release(bindptr.lptcomp);
263 /* test getting a value within a TKIND_ENUM */
264 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszUnchecked);
265 hr = ITypeComp_Bind(pTypeComp, wszUnchecked, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
266 ok_ole_success(hr, ITypeComp_Bind);
268 ok(desckind == DESCKIND_VARDESC,
269 "desckind should have been DESCKIND_VARDESC instead of %d\n",
270 desckind);
271 ITypeInfo_ReleaseVarDesc(pTypeInfo, bindptr.lpvardesc);
272 ITypeInfo_Release(pTypeInfo);
274 /* test getting a TKIND_INTERFACE */
275 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszIUnknown);
276 hr = ITypeComp_Bind(pTypeComp, wszIUnknown, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
277 ok_ole_success(hr, ITypeComp_Bind);
279 ok(desckind == DESCKIND_NONE,
280 "desckind should have been DESCKIND_NONE instead of %d\n",
281 desckind);
282 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
283 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
285 /* test getting a TKIND_DISPATCH */
286 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszFont);
287 hr = ITypeComp_Bind(pTypeComp, wszFont, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
288 ok_ole_success(hr, ITypeComp_Bind);
290 ok(desckind == DESCKIND_NONE,
291 "desckind should have been DESCKIND_NONE instead of %d\n",
292 desckind);
293 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
294 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
296 /* test getting a TKIND_RECORD/TKIND_ALIAS */
297 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszGUID);
298 hr = ITypeComp_Bind(pTypeComp, wszGUID, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
299 ok_ole_success(hr, ITypeComp_Bind);
301 ok(desckind == DESCKIND_NONE,
302 "desckind should have been DESCKIND_NONE instead of %d\n",
303 desckind);
304 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
305 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
307 /* test getting a TKIND_ALIAS */
308 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszOLE_COLOR);
309 hr = ITypeComp_Bind(pTypeComp, wszOLE_COLOR, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
310 ok_ole_success(hr, ITypeComp_Bind);
312 ok(desckind == DESCKIND_NONE,
313 "desckind should have been DESCKIND_NONE instead of %d\n",
314 desckind);
315 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
316 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
318 /* test getting a TKIND_COCLASS */
319 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszStdPicture);
320 hr = ITypeComp_Bind(pTypeComp, wszStdPicture, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
321 ok_ole_success(hr, ITypeComp_Bind);
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");
329 /* test basic BindType argument handling */
330 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszGUID);
331 hr = ITypeComp_BindType(pTypeComp, wszGUID, ulHash, NULL, NULL);
332 ok(hr == E_INVALIDARG, "Got %08x\n", hr);
334 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszGUID);
335 pTypeInfo = (void*)0xdeadbeef;
336 hr = ITypeComp_BindType(pTypeComp, wszGUID, ulHash, &pTypeInfo, NULL);
337 ok(hr == E_INVALIDARG, "Got %08x\n", hr);
338 ok(pTypeInfo == (void*)0xdeadbeef, "Got %p\n", pTypeInfo);
340 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszGUID);
341 pTypeComp_tmp = (void*)0xdeadbeef;
342 hr = ITypeComp_BindType(pTypeComp, wszGUID, ulHash, NULL, &pTypeComp_tmp);
343 ok(hr == E_INVALIDARG, "Got %08x\n", hr);
344 ok(pTypeComp_tmp == (void*)0xdeadbeef, "Got %p\n", pTypeComp_tmp);
346 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszGUID);
347 pTypeComp_tmp = (void*)0xdeadbeef;
348 pTypeInfo = (void*)0xdeadbeef;
349 hr = ITypeComp_BindType(pTypeComp, NULL, ulHash, &pTypeInfo, &pTypeComp_tmp);
350 ok(hr == E_INVALIDARG, "Got %08x\n", hr);
351 ok(pTypeInfo == (void*)0xdeadbeef, "Got %p\n", pTypeInfo);
352 ok(pTypeComp_tmp == (void*)0xdeadbeef, "Got %p\n", pTypeComp_tmp);
354 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszGUID);
355 pTypeComp_tmp = (void*)0xdeadbeef;
356 pTypeInfo = (void*)0xdeadbeef;
357 hr = ITypeComp_BindType(pTypeComp, wszGUID, ulHash, &pTypeInfo, &pTypeComp_tmp);
358 ok_ole_success(hr, ITypeComp_BindType);
359 ok(pTypeInfo != NULL, "Got NULL pTypeInfo\n");
360 todo_wine ok(pTypeComp_tmp == NULL, "Got pTypeComp_tmp %p\n", pTypeComp_tmp);
361 ITypeInfo_Release(pTypeInfo);
362 if(pTypeComp_tmp) ITypeComp_Release(pTypeComp_tmp); /* fixme */
364 /* test BindType case-insensitivity */
365 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszguid);
366 pTypeComp_tmp = (void*)0xdeadbeef;
367 pTypeInfo = (void*)0xdeadbeef;
368 hr = ITypeComp_BindType(pTypeComp, wszguid, ulHash, &pTypeInfo, &pTypeComp_tmp);
369 ok_ole_success(hr, ITypeComp_BindType);
370 ok(pTypeInfo != NULL, "Got NULL pTypeInfo\n");
371 todo_wine ok(pTypeComp_tmp == NULL, "Got pTypeComp_tmp %p\n", pTypeComp_tmp);
372 ITypeInfo_Release(pTypeInfo);
373 if(pTypeComp_tmp) ITypeComp_Release(pTypeComp_tmp); /* fixme */
375 ITypeComp_Release(pTypeComp);
377 /* tests for ITypeComp on an interface */
378 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IFont, &pFontTypeInfo);
379 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
381 hr = ITypeInfo_GetTypeComp(pFontTypeInfo, &pTypeComp);
382 ok_ole_success(hr, ITypeLib_GetTypeComp);
384 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszClone);
385 hr = ITypeComp_Bind(pTypeComp, wszClone, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
386 ok_ole_success(hr, ITypeComp_Bind);
388 ok(desckind == DESCKIND_FUNCDESC,
389 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
390 desckind);
391 ok(bindptr.lpfuncdesc != NULL, "bindptr.lpfuncdesc should not have been set to NULL\n");
392 ITypeInfo_ReleaseFuncDesc(pTypeInfo, bindptr.lpfuncdesc);
393 ITypeInfo_Release(pTypeInfo);
395 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszClone);
396 hr = ITypeComp_Bind(pTypeComp, wszClone, ulHash, INVOKE_PROPERTYGET, &pTypeInfo, &desckind, &bindptr);
397 ok(hr == TYPE_E_TYPEMISMATCH, "ITypeComp_Bind should have failed with TYPE_E_TYPEMISMATCH instead of 0x%08x\n", hr);
399 ok(desckind == DESCKIND_NONE,
400 "desckind should have been DESCKIND_NONE instead of %d\n",
401 desckind);
402 ok(!pTypeInfo, "pTypeInfo should have been set to NULL\n");
403 ok(!bindptr.lptcomp, "bindptr should have been set to NULL\n");
405 /* tests that the compare is case-insensitive */
406 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszclone);
407 hr = ITypeComp_Bind(pTypeComp, wszclone, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
408 ok_ole_success(hr, ITypeComp_Bind);
410 ok(desckind == DESCKIND_FUNCDESC,
411 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
412 desckind);
413 ok(bindptr.lpfuncdesc != NULL, "bindptr.lpfuncdesc should not have been set to NULL\n");
414 ITypeInfo_ReleaseFuncDesc(pTypeInfo, bindptr.lpfuncdesc);
415 ITypeInfo_Release(pTypeInfo);
417 /* tests nonexistent members */
418 desckind = 0xdeadbeef;
419 bindptr.lptcomp = (ITypeComp*)0xdeadbeef;
420 pTypeInfo = (ITypeInfo*)0xdeadbeef;
421 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszJunk);
422 hr = ITypeComp_Bind(pTypeComp, wszJunk, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
423 ok_ole_success(hr, ITypeComp_Bind);
424 ok(desckind == DESCKIND_NONE, "desckind should have been DESCKIND_NONE, was: %d\n", desckind);
425 ok(pTypeInfo == NULL, "pTypeInfo should have been NULL, was: %p\n", pTypeInfo);
426 ok(bindptr.lptcomp == NULL, "bindptr should have been NULL, was: %p\n", bindptr.lptcomp);
428 /* tests inherited members */
429 desckind = 0xdeadbeef;
430 bindptr.lpfuncdesc = NULL;
431 pTypeInfo = NULL;
432 ulHash = LHashValOfNameSys(SYS_WIN32, LOCALE_NEUTRAL, wszAddRef);
433 hr = ITypeComp_Bind(pTypeComp, wszAddRef, ulHash, 0, &pTypeInfo, &desckind, &bindptr);
434 ok_ole_success(hr, ITypeComp_Bind);
435 ok(desckind == DESCKIND_FUNCDESC, "desckind should have been DESCKIND_FUNCDESC, was: %d\n", desckind);
436 ok(pTypeInfo != NULL, "pTypeInfo should not have been NULL, was: %p\n", pTypeInfo);
437 ok(bindptr.lpfuncdesc != NULL, "bindptr should not have been NULL, was: %p\n", bindptr.lpfuncdesc);
438 ITypeInfo_ReleaseFuncDesc(pTypeInfo, bindptr.lpfuncdesc);
439 ITypeInfo_Release(pTypeInfo);
441 ITypeComp_Release(pTypeComp);
442 ITypeInfo_Release(pFontTypeInfo);
443 ITypeLib_Release(pTypeLib);
446 static void test_CreateDispTypeInfo(void)
448 ITypeInfo *pTypeInfo, *pTI2;
449 HRESULT hr;
450 INTERFACEDATA ifdata;
451 METHODDATA methdata[4];
452 PARAMDATA parms1[2];
453 PARAMDATA parms3[1];
454 TYPEATTR *pTypeAttr;
455 HREFTYPE href;
456 FUNCDESC *pFuncDesc;
457 MEMBERID memid;
459 static WCHAR func1[] = {'f','u','n','c','1',0};
460 static const WCHAR func2[] = {'f','u','n','c','2',0};
461 static const WCHAR func3[] = {'f','u','n','c','3',0};
462 static const WCHAR parm1[] = {'p','a','r','m','1',0};
463 static const WCHAR parm2[] = {'p','a','r','m','2',0};
464 OLECHAR *name = func1;
466 ifdata.pmethdata = methdata;
467 ifdata.cMembers = sizeof(methdata) / sizeof(methdata[0]);
469 methdata[0].szName = SysAllocString(func1);
470 methdata[0].ppdata = parms1;
471 methdata[0].dispid = 0x123;
472 methdata[0].iMeth = 0;
473 methdata[0].cc = CC_STDCALL;
474 methdata[0].cArgs = 2;
475 methdata[0].wFlags = DISPATCH_METHOD;
476 methdata[0].vtReturn = VT_HRESULT;
477 parms1[0].szName = SysAllocString(parm1);
478 parms1[0].vt = VT_I4;
479 parms1[1].szName = SysAllocString(parm2);
480 parms1[1].vt = VT_BSTR;
482 methdata[1].szName = SysAllocString(func2);
483 methdata[1].ppdata = NULL;
484 methdata[1].dispid = 0x124;
485 methdata[1].iMeth = 1;
486 methdata[1].cc = CC_STDCALL;
487 methdata[1].cArgs = 0;
488 methdata[1].wFlags = DISPATCH_PROPERTYGET;
489 methdata[1].vtReturn = VT_I4;
491 methdata[2].szName = SysAllocString(func3);
492 methdata[2].ppdata = parms3;
493 methdata[2].dispid = 0x125;
494 methdata[2].iMeth = 3;
495 methdata[2].cc = CC_STDCALL;
496 methdata[2].cArgs = 1;
497 methdata[2].wFlags = DISPATCH_PROPERTYPUT;
498 methdata[2].vtReturn = VT_HRESULT;
499 parms3[0].szName = SysAllocString(parm1);
500 parms3[0].vt = VT_I4;
502 methdata[3].szName = SysAllocString(func3);
503 methdata[3].ppdata = NULL;
504 methdata[3].dispid = 0x125;
505 methdata[3].iMeth = 4;
506 methdata[3].cc = CC_STDCALL;
507 methdata[3].cArgs = 0;
508 methdata[3].wFlags = DISPATCH_PROPERTYGET;
509 methdata[3].vtReturn = VT_I4;
511 hr = CreateDispTypeInfo(&ifdata, LOCALE_NEUTRAL, &pTypeInfo);
512 ok(hr == S_OK, "hr %08x\n", hr);
514 hr = ITypeInfo_GetTypeAttr(pTypeInfo, &pTypeAttr);
515 ok(hr == S_OK, "hr %08x\n", hr);
517 ok(pTypeAttr->typekind == TKIND_COCLASS, "typekind %0x\n", pTypeAttr->typekind);
518 ok(pTypeAttr->cImplTypes == 1, "cImplTypes %d\n", pTypeAttr->cImplTypes);
519 ok(pTypeAttr->cFuncs == 0, "cFuncs %d\n", pTypeAttr->cFuncs);
520 ok(pTypeAttr->wTypeFlags == 0, "wTypeFlags %04x\n", pTypeAttr->cFuncs);
521 ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr);
523 hr = ITypeInfo_GetRefTypeOfImplType(pTypeInfo, 0, &href);
524 ok(hr == S_OK, "hr %08x\n", hr);
525 ok(href == 0, "href = 0x%x\n", href);
526 hr = ITypeInfo_GetRefTypeInfo(pTypeInfo, href, &pTI2);
527 ok(hr == S_OK, "hr %08x\n", hr);
528 hr = ITypeInfo_GetTypeAttr(pTI2, &pTypeAttr);
529 ok(hr == S_OK, "hr %08x\n", hr);
530 ok(pTypeAttr->typekind == TKIND_INTERFACE, "typekind %0x\n", pTypeAttr->typekind);
531 ok(pTypeAttr->cFuncs == 4, "cFuncs %d\n", pTypeAttr->cFuncs);
532 ok(IsEqualGUID(&pTypeAttr->guid, &GUID_NULL), "guid {%08x-...}\n", pTypeAttr->guid.Data1);
533 ok(pTypeAttr->wTypeFlags == 0, "typeflags %08x\n", pTypeAttr->wTypeFlags);
535 ITypeInfo_ReleaseTypeAttr(pTI2, pTypeAttr);
537 hr = ITypeInfo_GetFuncDesc(pTI2, 0, &pFuncDesc);
538 ok(hr == S_OK, "hr %08x\n", hr);
539 ok(pFuncDesc->memid == 0x123, "memid %x\n", pFuncDesc->memid);
540 ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind);
541 ok(pFuncDesc->invkind == methdata[0].wFlags, "invkind %d\n", pFuncDesc->invkind);
542 ok(pFuncDesc->callconv == methdata[0].cc, "callconv %d\n", pFuncDesc->callconv);
543 ok(pFuncDesc->cParams == methdata[0].cArgs, "cParams %d\n", pFuncDesc->cParams);
544 ok(pFuncDesc->oVft == 0, "oVft %d\n", pFuncDesc->oVft);
545 ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags);
546 ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_HRESULT, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt);
547 ok(pFuncDesc->lprgelemdescParam[0].tdesc.vt == VT_I4, "parm 0 vt %x\n", pFuncDesc->lprgelemdescParam[0].tdesc.vt);
548 ok(U(pFuncDesc->lprgelemdescParam[0]).paramdesc.wParamFlags == PARAMFLAG_NONE, "parm 0 flags %x\n", U(pFuncDesc->lprgelemdescParam[0]).paramdesc.wParamFlags);
550 ok(pFuncDesc->lprgelemdescParam[1].tdesc.vt == VT_BSTR, "parm 1 vt %x\n", pFuncDesc->lprgelemdescParam[1].tdesc.vt);
551 ok(U(pFuncDesc->lprgelemdescParam[1]).paramdesc.wParamFlags == PARAMFLAG_NONE, "parm 1 flags %x\n", U(pFuncDesc->lprgelemdescParam[1]).paramdesc.wParamFlags);
552 ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc);
554 hr = ITypeInfo_GetFuncDesc(pTI2, 1, &pFuncDesc);
555 ok(hr == S_OK, "hr %08x\n", hr);
556 ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind);
557 ok(pFuncDesc->invkind == methdata[1].wFlags, "invkind %d\n", pFuncDesc->invkind);
558 ok(pFuncDesc->callconv == methdata[1].cc, "callconv %d\n", pFuncDesc->callconv);
559 ok(pFuncDesc->cParams == methdata[1].cArgs, "cParams %d\n", pFuncDesc->cParams);
560 ok(pFuncDesc->oVft == sizeof(void *), "oVft %d\n", pFuncDesc->oVft);
561 ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags);
562 ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_I4, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt);
563 ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc);
565 hr = ITypeInfo_GetFuncDesc(pTI2, 2, &pFuncDesc);
566 ok(hr == S_OK, "hr %08x\n", hr);
567 ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind);
568 ok(pFuncDesc->invkind == methdata[2].wFlags, "invkind %d\n", pFuncDesc->invkind);
569 ok(pFuncDesc->callconv == methdata[2].cc, "callconv %d\n", pFuncDesc->callconv);
570 ok(pFuncDesc->cParams == methdata[2].cArgs, "cParams %d\n", pFuncDesc->cParams);
571 ok(pFuncDesc->oVft == 3 * sizeof(void *), "oVft %d\n", pFuncDesc->oVft);
572 ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags);
573 ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_HRESULT, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt);
574 ok(pFuncDesc->lprgelemdescParam[0].tdesc.vt == VT_I4, "parm 0 vt %x\n", pFuncDesc->lprgelemdescParam[0].tdesc.vt);
575 ok(U(pFuncDesc->lprgelemdescParam[0]).paramdesc.wParamFlags == PARAMFLAG_NONE, "parm 0 flags %x\n", U(pFuncDesc->lprgelemdescParam[0]).paramdesc.wParamFlags);
576 ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc);
578 hr = ITypeInfo_GetFuncDesc(pTI2, 3, &pFuncDesc);
579 ok(hr == S_OK, "hr %08x\n", hr);
580 ok(pFuncDesc->funckind == FUNC_VIRTUAL, "funckind %d\n", pFuncDesc->funckind);
581 ok(pFuncDesc->invkind == methdata[3].wFlags, "invkind %d\n", pFuncDesc->invkind);
582 ok(pFuncDesc->callconv == methdata[3].cc, "callconv %d\n", pFuncDesc->callconv);
583 ok(pFuncDesc->cParams == methdata[3].cArgs, "cParams %d\n", pFuncDesc->cParams);
584 ok(pFuncDesc->oVft == 4 * sizeof(void *), "oVft %d\n", pFuncDesc->oVft);
585 ok(pFuncDesc->wFuncFlags == 0, "oVft %d\n", pFuncDesc->wFuncFlags);
586 ok(pFuncDesc->elemdescFunc.tdesc.vt == VT_I4, "ret vt %x\n", pFuncDesc->elemdescFunc.tdesc.vt);
587 ITypeInfo_ReleaseFuncDesc(pTI2, pFuncDesc);
589 /* test GetIDsOfNames on a coclass to see if it searches its interfaces */
590 hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &name, 1, &memid);
591 ok(hr == S_OK, "hr 0x%08x\n", hr);
592 ok(memid == 0x123, "memid 0x%08x\n", memid);
594 ITypeInfo_Release(pTI2);
595 ITypeInfo_Release(pTypeInfo);
597 SysFreeString(parms1[0].szName);
598 SysFreeString(parms1[1].szName);
599 SysFreeString(parms3[0].szName);
600 SysFreeString(methdata[0].szName);
601 SysFreeString(methdata[1].szName);
602 SysFreeString(methdata[2].szName);
603 SysFreeString(methdata[3].szName);
606 static const char *create_test_typelib(int res_no)
608 static char filename[MAX_PATH];
609 HANDLE file;
610 HRSRC res;
611 void *ptr;
612 DWORD written;
614 GetTempFileNameA( ".", "tlb", 0, filename );
615 file = CreateFile( filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
616 ok( file != INVALID_HANDLE_VALUE, "file creation failed\n" );
617 if (file == INVALID_HANDLE_VALUE) return NULL;
618 res = FindResource( GetModuleHandle(0), MAKEINTRESOURCE(res_no), "TYPELIB" );
619 ok( res != 0, "couldn't find resource\n" );
620 ptr = LockResource( LoadResource( GetModuleHandle(0), res ));
621 WriteFile( file, ptr, SizeofResource( GetModuleHandle(0), res ), &written, NULL );
622 ok( written == SizeofResource( GetModuleHandle(0), res ), "couldn't write resource\n" );
623 CloseHandle( file );
624 return filename;
627 static void test_TypeInfo(void)
629 ITypeLib *pTypeLib;
630 ITypeInfo *pTypeInfo;
631 ITypeInfo2 *pTypeInfo2;
632 HRESULT hr;
633 static WCHAR wszBogus[] = { 'b','o','g','u','s',0 };
634 static WCHAR wszGetTypeInfo[] = { 'G','e','t','T','y','p','e','I','n','f','o',0 };
635 static WCHAR wszClone[] = {'C','l','o','n','e',0};
636 OLECHAR* bogus = wszBogus;
637 OLECHAR* pwszGetTypeInfo = wszGetTypeInfo;
638 OLECHAR* pwszClone = wszClone;
639 DISPID dispidMember;
640 DISPPARAMS dispparams;
641 GUID bogusguid = {0x806afb4f,0x13f7,0x42d2,{0x89,0x2c,0x6c,0x97,0xc3,0x6a,0x36,0xc1}};
642 VARIANT var, res, args[2];
643 UINT count, i;
644 TYPEKIND kind;
645 const char *filenameA;
646 WCHAR filename[MAX_PATH];
648 hr = LoadTypeLib(wszStdOle2, &pTypeLib);
649 ok_ole_success(hr, LoadTypeLib);
651 count = ITypeLib_GetTypeInfoCount(pTypeLib);
652 ok(count > 0, "got %d\n", count);
654 /* invalid index */
655 hr = ITypeLib_GetTypeInfo(pTypeLib, count, &pTypeInfo);
656 ok(hr == TYPE_E_ELEMENTNOTFOUND, "got 0x%08x\n", hr);
658 hr = ITypeLib_GetTypeInfo(pTypeLib, 0, NULL);
659 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
661 hr = ITypeLib_GetLibAttr(pTypeLib, NULL);
662 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
664 hr = ITypeLib_GetTypeInfoType(pTypeLib, count, &kind);
665 ok(hr == TYPE_E_ELEMENTNOTFOUND, "got 0x%08x\n", hr);
667 hr = ITypeLib_GetTypeInfoType(pTypeLib, count, NULL);
668 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
670 hr = ITypeLib_GetTypeInfoType(pTypeLib, 0, NULL);
671 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
673 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IFont, &pTypeInfo);
674 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
676 /* test nonexistent method name */
677 hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &bogus, 1, &dispidMember);
678 ok(hr == DISP_E_UNKNOWNNAME,
679 "ITypeInfo_GetIDsOfNames should have returned DISP_E_UNKNOWNNAME instead of 0x%08x\n",
680 hr);
682 dispparams.cArgs = 0;
683 dispparams.rgdispidNamedArgs = NULL;
684 dispparams.rgvarg = NULL;
686 /* test dispparams not NULL */
688 /* invalid member id -- wrong flags -- cNamedArgs not bigger than cArgs */
689 dispparams.cNamedArgs = 0;
690 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, 0xdeadbeef, DISPATCH_PROPERTYGET, &dispparams, NULL, NULL, NULL);
691 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
692 /* invalid member id -- correct flags -- cNamedArgs not bigger than cArgs */
693 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, 0xdeadbeef, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
694 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
696 /* invalid member id -- wrong flags -- cNamedArgs bigger than cArgs */
697 dispparams.cNamedArgs = 1;
698 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, 0xdeadbeef, DISPATCH_PROPERTYGET, &dispparams, NULL, NULL, NULL);
699 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
700 /* invalid member id -- correct flags -- cNamedArgs bigger than cArgs */
701 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, 0xdeadbeef, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
702 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
705 hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &pwszClone, 1, &dispidMember);
706 ok_ole_success(hr, ITypeInfo_GetIDsOfNames);
708 /* correct member id -- wrong flags -- cNamedArgs not bigger than cArgs */
709 dispparams.cNamedArgs = 0;
710 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, &dispparams, NULL, NULL, NULL);
711 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
712 /* correct member id -- correct flags -- cNamedArgs not bigger than cArgs */
713 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
714 ok(hr == DISP_E_BADPARAMCOUNT, "ITypeInfo_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr);
716 /* correct member id -- wrong flags -- cNamedArgs bigger than cArgs */
717 dispparams.cNamedArgs = 1;
718 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, &dispparams, NULL, NULL, NULL);
719 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
720 /* correct member id -- correct flags -- cNamedArgs bigger than cArgs */
721 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
722 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
724 /* test NULL dispparams */
726 /* correct member id -- wrong flags -- cNamedArgs not bigger than cArgs */
727 dispparams.cNamedArgs = 0;
728 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
729 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
730 /* correct member id -- correct flags -- cNamedArgs not bigger than cArgs */
731 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, NULL, NULL, NULL, NULL);
732 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
734 /* correct member id -- wrong flags -- cNamedArgs bigger than cArgs */
735 dispparams.cNamedArgs = 1;
736 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
737 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
738 /* correct member id -- correct flags -- cNamedArgs bigger than cArgs */
739 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, NULL, NULL, NULL, NULL);
740 ok(hr == E_INVALIDARG, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr);
742 ITypeInfo_Release(pTypeInfo);
746 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IDispatch, &pTypeInfo);
747 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
749 hr = ITypeInfo_GetIDsOfNames(pTypeInfo, &pwszGetTypeInfo, 1, &dispidMember);
750 ok_ole_success(hr, ITypeInfo_GetIDsOfNames);
752 hr = ITypeInfo_QueryInterface(pTypeInfo, &IID_ITypeInfo2, (void**)&pTypeInfo2);
753 ok_ole_success(hr, ITypeInfo_QueryInterface);
755 if (SUCCEEDED(hr))
757 VariantInit(&var);
759 V_VT(&var) = VT_I4;
761 /* test unknown guid passed to GetCustData */
762 hr = ITypeInfo2_GetCustData(pTypeInfo2, &bogusguid, &var);
763 ok_ole_success(hr, ITypeInfo_GetCustData);
764 ok(V_VT(&var) == VT_EMPTY, "got %i, expected VT_EMPTY\n", V_VT(&var));
766 ITypeInfo2_Release(pTypeInfo2);
768 VariantClear(&var);
771 /* test invoking a method with a [restricted] keyword */
773 /* correct member id -- wrong flags -- cNamedArgs not bigger than cArgs */
774 dispparams.cNamedArgs = 0;
775 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, &dispparams, NULL, NULL, NULL);
776 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
777 /* correct member id -- correct flags -- cNamedArgs not bigger than cArgs */
778 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
779 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
781 /* correct member id -- wrong flags -- cNamedArgs bigger than cArgs */
782 dispparams.cNamedArgs = 1;
783 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, &dispparams, NULL, NULL, NULL);
784 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
785 /* correct member id -- correct flags -- cNamedArgs bigger than cArgs */
786 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
787 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
789 /* test NULL dispparams */
791 /* correct member id -- wrong flags -- cNamedArgs not bigger than cArgs */
792 dispparams.cNamedArgs = 0;
793 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
794 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
795 /* correct member id -- correct flags -- cNamedArgs not bigger than cArgs */
796 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, NULL, NULL, NULL, NULL);
797 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
799 /* correct member id -- wrong flags -- cNamedArgs bigger than cArgs */
800 dispparams.cNamedArgs = 1;
801 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_PROPERTYGET, NULL, NULL, NULL, NULL);
802 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
803 /* correct member id -- correct flags -- cNamedArgs bigger than cArgs */
804 hr = ITypeInfo_Invoke(pTypeInfo, (void *)0xdeadbeef, dispidMember, DISPATCH_METHOD, NULL, NULL, NULL, NULL);
805 ok(hr == DISP_E_MEMBERNOTFOUND, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr);
807 ITypeInfo_Release(pTypeInfo);
808 ITypeLib_Release(pTypeLib);
810 filenameA = create_test_typelib(3);
811 MultiByteToWideChar(CP_ACP, 0, filenameA, -1, filename, MAX_PATH);
812 hr = LoadTypeLib(filename, &pTypeLib);
813 ok(hr == S_OK, "got 0x%08x\n", hr);
815 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IInvokeTest, &pTypeInfo);
816 ok(hr == S_OK, "got 0x%08x\n", hr);
818 dispparams.cArgs = 1;
819 dispparams.cNamedArgs = 0;
820 dispparams.rgdispidNamedArgs = NULL;
821 dispparams.rgvarg = args;
823 V_VT(&args[0]) = VT_I4;
824 V_I4(&args[0]) = 0;
826 V_VT(&res) = VT_EMPTY;
828 i = 0;
829 V_VT(&res) = VT_EMPTY;
830 V_I4(&res) = 0;
831 /* call propget with DISPATCH_METHOD|DISPATCH_PROPERTYGET flags */
832 hr = ITypeInfo_Invoke(pTypeInfo, &invoketest, DISPID_VALUE, DISPATCH_METHOD|DISPATCH_PROPERTYGET,
833 &dispparams, &res, NULL, &i);
834 ok(hr == S_OK, "got 0x%08x\n", hr);
835 ok(V_VT(&res) == VT_I4, "got %d\n", V_VT(&res));
836 ok(V_I4(&res) == 1, "got %d\n", V_I4(&res));
838 i = 0;
839 /* call propget with DISPATCH_METHOD flags */
840 hr = ITypeInfo_Invoke(pTypeInfo, &invoketest, DISPID_VALUE, DISPATCH_METHOD,
841 &dispparams, &res, NULL, &i);
842 ok(hr == DISP_E_MEMBERNOTFOUND, "got 0x%08x, %d\n", hr, i);
844 i = 0;
845 V_VT(&res) = VT_EMPTY;
846 V_I4(&res) = 0;
847 hr = ITypeInfo_Invoke(pTypeInfo, &invoketest, DISPID_VALUE, DISPATCH_PROPERTYGET,
848 &dispparams, &res, NULL, &i);
849 ok(hr == S_OK, "got 0x%08x, %d\n", hr, i);
850 ok(V_VT(&res) == VT_I4, "got %d\n", V_VT(&res));
851 ok(V_I4(&res) == 1, "got %d\n", V_I4(&res));
853 ITypeInfo_Release(pTypeInfo);
854 ITypeLib_Release(pTypeLib);
855 DeleteFileA(filenameA);
858 static int WINAPI int_func( int a0, int a1, int a2, int a3, int a4 )
860 ok( a0 == 1, "wrong arg0 %x\n", a0 );
861 ok( a1 == -1, "wrong arg1 %x\n", a1 );
862 ok( a2 == (0x55550000 | 1234), "wrong arg2 %x\n", a2 );
863 ok( a3 == 0xdeadbeef, "wrong arg3 %x\n", a3 );
864 ok( a4 == 0x555555fd, "wrong arg4 %x\n", a4 );
865 return 4321;
868 static double WINAPI double_func( double a0, float a1, double a2, int a3 )
870 ok( a0 == 1.2, "wrong arg0 %f\n", (double)a0 );
871 ok( a1 == 3.25, "wrong arg1 %f\n", (double)a1 );
872 ok( a2 == 1.2e12, "wrong arg2 %f\n", (double)a2);
873 ok( a3 == -4433.0, "wrong arg3 %f\n", (double)a3 );
874 return 4321;
877 static LONGLONG WINAPI longlong_func( LONGLONG a0, CY a1 )
879 ok( a0 == (((ULONGLONG)0xdead << 32) | 0xbeef), "wrong arg0 %08x%08x\n", (DWORD)(a0 >> 32), (DWORD)a0);
880 ok( a1.int64 == ((ULONGLONG)10000 * 12345678), "wrong arg1 %08x%08x\n",
881 (DWORD)(a1.int64 >> 32), (DWORD)a1.int64 );
882 return ((ULONGLONG)4321 << 32) | 8765;
885 static VARIANT WINAPI variant_func( int a0, BOOL a1, DECIMAL a2, VARIANT a3 )
887 VARIANT var;
888 ok( a0 == 2233, "wrong arg0 %x\n", a0 );
889 ok( a1 == 1 || broken(a1 == 0x55550001), "wrong arg1 %x\n", a1 );
890 V_VT(&var) = VT_LPWSTR;
891 V_UI4(&var) = 0xbabe;
892 ok( a2.Hi32 == 1122, "wrong arg2.Hi32 %x\n", a2.Hi32 );
893 ok( U1(a2).Lo64 == 3344, "wrong arg2.Lo64 %08x%08x\n", (DWORD)(U1(a2).Lo64 >> 32), (DWORD)U1(a2).Lo64 );
894 ok( V_VT(&a3) == VT_EMPTY, "wrong arg3 type %x\n", V_VT(&a3) );
895 ok( V_UI4(&a3) == 0xdeadbeef, "wrong arg3 value %x\n", V_UI4(&a3) );
896 return var;
899 static int CDECL void_func( int a0, int a1 )
901 if (is_win64) /* VT_EMPTY is passed as real arg on win64 */
903 ok( a0 == 0x55555555, "wrong arg0 %x\n", a0 );
904 ok( a1 == 1111, "wrong arg1 %x\n", a1 );
906 else
908 ok( a0 == 1111, "wrong arg0 %x\n", a0 );
909 ok( a1 == 0, "wrong arg1 %x\n", a1 );
911 return 12;
914 static int WINAPI stdcall_func( int a )
916 return 0;
919 static int WINAPI inst_func( void *inst, int a )
921 ok( (*(void ***)inst)[3] == inst_func, "wrong ptr %p\n", inst );
922 ok( a == 3, "wrong arg %x\n", a );
923 return a * 2;
926 static HRESULT WINAPI ret_false_func(void)
928 return S_FALSE;
931 static const void *vtable[] = { NULL, NULL, NULL, inst_func };
933 static void test_DispCallFunc(void)
935 const void **inst = vtable;
936 HRESULT res;
937 VARIANT result, args[5];
938 VARIANTARG *pargs[5];
939 VARTYPE types[5];
940 int i;
942 for (i = 0; i < 5; i++) pargs[i] = &args[i];
944 memset( args, 0x55, sizeof(args) );
945 types[0] = VT_UI4;
946 V_UI4(&args[0]) = 1;
947 types[1] = VT_I4;
948 V_I4(&args[1]) = -1;
949 types[2] = VT_I2;
950 V_I2(&args[2]) = 1234;
951 types[3] = VT_UI4;
952 V_UI4(&args[3]) = 0xdeadbeef;
953 types[4] = VT_UI4;
954 V_I1(&args[4]) = -3;
955 memset( &result, 0xcc, sizeof(result) );
956 res = DispCallFunc( NULL, (ULONG_PTR)int_func, CC_STDCALL, VT_UI4, 5, types, pargs, &result );
957 ok( res == S_OK, "DispCallFunc failed %x\n", res );
958 ok( V_VT(&result) == VT_UI4, "wrong result type %d\n", V_VT(&result) );
959 ok( V_UI4(&result) == 4321, "wrong result %u\n", V_UI4(&result) );
961 /* the function checks the argument sizes for stdcall */
962 if (!is_win64) /* no stdcall on 64-bit */
964 res = DispCallFunc( NULL, (ULONG_PTR)stdcall_func, CC_STDCALL, VT_UI4, 0, types, pargs, &result );
965 ok( res == DISP_E_BADCALLEE, "DispCallFunc wrong error %x\n", res );
966 res = DispCallFunc( NULL, (ULONG_PTR)stdcall_func, CC_STDCALL, VT_UI4, 1, types, pargs, &result );
967 ok( res == S_OK, "DispCallFunc failed %x\n", res );
968 res = DispCallFunc( NULL, (ULONG_PTR)stdcall_func, CC_STDCALL, VT_UI4, 2, types, pargs, &result );
969 ok( res == DISP_E_BADCALLEE, "DispCallFunc wrong error %x\n", res );
972 memset( args, 0x55, sizeof(args) );
973 types[0] = VT_R8;
974 V_R8(&args[0]) = 1.2;
975 types[1] = VT_R4;
976 V_R4(&args[1]) = 3.25;
977 types[2] = VT_R8;
978 V_R8(&args[2]) = 1.2e12;
979 types[3] = VT_I4;
980 V_I4(&args[3]) = -4433;
981 memset( &result, 0xcc, sizeof(result) );
982 res = DispCallFunc( NULL, (ULONG_PTR)double_func, CC_STDCALL, VT_R8, 4, types, pargs, &result );
983 ok( res == S_OK, "DispCallFunc failed %x\n", res );
984 ok( V_VT(&result) == VT_R8, "wrong result type %d\n", V_VT(&result) );
985 ok( V_R8(&result) == 4321, "wrong result %f\n", V_R8(&result) );
987 memset( args, 0x55, sizeof(args) );
988 types[0] = VT_I8;
989 V_I8(&args[0]) = ((ULONGLONG)0xdead << 32) | 0xbeef;
990 types[1] = VT_CY;
991 V_CY(&args[1]).int64 = (ULONGLONG)10000 * 12345678;
992 memset( &result, 0xcc, sizeof(result) );
993 res = DispCallFunc( NULL, (ULONG_PTR)longlong_func, CC_STDCALL, VT_I8, 2, types, pargs, &result );
994 ok( res == S_OK || broken(res == E_INVALIDARG), /* longlong not supported on <= win2k */
995 "DispCallFunc failed %x\n", res );
996 if (res == S_OK)
998 ok( V_VT(&result) == VT_I8, "wrong result type %d\n", V_VT(&result) );
999 ok( V_I8(&result) == (((ULONGLONG)4321 << 32) | 8765), "wrong result %08x%08x\n",
1000 (DWORD)(V_I8(&result) >> 32), (DWORD)V_I8(&result) );
1003 memset( args, 0x55, sizeof(args) );
1004 types[0] = VT_I4;
1005 V_I4(&args[0]) = 2233;
1006 types[1] = VT_BOOL;
1007 V_BOOL(&args[1]) = 1;
1008 types[2] = VT_DECIMAL;
1009 V_DECIMAL(&args[2]).Hi32 = 1122;
1010 U1(V_DECIMAL(&args[2])).Lo64 = 3344;
1011 types[3] = VT_VARIANT;
1012 V_VT(&args[3]) = VT_EMPTY;
1013 V_UI4(&args[3]) = 0xdeadbeef;
1014 types[4] = VT_EMPTY;
1015 memset( &result, 0xcc, sizeof(result) );
1016 res = DispCallFunc( NULL, (ULONG_PTR)variant_func, CC_STDCALL, VT_VARIANT, 5, types, pargs, &result );
1017 ok( res == S_OK, "DispCallFunc failed %x\n", res );
1018 ok( V_VT(&result) == VT_LPWSTR, "wrong result type %d\n", V_VT(&result) );
1019 ok( V_UI4(&result) == 0xbabe, "wrong result %08x\n", V_UI4(&result) );
1021 memset( args, 0x55, sizeof(args) );
1022 types[0] = VT_EMPTY;
1023 types[1] = VT_I4;
1024 V_I4(&args[1]) = 1111;
1025 types[2] = VT_EMPTY;
1026 types[3] = VT_I4;
1027 V_I4(&args[3]) = 0;
1028 types[4] = VT_EMPTY;
1029 memset( &result, 0xcc, sizeof(result) );
1030 res = DispCallFunc( NULL, (ULONG_PTR)void_func, CC_CDECL, VT_EMPTY, 5, types, pargs, &result );
1031 ok( res == S_OK, "DispCallFunc failed %x\n", res );
1032 ok( V_VT(&result) == VT_EMPTY, "wrong result type %d\n", V_VT(&result) );
1033 if (is_win64)
1034 ok( V_UI4(&result) == 12, "wrong result %08x\n", V_UI4(&result) );
1035 else
1036 ok( V_UI4(&result) == 0xcccccccc, "wrong result %08x\n", V_UI4(&result) );
1038 memset( args, 0x55, sizeof(args) );
1039 types[0] = VT_I4;
1040 V_I4(&args[0]) = 3;
1041 memset( &result, 0xcc, sizeof(result) );
1042 res = DispCallFunc( &inst, 3 * sizeof(void*), CC_STDCALL, VT_I4, 1, types, pargs, &result );
1043 ok( res == S_OK, "DispCallFunc failed %x\n", res );
1044 ok( V_VT(&result) == VT_I4, "wrong result type %d\n", V_VT(&result) );
1045 ok( V_I4(&result) == 6, "wrong result %08x\n", V_I4(&result) );
1047 memset( &result, 0xcc, sizeof(result) );
1048 res = DispCallFunc(NULL, (ULONG_PTR)ret_false_func, CC_STDCALL, VT_ERROR, 0, NULL, NULL, &result);
1049 ok(res == S_OK, "DispCallFunc failed: %08x\n", res);
1050 ok(V_VT(&result) == VT_ERROR, "V_VT(result) = %u\n", V_VT(&result));
1051 ok(V_ERROR(&result) == S_FALSE, "V_ERROR(result) = %08x\n", V_ERROR(&result));
1053 memset( &result, 0xcc, sizeof(result) );
1054 res = DispCallFunc(NULL, (ULONG_PTR)ret_false_func, CC_STDCALL, VT_HRESULT, 0, NULL, NULL, &result);
1055 ok(res == E_INVALIDARG, "DispCallFunc failed: %08x\n", res);
1056 ok(V_VT(&result) == 0xcccc, "V_VT(result) = %u\n", V_VT(&result));
1059 /* RegDeleteTreeW from dlls/advapi32/registry.c */
1060 static LSTATUS myRegDeleteTreeW(HKEY hKey, LPCWSTR lpszSubKey)
1062 LONG ret;
1063 DWORD dwMaxSubkeyLen, dwMaxValueLen;
1064 DWORD dwMaxLen, dwSize;
1065 WCHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
1066 HKEY hSubKey = hKey;
1068 if(lpszSubKey)
1070 ret = RegOpenKeyExW(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
1071 if (ret) return ret;
1074 ret = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL,
1075 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
1076 if (ret) goto cleanup;
1078 dwMaxSubkeyLen++;
1079 dwMaxValueLen++;
1080 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
1081 if (dwMaxLen > sizeof(szNameBuf)/sizeof(WCHAR))
1083 /* Name too big: alloc a buffer for it */
1084 if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(WCHAR))))
1086 ret = ERROR_NOT_ENOUGH_MEMORY;
1087 goto cleanup;
1091 /* Recursively delete all the subkeys */
1092 while (TRUE)
1094 dwSize = dwMaxLen;
1095 if (RegEnumKeyExW(hSubKey, 0, lpszName, &dwSize, NULL,
1096 NULL, NULL, NULL)) break;
1098 ret = myRegDeleteTreeW(hSubKey, lpszName);
1099 if (ret) goto cleanup;
1102 if (lpszSubKey)
1103 ret = RegDeleteKeyW(hKey, lpszSubKey);
1104 else
1105 while (TRUE)
1107 dwSize = dwMaxLen;
1108 if (RegEnumValueW(hKey, 0, lpszName, &dwSize,
1109 NULL, NULL, NULL, NULL)) break;
1111 ret = RegDeleteValueW(hKey, lpszName);
1112 if (ret) goto cleanup;
1115 cleanup:
1116 if (lpszName != szNameBuf)
1117 HeapFree(GetProcessHeap(), 0, lpszName);
1118 if(lpszSubKey)
1119 RegCloseKey(hSubKey);
1120 return ret;
1123 static BOOL do_typelib_reg_key(GUID *uid, WORD maj, WORD min, DWORD arch, LPCWSTR base, BOOL remove)
1125 static const WCHAR typelibW[] = {'T','y','p','e','l','i','b','\\',0};
1126 static const WCHAR formatW[] = {'\\','%','u','.','%','u','\\','0','\\','w','i','n','%','u',0};
1127 static const WCHAR format2W[] = {'%','s','_','%','u','_','%','u','.','d','l','l',0};
1128 WCHAR buf[128];
1129 HKEY hkey;
1130 BOOL ret = TRUE;
1131 DWORD res;
1133 memcpy(buf, typelibW, sizeof(typelibW));
1134 StringFromGUID2(uid, buf + lstrlenW(buf), 40);
1136 if (remove)
1138 ok(myRegDeleteTreeW(HKEY_CLASSES_ROOT, buf) == ERROR_SUCCESS, "SHDeleteKey failed\n");
1139 return TRUE;
1142 wsprintfW(buf + lstrlenW(buf), formatW, maj, min, arch);
1144 SetLastError(0xdeadbeef);
1145 res = RegCreateKeyExW(HKEY_CLASSES_ROOT, buf, 0, NULL, 0,
1146 KEY_WRITE, NULL, &hkey, NULL);
1147 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1149 win_skip("W-calls are not implemented\n");
1150 return FALSE;
1153 if (res != ERROR_SUCCESS)
1155 trace("RegCreateKeyExW failed: %u\n", res);
1156 return FALSE;
1159 wsprintfW(buf, format2W, base, maj, min);
1160 if (RegSetValueExW(hkey, NULL, 0, REG_SZ,
1161 (BYTE *)buf, (lstrlenW(buf) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
1163 trace("RegSetValueExW failed\n");
1164 ret = FALSE;
1166 RegCloseKey(hkey);
1167 return ret;
1170 static void test_QueryPathOfRegTypeLib(DWORD arch)
1172 static const struct test_data
1174 WORD maj, min;
1175 HRESULT ret;
1176 const WCHAR path[16];
1177 } td[] = {
1178 { 1, 0, TYPE_E_LIBNOTREGISTERED, { 0 } },
1179 { 3, 0, S_OK, {'f','a','k','e','_','3','_','0','.','d','l','l',0 } },
1180 { 3, 1, S_OK, {'f','a','k','e','_','3','_','1','.','d','l','l',0 } },
1181 { 3, 22, S_OK, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
1182 { 3, 37, S_OK, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
1183 { 3, 40, S_OK, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
1184 { 0xffff, 0xffff, S_OK, {'f','a','k','e','_','5','_','3','7','.','d','l','l',0 } },
1185 { 0xffff, 0, TYPE_E_LIBNOTREGISTERED, { 0 } },
1186 { 3, 0xffff, TYPE_E_LIBNOTREGISTERED, { 0 } },
1187 { 5, 0xffff, TYPE_E_LIBNOTREGISTERED, { 0 } },
1188 { 4, 0, TYPE_E_LIBNOTREGISTERED, { 0 } }
1190 static const WCHAR base[] = {'f','a','k','e',0};
1191 static const WCHAR wrongW[] = {'w','r','o','n','g',0};
1192 UINT i;
1193 RPC_STATUS status;
1194 GUID uid;
1195 WCHAR uid_str[40];
1196 HRESULT ret;
1197 BSTR path;
1199 status = UuidCreate(&uid);
1200 ok(!status || status == RPC_S_UUID_LOCAL_ONLY, "UuidCreate error %08x\n", status);
1202 StringFromGUID2(&uid, uid_str, 40);
1203 /*trace("GUID: %s\n", wine_dbgstr_w(uid_str));*/
1205 if (!do_typelib_reg_key(&uid, 3, 0, arch, base, 0)) return;
1206 if (!do_typelib_reg_key(&uid, 3, 1, arch, base, 0)) return;
1207 if (!do_typelib_reg_key(&uid, 3, 37, arch, base, 0)) return;
1208 if (!do_typelib_reg_key(&uid, 5, 37, arch, base, 0)) return;
1209 if (arch == 64 && !do_typelib_reg_key(&uid, 5, 37, 32, wrongW, 0)) return;
1211 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
1213 ret = QueryPathOfRegTypeLib(&uid, td[i].maj, td[i].min, 0, &path);
1214 ok(ret == td[i].ret, "QueryPathOfRegTypeLib(%u.%u) returned %08x\n", td[i].maj, td[i].min, ret);
1215 if (ret == S_OK)
1217 ok(!lstrcmpW(td[i].path, path), "typelib %u.%u path doesn't match\n", td[i].maj, td[i].min);
1218 SysFreeString(path);
1222 do_typelib_reg_key(&uid, 0, 0, arch, NULL, 1);
1225 static void test_inheritance(void)
1227 HRESULT hr;
1228 ITypeLib *pTL;
1229 ITypeInfo *pTI, *pTI_p;
1230 TYPEATTR *pTA;
1231 HREFTYPE href;
1232 FUNCDESC *pFD;
1233 WCHAR path[MAX_PATH];
1234 CHAR pathA[MAX_PATH];
1235 static const WCHAR tl_path[] = {'.','\\','m','i','d','l','_','t','m','a','r','s','h','a','l','.','t','l','b',0};
1237 BOOL use_midl_tlb = 0;
1239 GetModuleFileNameA(NULL, pathA, MAX_PATH);
1240 MultiByteToWideChar(CP_ACP, 0, pathA, -1, path, MAX_PATH);
1242 if(use_midl_tlb)
1243 memcpy(path, tl_path, sizeof(tl_path));
1245 hr = LoadTypeLib(path, &pTL);
1246 if(FAILED(hr)) return;
1249 /* ItestIF3 is a syntax 2 dispinterface */
1250 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF3, &pTI);
1251 ok(hr == S_OK, "hr %08x\n", hr);
1253 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
1254 ok(hr == S_OK, "hr %08x\n", hr);
1255 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
1256 ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
1257 ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
1258 if(use_midl_tlb) {
1259 ok(pTA->cFuncs == 6, "cfuncs %d\n", pTA->cFuncs);
1260 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
1262 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
1264 if(use_midl_tlb) {
1265 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
1266 ok(hr == S_OK, "hr %08x\n", hr);
1267 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
1268 ok(hr == S_OK, "hr %08x\n", hr);
1269 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
1270 ok(hr == S_OK, "got %08x\n", hr);
1271 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
1272 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
1273 ITypeInfo_Release(pTI_p);
1275 /* Should have six methods */
1276 hr = ITypeInfo_GetFuncDesc(pTI, 6, &pFD);
1277 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
1278 hr = ITypeInfo_GetFuncDesc(pTI, 5, &pFD);
1279 ok(hr == S_OK, "hr %08x\n", hr);
1280 ok(pFD->memid == 0x60020000, "memid %08x\n", pFD->memid);
1281 ok(pFD->oVft == 5 * sizeof(void *), "oVft %d\n", pFD->oVft);
1282 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
1284 ITypeInfo_Release(pTI);
1287 /* ItestIF4 is a syntax 1 dispinterface */
1288 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF4, &pTI);
1289 ok(hr == S_OK, "hr %08x\n", hr);
1291 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
1292 ok(hr == S_OK, "hr %08x\n", hr);
1293 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
1294 ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
1295 ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
1296 ok(pTA->cFuncs == 1, "cfuncs %d\n", pTA->cFuncs);
1297 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
1298 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
1300 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
1301 ok(hr == S_OK, "hr %08x\n", hr);
1302 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
1303 ok(hr == S_OK, "hr %08x\n", hr);
1304 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
1305 ok(hr == S_OK, "got %08x\n", hr);
1306 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
1307 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
1308 ITypeInfo_Release(pTI_p);
1309 hr = ITypeInfo_GetFuncDesc(pTI, 1, &pFD);
1310 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
1311 hr = ITypeInfo_GetFuncDesc(pTI, 0, &pFD);
1312 ok(hr == S_OK, "hr %08x\n", hr);
1313 ok(pFD->memid == 0x1c, "memid %08x\n", pFD->memid);
1314 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
1315 ITypeInfo_Release(pTI);
1318 /* ItestIF5 is dual with inherited ifaces which derive from IUnknown but not IDispatch */
1319 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &IID_ItestIF5, &pTI);
1320 ok(hr == S_OK, "hr %08x\n", hr);
1322 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
1323 ok(hr == S_OK, "hr %08x\n", hr);
1324 if (hr == S_OK)
1326 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
1327 ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
1328 if(use_midl_tlb) {
1329 ok(pTA->wTypeFlags == TYPEFLAG_FDUAL, "typeflags %x\n", pTA->wTypeFlags);
1331 ok(pTA->cFuncs == 8, "cfuncs %d\n", pTA->cFuncs);
1332 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
1333 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
1335 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
1336 ok(hr == S_OK, "hr %08x\n", hr);
1337 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
1338 ok(hr == S_OK, "hr %08x\n", hr);
1339 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
1340 ok(hr == S_OK, "got %08x\n", hr);
1341 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
1342 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
1343 ITypeInfo_Release(pTI_p);
1344 if(use_midl_tlb) {
1345 hr = ITypeInfo_GetFuncDesc(pTI, 6, &pFD);
1346 ok(hr == S_OK, "hr %08x\n", hr);
1347 ok(pFD->memid == 0x1234, "memid %08x\n", pFD->memid);
1348 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
1350 ITypeInfo_Release(pTI);
1352 /* ItestIF7 is dual with inherited ifaces which derive from Dispatch */
1353 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &IID_ItestIF7, &pTI);
1354 ok(hr == S_OK, "hr %08x\n", hr);
1356 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
1357 ok(hr == S_OK, "hr %08x\n", hr);
1358 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
1359 ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
1360 ok(pTA->wTypeFlags == (TYPEFLAG_FDISPATCHABLE|TYPEFLAG_FDUAL), "typeflags %x\n", pTA->wTypeFlags);
1361 ok(pTA->cFuncs == 10, "cfuncs %d\n", pTA->cFuncs);
1362 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
1363 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
1365 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
1366 ok(hr == S_OK, "hr %08x\n", hr);
1367 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
1368 ok(hr == S_OK, "hr %08x\n", hr);
1369 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
1370 ok(hr == S_OK, "got %08x\n", hr);
1371 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
1372 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
1373 ITypeInfo_Release(pTI_p);
1375 hr = ITypeInfo_GetFuncDesc(pTI, 9, &pFD);
1376 ok(hr == S_OK, "hr %08x\n", hr);
1377 ok(pFD->memid == 0x1236, "memid %08x\n", pFD->memid);
1378 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
1379 ITypeInfo_Release(pTI);
1381 /* ItestIF10 is a syntax 2 dispinterface which doesn't derive from IUnknown */
1382 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF10, &pTI);
1383 ok(hr == S_OK, "hr %08x\n", hr);
1385 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
1386 ok(hr == S_OK, "hr %08x\n", hr);
1387 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
1388 ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
1389 ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
1390 if(use_midl_tlb) {
1391 ok(pTA->cFuncs == 3, "cfuncs %d\n", pTA->cFuncs);
1392 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
1394 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
1396 if(use_midl_tlb) {
1397 hr = ITypeInfo_GetRefTypeOfImplType(pTI, -1, &href);
1398 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
1399 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
1400 ok(hr == S_OK, "hr %08x\n", hr);
1401 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
1402 ok(hr == S_OK, "hr %08x\n", hr);
1403 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
1404 ok(hr == S_OK, "got %08x\n", hr);
1405 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
1406 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
1407 ITypeInfo_Release(pTI_p);
1409 /* Should have three methods */
1410 hr = ITypeInfo_GetFuncDesc(pTI, 3, &pFD);
1411 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
1412 hr = ITypeInfo_GetFuncDesc(pTI, 2, &pFD);
1413 ok(hr == S_OK, "hr %08x\n", hr);
1414 ok(pFD->memid == 0x60010000, "memid %08x\n", pFD->memid);
1415 ok(pFD->oVft == 2 * sizeof(void *), "oVft %d\n", pFD->oVft);
1416 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
1418 ITypeInfo_Release(pTI);
1420 /* ItestIF11 is a syntax 2 dispinterface which derives from IDispatch */
1421 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &DIID_ItestIF11, &pTI);
1422 ok(hr == S_OK, "hr %08x\n", hr);
1424 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
1425 ok(hr == S_OK, "hr %08x\n", hr);
1426 ok(pTA->typekind == TKIND_DISPATCH, "kind %04x\n", pTA->typekind);
1427 ok(pTA->cbSizeVft == 7 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
1428 ok(pTA->wTypeFlags == TYPEFLAG_FDISPATCHABLE, "typeflags %x\n", pTA->wTypeFlags);
1429 if(use_midl_tlb) {
1430 ok(pTA->cFuncs == 10, "cfuncs %d\n", pTA->cFuncs);
1431 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
1433 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
1435 if(use_midl_tlb) {
1436 hr = ITypeInfo_GetRefTypeOfImplType(pTI, 0, &href);
1437 ok(hr == S_OK, "hr %08x\n", hr);
1438 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
1439 ok(hr == S_OK, "hr %08x\n", hr);
1440 hr = ITypeInfo_GetTypeAttr(pTI_p, &pTA);
1441 ok(hr == S_OK, "got %08x\n", hr);
1442 ok(IsEqualGUID(&pTA->guid, &IID_IDispatch), "guid {%08x-....\n", pTA->guid.Data1);
1443 ITypeInfo_ReleaseTypeAttr(pTI_p, pTA);
1444 ITypeInfo_Release(pTI_p);
1446 /* Should have ten methods */
1447 hr = ITypeInfo_GetFuncDesc(pTI, 10, &pFD);
1448 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
1449 hr = ITypeInfo_GetFuncDesc(pTI, 9, &pFD);
1450 ok(hr == S_OK, "hr %08x\n", hr);
1451 ok(pFD->memid == 0x1236, "memid %08x\n", pFD->memid);
1452 ok(pFD->oVft == 9 * sizeof(void *), "oVft %d\n", pFD->oVft);
1454 /* first argument to 10th function is an HREFTYPE from the impl type */
1455 ok(pFD->cParams == 1, "cParams %i\n", pFD->cParams);
1456 ok(pFD->lprgelemdescParam[0].tdesc.vt == VT_USERDEFINED,
1457 "vt 0x%x\n", pFD->lprgelemdescParam[0].tdesc.vt);
1458 href = U(pFD->lprgelemdescParam[0].tdesc).hreftype;
1459 ok((href & 0xff000000) == 0x04000000, "href 0x%08x\n", href);
1460 hr = ITypeInfo_GetRefTypeInfo(pTI, href, &pTI_p);
1461 ok(hr == S_OK, "hr %08x\n", hr);
1462 if (SUCCEEDED(hr)) ITypeInfo_Release(pTI_p);
1463 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
1465 ITypeInfo_Release(pTI);
1468 /* ItestIF2 is an interface which derives from IUnknown */
1469 hr = ITypeLib_GetTypeInfoOfGuid(pTL, &IID_ItestIF2, &pTI);
1470 ok(hr == S_OK, "hr %08x\n", hr);
1472 hr = ITypeInfo_GetTypeAttr(pTI, &pTA);
1473 ok(hr == S_OK, "hr %08x\n", hr);
1474 ok(pTA->typekind == TKIND_INTERFACE, "kind %04x\n", pTA->typekind);
1475 ok(pTA->cbSizeVft == 6 * sizeof(void *), "sizevft %d\n", pTA->cbSizeVft);
1476 ok(pTA->wTypeFlags == 0, "typeflags %x\n", pTA->wTypeFlags);
1477 if(use_midl_tlb) {
1478 ok(pTA->cFuncs == 1, "cfuncs %d\n", pTA->cFuncs);
1479 ok(pTA->cImplTypes == 1, "cimpltypes %d\n", pTA->cImplTypes);
1481 ITypeInfo_ReleaseTypeAttr(pTI, pTA);
1483 if(use_midl_tlb) {
1484 /* Should have one method */
1485 hr = ITypeInfo_GetFuncDesc(pTI, 1, &pFD);
1486 ok(hr == TYPE_E_ELEMENTNOTFOUND, "hr %08x\n", hr);
1487 hr = ITypeInfo_GetFuncDesc(pTI, 0, &pFD);
1488 ok(hr == S_OK, "hr %08x\n", hr);
1489 ok(pFD->memid == 0x60020000, "memid %08x\n", pFD->memid);
1490 ok(pFD->oVft == 5 * sizeof(void *), "oVft %d\n", pFD->oVft);
1491 ITypeInfo_ReleaseFuncDesc(pTI, pFD);
1493 ITypeInfo_Release(pTI);
1495 ITypeLib_Release(pTL);
1497 return;
1500 static void test_CreateTypeLib(void) {
1501 static const WCHAR stdoleW[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
1502 static OLECHAR typelibW[] = {'t','y','p','e','l','i','b',0};
1503 static OLECHAR helpfileW[] = {'C',':','\\','b','o','g','u','s','.','h','l','p',0};
1504 static OLECHAR interface1W[] = {'i','n','t','e','r','f','a','c','e','1',0};
1505 static OLECHAR interface2W[] = {'i','n','t','e','r','f','a','c','e','2',0};
1506 static OLECHAR interface3W[] = {'i','n','t','e','r','f','a','c','e','3',0};
1507 static OLECHAR dualW[] = {'d','u','a','l',0};
1508 static OLECHAR coclassW[] = {'c','o','c','l','a','s','s',0};
1509 static WCHAR defaultW[] = {'d','e','f','a','u','l','t',0x3213,0};
1510 static WCHAR defaultQW[] = {'d','e','f','a','u','l','t','?',0};
1511 static OLECHAR func1W[] = {'f','u','n','c','1',0};
1512 static OLECHAR func2W[] = {'f','u','n','c','2',0};
1513 static OLECHAR prop1W[] = {'P','r','o','p','1',0};
1514 static OLECHAR param1W[] = {'p','a','r','a','m','1',0};
1515 static OLECHAR param2W[] = {'p','a','r','a','m','2',0};
1516 static OLECHAR asdfW[] = {'A','s','d','f',0};
1517 static OLECHAR *names1[] = {func1W, param1W, param2W};
1518 static OLECHAR *names2[] = {func2W, param1W, param2W};
1519 static OLECHAR *propname[] = {prop1W, param1W};
1520 static const GUID custguid = {0xbf611abe,0x5b38,0x11df,{0x91,0x5c,0x08,0x02,0x79,0x79,0x94,0x70}};
1521 static const GUID bogusguid = {0xbf611abe,0x5b38,0x11df,{0x91,0x5c,0x08,0x02,0x79,0x79,0x94,0x71}};
1523 char filename[MAX_PATH];
1524 WCHAR filenameW[MAX_PATH];
1525 ICreateTypeLib2 *createtl;
1526 ICreateTypeInfo *createti;
1527 ICreateTypeInfo2 *createti2;
1528 ITypeLib *tl, *stdole;
1529 ITypeInfo *interface1, *interface2, *dual, *unknown, *dispatch, *ti;
1530 ITypeInfo2 *ti2;
1531 FUNCDESC funcdesc, *pfuncdesc;
1532 ELEMDESC elemdesc[5], *edesc;
1533 PARAMDESCEX paramdescex;
1534 TYPEDESC typedesc1, typedesc2;
1535 TYPEATTR *typeattr;
1536 TLIBATTR *libattr;
1537 HREFTYPE hreftype;
1538 BSTR name, docstring, helpfile;
1539 DWORD helpcontext;
1540 int impltypeflags;
1541 VARIANT cust_data;
1542 HRESULT hres;
1543 TYPEKIND kind;
1545 trace("CreateTypeLib tests\n");
1547 hres = LoadTypeLib(stdoleW, &stdole);
1548 ok(hres == S_OK, "got %08x\n", hres);
1550 hres = ITypeLib_GetTypeInfoOfGuid(stdole, &IID_IUnknown, &unknown);
1551 ok(hres == S_OK, "got %08x\n", hres);
1553 hres = ITypeLib_GetTypeInfoOfGuid(stdole, &IID_IDispatch, &dispatch);
1554 ok(hres == S_OK, "got %08x\n", hres);
1556 GetTempFileNameA(".", "tlb", 0, filename);
1557 MultiByteToWideChar(CP_ACP, 0, filename, -1, filenameW, MAX_PATH);
1559 hres = CreateTypeLib2(SYS_WIN32, filenameW, &createtl);
1560 ok(hres == S_OK, "got %08x\n", hres);
1562 hres = ICreateTypeLib2_QueryInterface(createtl, &IID_ITypeLib, (void**)&tl);
1563 ok(hres == S_OK, "got %08x\n", hres);
1565 hres = ITypeLib_GetTypeInfo(tl, 0, NULL);
1566 ok(hres == E_INVALIDARG, "got 0x%08x\n", hres);
1568 hres = ITypeLib_GetTypeInfoType(tl, 0, &kind);
1569 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got 0x%08x\n", hres);
1571 hres = ITypeLib_GetTypeInfoType(tl, 0, NULL);
1572 ok(hres == E_INVALIDARG, "got 0x%08x\n", hres);
1574 hres = ITypeLib_GetTypeInfoType(tl, 0, NULL);
1575 ok(hres == E_INVALIDARG, "got 0x%08x\n", hres);
1577 hres = ITypeLib_GetLibAttr(tl, NULL);
1578 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1580 hres = ITypeLib_GetLibAttr(tl, &libattr);
1581 ok(hres == S_OK, "got %08x\n", hres);
1583 ok(libattr->syskind == SYS_WIN32, "syskind = %d\n", libattr->syskind);
1584 ok(libattr->wMajorVerNum == 0, "wMajorVer = %d\n", libattr->wMajorVerNum);
1585 ok(libattr->wMinorVerNum == 0, "wMinorVerNum = %d\n", libattr->wMinorVerNum);
1586 ok(libattr->wLibFlags == 0, "wLibFlags = %d\n", libattr->wLibFlags);
1588 ITypeLib_ReleaseTLibAttr(tl, libattr);
1590 name = (BSTR)0xdeadbeef;
1591 hres = ITypeLib_GetDocumentation(tl, -1, &name, &docstring, &helpcontext, &helpfile);
1592 ok(hres == S_OK, "got %08x\n", hres);
1593 ok(name == NULL, "name != NULL\n");
1594 ok(docstring == NULL, "docstring != NULL\n");
1595 ok(helpcontext == 0, "helpcontext != 0\n");
1596 ok(helpfile == NULL, "helpfile != NULL\n");
1598 hres = ITypeLib_GetDocumentation(tl, 0, &name, NULL, NULL, NULL);
1599 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1601 hres = ICreateTypeLib2_SetName(createtl, typelibW);
1602 ok(hres == S_OK, "got %08x\n", hres);
1604 hres = ICreateTypeLib2_SetHelpFileName(createtl, helpfileW);
1605 ok(hres == S_OK, "got %08x\n", hres);
1607 hres = ITypeLib_GetDocumentation(tl, -1, NULL, NULL, NULL, NULL);
1608 ok(hres == S_OK, "got %08x\n", hres);
1610 hres = ITypeLib_GetDocumentation(tl, -1, &name, NULL, NULL, &helpfile);
1611 ok(hres == S_OK, "got %08x\n", hres);
1612 ok(!memcmp(name, typelibW, sizeof(typelibW)), "name = %s\n", wine_dbgstr_w(name));
1613 ok(!memcmp(helpfile, helpfileW, sizeof(helpfileW)), "helpfile = %s\n", wine_dbgstr_w(helpfile));
1615 SysFreeString(name);
1616 SysFreeString(helpfile);
1618 /* invalid parameters */
1619 hres = ICreateTypeLib2_CreateTypeInfo(createtl, NULL, TKIND_INTERFACE, &createti);
1620 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1622 hres = ICreateTypeLib2_CreateTypeInfo(createtl, interface1W, TKIND_INTERFACE, NULL);
1623 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1625 hres = ICreateTypeLib2_CreateTypeInfo(createtl, NULL, TKIND_INTERFACE, NULL);
1626 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1628 hres = ICreateTypeLib2_CreateTypeInfo(createtl, interface1W, TKIND_INTERFACE, &createti);
1629 ok(hres == S_OK, "got %08x\n", hres);
1631 hres = ICreateTypeInfo_QueryInterface(createti, &IID_ITypeInfo, (void**)&interface1);
1632 ok(hres == S_OK, "got %08x\n", hres);
1634 hres = ITypeLib_GetDocumentation(tl, 0, &name, NULL, NULL, NULL);
1635 ok(hres == S_OK, "got %08x\n", hres);
1636 ok(!memcmp(name, interface1W, sizeof(interface1W)), "name = %s\n", wine_dbgstr_w(name));
1638 SysFreeString(name);
1640 ITypeLib_Release(tl);
1642 name = (BSTR)0xdeadbeef;
1643 helpfile = (BSTR)0xdeadbeef;
1644 hres = ITypeInfo_GetDocumentation(interface1, -1, &name, &docstring, &helpcontext, &helpfile);
1645 ok(hres == S_OK, "got %08x\n", hres);
1646 ok(!memcmp(name, interface1W, sizeof(interface1W)), "name = %s\n", wine_dbgstr_w(name));
1647 ok(docstring == NULL, "docstring != NULL\n");
1648 ok(helpcontext == 0, "helpcontext != 0\n");
1649 ok(!memcmp(helpfile, helpfileW, sizeof(helpfileW)), "helpfile = %s\n", wine_dbgstr_w(helpfile));
1651 SysFreeString(name);
1652 SysFreeString(helpfile);
1654 hres = ITypeInfo_GetDocumentation(interface1, 0, &name, NULL, NULL, NULL);
1655 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1657 hres = ITypeInfo_GetRefTypeInfo(interface1, 0, NULL);
1658 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1661 hres = ICreateTypeInfo_LayOut(createti);
1662 ok(hres == S_OK, "got %08x\n", hres);
1664 hres = ICreateTypeInfo_AddRefTypeInfo(createti, NULL, &hreftype);
1665 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1667 hres = ICreateTypeInfo_AddRefTypeInfo(createti, unknown, NULL);
1668 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1670 hres = ICreateTypeInfo_AddRefTypeInfo(createti, unknown, &hreftype);
1671 ok(hres == S_OK, "got %08x\n", hres);
1672 if(hres != S_OK) {
1673 skip("Skipping some tests\n");
1674 return;
1677 hres = ICreateTypeInfo_AddImplType(createti, 1, hreftype);
1678 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1680 hres = ICreateTypeInfo_AddImplType(createti, 0, hreftype);
1681 ok(hres == S_OK, "got %08x\n", hres);
1683 hres = ITypeInfo_GetRefTypeOfImplType(interface1, 0, &hreftype);
1684 ok(hres == S_OK, "got %08x\n", hres);
1685 ok(hreftype == 3, "hreftype = %d\n", hreftype);
1687 hres = ITypeInfo_GetRefTypeOfImplType(interface1, -1, &hreftype);
1688 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1690 ICreateTypeInfo_QueryInterface(createti, &IID_ITypeInfo2, (void**)&ti2);
1692 memset(&funcdesc, 0, sizeof(FUNCDESC));
1693 funcdesc.funckind = FUNC_PUREVIRTUAL;
1694 funcdesc.invkind = INVOKE_PROPERTYGET;
1695 funcdesc.callconv = CC_STDCALL;
1696 funcdesc.elemdescFunc.tdesc.vt = VT_BSTR;
1697 U(funcdesc.elemdescFunc).idldesc.wIDLFlags = IDLFLAG_NONE;
1699 hres = ICreateTypeInfo_AddFuncDesc(createti, 0, NULL);
1700 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1702 hres = ICreateTypeInfo_AddFuncDesc(createti, 1, &funcdesc);
1703 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1705 hres = ICreateTypeInfo_AddFuncDesc(createti, 0, &funcdesc);
1706 ok(hres == S_OK, "got %08x\n", hres);
1708 hres = ITypeInfo2_GetFuncDesc(ti2, 0, NULL);
1709 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1711 hres = ITypeInfo2_GetFuncDesc(ti2, 1, &pfuncdesc);
1712 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1714 hres = ITypeInfo2_GetFuncDesc(ti2, 0, &pfuncdesc);
1715 ok(hres == S_OK, "got %08x\n", hres);
1717 ok(pfuncdesc->memid == 0, "got %x\n", pfuncdesc->memid);
1718 ok(pfuncdesc->lprgscode == NULL, "got %p\n", pfuncdesc->lprgscode);
1719 ok(pfuncdesc->lprgelemdescParam == NULL, "got %p\n", pfuncdesc->lprgelemdescParam);
1720 ok(pfuncdesc->funckind == FUNC_PUREVIRTUAL, "got 0x%x\n", pfuncdesc->funckind);
1721 ok(pfuncdesc->invkind == INVOKE_PROPERTYGET, "got 0x%x\n", pfuncdesc->invkind);
1722 ok(pfuncdesc->callconv == CC_STDCALL, "got 0x%x\n", pfuncdesc->callconv);
1723 ok(pfuncdesc->cParams == 0, "got %d\n", pfuncdesc->cParams);
1724 ok(pfuncdesc->cParamsOpt == 0, "got %d\n", pfuncdesc->cParamsOpt);
1725 ok(pfuncdesc->oVft == 12 || broken(pfuncdesc->oVft == 24) /* xp64 */,
1726 "got %d\n", pfuncdesc->oVft);
1727 ok(pfuncdesc->cScodes == 0, "got %d\n", pfuncdesc->cScodes);
1728 ok(pfuncdesc->elemdescFunc.tdesc.vt == VT_BSTR, "got %d\n", pfuncdesc->elemdescFunc.tdesc.vt);
1729 ok(pfuncdesc->wFuncFlags == 0, "got 0x%x\n", pfuncdesc->wFuncFlags);
1731 ITypeInfo2_ReleaseFuncDesc(ti2, pfuncdesc);
1733 hres = ICreateTypeInfo_SetFuncHelpContext(createti, 0, 0xabcdefab);
1734 ok(hres == S_OK, "got %08x\n", hres);
1736 funcdesc.invkind = INVOKE_PROPERTYPUT;
1737 hres = ICreateTypeInfo_AddFuncDesc(createti, 1, &funcdesc);
1738 ok(hres == TYPE_E_INCONSISTENTPROPFUNCS, "got %08x\n", hres);
1740 funcdesc.invkind = INVOKE_PROPERTYPUTREF;
1741 hres = ICreateTypeInfo_AddFuncDesc(createti, 1, &funcdesc);
1742 ok(hres == TYPE_E_INCONSISTENTPROPFUNCS, "got %08x\n", hres);
1744 elemdesc[0].tdesc.vt = VT_BSTR;
1745 U(elemdesc[0]).idldesc.dwReserved = 0;
1746 U(elemdesc[0]).idldesc.wIDLFlags = IDLFLAG_FIN;
1748 funcdesc.lprgelemdescParam = elemdesc;
1749 funcdesc.invkind = INVOKE_PROPERTYPUT;
1750 funcdesc.cParams = 1;
1751 funcdesc.elemdescFunc.tdesc.vt = VT_VOID;
1753 hres = ICreateTypeInfo_AddFuncDesc(createti, 1, &funcdesc);
1754 ok(hres == S_OK, "got %08x\n", hres);
1756 hres = ICreateTypeInfo_SetFuncHelpContext(createti, 1, 0xabcdefab);
1757 ok(hres == S_OK, "got %08x\n", hres);
1759 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 0, propname, 0);
1760 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1762 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 0, NULL, 1);
1763 ok(hres == E_INVALIDARG, "got %08x\n", hres);
1765 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 0, propname, 1);
1766 ok(hres == S_OK, "got %08x\n", hres);
1768 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 1, propname, 1);
1769 ok(hres == S_OK, "got %08x\n", hres);
1771 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 1, propname, 2);
1772 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
1774 hres = ITypeInfo2_GetFuncDesc(ti2, 1, &pfuncdesc);
1775 ok(hres == S_OK, "got %08x\n", hres);
1777 ok(pfuncdesc->memid == 0, "got %x\n", pfuncdesc->memid);
1778 ok(pfuncdesc->lprgscode == NULL, "got %p\n", pfuncdesc->lprgscode);
1779 ok(pfuncdesc->lprgelemdescParam != NULL, "got %p\n", pfuncdesc->lprgelemdescParam);
1780 ok(pfuncdesc->funckind == FUNC_PUREVIRTUAL, "got 0x%x\n", pfuncdesc->funckind);
1781 ok(pfuncdesc->invkind == INVOKE_PROPERTYPUT, "got 0x%x\n", pfuncdesc->invkind);
1782 ok(pfuncdesc->callconv == CC_STDCALL, "got 0x%x\n", pfuncdesc->callconv);
1783 ok(pfuncdesc->cParams == 1, "got %d\n", pfuncdesc->cParams);
1784 ok(pfuncdesc->cParamsOpt == 0, "got %d\n", pfuncdesc->cParamsOpt);
1785 ok(pfuncdesc->oVft == 16 || broken(pfuncdesc->oVft == 28) /* xp64 */,
1786 "got %d\n", pfuncdesc->oVft);
1787 ok(pfuncdesc->cScodes == 0, "got %d\n", pfuncdesc->cScodes);
1788 ok(pfuncdesc->elemdescFunc.tdesc.vt == VT_VOID, "got %d\n", pfuncdesc->elemdescFunc.tdesc.vt);
1789 ok(pfuncdesc->wFuncFlags == 0, "got 0x%x\n", pfuncdesc->wFuncFlags);
1791 edesc = pfuncdesc->lprgelemdescParam;
1792 ok(edesc->tdesc.vt == VT_BSTR, "got: %d\n", edesc->tdesc.vt);
1793 ok(U(*edesc).idldesc.wIDLFlags == IDLFLAG_FIN, "got: %x\n", U(*edesc).idldesc.wIDLFlags);
1795 ITypeInfo2_ReleaseFuncDesc(ti2, pfuncdesc);
1798 funcdesc.invkind = INVOKE_PROPERTYPUTREF;
1799 hres = ICreateTypeInfo_AddFuncDesc(createti, 0, &funcdesc);
1800 ok(hres == S_OK, "got %08x\n", hres);
1802 hres = ICreateTypeInfo_SetFuncHelpContext(createti, 0, 0xabcdefab);
1803 ok(hres == S_OK, "got %08x\n", hres);
1805 hres = ICreateTypeInfo_SetFuncHelpContext(createti, 0, 0x201);
1806 ok(hres == S_OK, "got %08x\n", hres);
1808 funcdesc.memid = 1;
1809 funcdesc.lprgelemdescParam = NULL;
1810 funcdesc.invkind = INVOKE_FUNC;
1811 funcdesc.cParams = 0;
1812 hres = ICreateTypeInfo_AddFuncDesc(createti, 1, &funcdesc);
1813 ok(hres == S_OK, "got %08x\n", hres);
1815 hres = ITypeInfo2_GetFuncDesc(ti2, 1, &pfuncdesc);
1816 ok(hres == S_OK, "got %08x\n", hres);
1818 ok(pfuncdesc->memid == 1, "got %d\n", pfuncdesc->memid);
1819 ok(pfuncdesc->lprgscode == NULL, "got %p\n", pfuncdesc->lprgscode);
1820 ok(pfuncdesc->lprgelemdescParam == NULL, "got %p\n", pfuncdesc->lprgelemdescParam);
1821 ok(pfuncdesc->funckind == FUNC_PUREVIRTUAL, "got 0x%x\n", pfuncdesc->funckind);
1822 ok(pfuncdesc->invkind == INVOKE_FUNC, "got 0x%x\n", pfuncdesc->invkind);
1823 ok(pfuncdesc->callconv == CC_STDCALL, "got 0x%x\n", pfuncdesc->callconv);
1824 ok(pfuncdesc->cParams == 0, "got %d\n", pfuncdesc->cParams);
1825 ok(pfuncdesc->cParamsOpt == 0, "got %d\n", pfuncdesc->cParamsOpt);
1826 ok(pfuncdesc->oVft == 16 || broken(pfuncdesc->oVft == 28), /* xp64 */
1827 "got %d\n", pfuncdesc->oVft);
1828 ok(pfuncdesc->cScodes == 0, "got %d\n", pfuncdesc->cScodes);
1829 ok(pfuncdesc->elemdescFunc.tdesc.vt == VT_VOID, "got %d\n", pfuncdesc->elemdescFunc.tdesc.vt);
1830 ok(pfuncdesc->wFuncFlags == 0, "got 0x%x\n", pfuncdesc->wFuncFlags);
1832 ITypeInfo2_ReleaseFuncDesc(ti2, pfuncdesc);
1834 funcdesc.memid = MEMBERID_NIL;
1835 hres = ICreateTypeInfo_AddFuncDesc(createti, 1, &funcdesc);
1836 ok(hres == S_OK, "got %08x\n", hres);
1838 elemdesc[0].tdesc.vt = VT_PTR;
1839 U(elemdesc[0].tdesc).lptdesc = &typedesc1;
1840 typedesc1.vt = VT_BSTR;
1841 funcdesc.cParams = 1;
1842 funcdesc.lprgelemdescParam = elemdesc;
1843 hres = ICreateTypeInfo_AddFuncDesc(createti, 4, &funcdesc);
1844 ok(hres == S_OK, "got %08x\n", hres);
1846 hres = ITypeInfo2_GetFuncDesc(ti2, 4, &pfuncdesc);
1847 ok(hres == S_OK, "got %08x\n", hres);
1849 ok(pfuncdesc->memid == 0x60010004, "got %x\n", pfuncdesc->memid);
1850 ok(pfuncdesc->lprgscode == NULL, "got %p\n", pfuncdesc->lprgscode);
1851 ok(pfuncdesc->lprgelemdescParam != NULL, "got %p\n", pfuncdesc->lprgelemdescParam);
1852 ok(pfuncdesc->funckind == FUNC_PUREVIRTUAL, "got 0x%x\n", pfuncdesc->funckind);
1853 ok(pfuncdesc->invkind == INVOKE_FUNC, "got 0x%x\n", pfuncdesc->invkind);
1854 ok(pfuncdesc->callconv == CC_STDCALL, "got 0x%x\n", pfuncdesc->callconv);
1855 ok(pfuncdesc->cParams == 1, "got %d\n", pfuncdesc->cParams);
1856 ok(pfuncdesc->cParamsOpt == 0, "got %d\n", pfuncdesc->cParamsOpt);
1857 ok(pfuncdesc->oVft == 28 || broken(pfuncdesc->oVft == 40) /* xp64 */,
1858 "got %d\n", pfuncdesc->oVft);
1859 ok(pfuncdesc->cScodes == 0, "got %d\n", pfuncdesc->cScodes);
1860 ok(pfuncdesc->elemdescFunc.tdesc.vt == VT_VOID, "got %d\n", pfuncdesc->elemdescFunc.tdesc.vt);
1861 ok(pfuncdesc->wFuncFlags == 0, "got 0x%x\n", pfuncdesc->wFuncFlags);
1863 edesc = pfuncdesc->lprgelemdescParam;
1864 ok(edesc->tdesc.vt == VT_PTR, "got: %d\n", edesc->tdesc.vt);
1865 ok(U(*edesc).paramdesc.wParamFlags == PARAMFLAG_FIN, "got: 0x%x\n", U(*edesc).paramdesc.wParamFlags);
1866 ok(U(*edesc).paramdesc.pparamdescex == NULL, "got: %p\n", U(*edesc).paramdesc.pparamdescex);
1867 ok(U(edesc->tdesc).lptdesc != NULL, "got: %p\n", U(edesc->tdesc).lptdesc);
1868 ok(U(edesc->tdesc).lptdesc->vt == VT_BSTR, "got: %d\n", U(edesc->tdesc).lptdesc->vt);
1870 ITypeInfo2_ReleaseFuncDesc(ti2, pfuncdesc);
1872 U(elemdesc[0].tdesc).lptdesc = &typedesc2;
1873 typedesc2.vt = VT_PTR;
1874 U(typedesc2).lptdesc = &typedesc1;
1875 hres = ICreateTypeInfo_AddFuncDesc(createti, 4, &funcdesc);
1876 ok(hres == S_OK, "got %08x\n", hres);
1878 hres = ITypeInfo2_GetFuncDesc(ti2, 4, &pfuncdesc);
1879 ok(hres == S_OK, "got %08x\n", hres);
1881 ok(pfuncdesc->memid == 0x60010007, "got %x\n", pfuncdesc->memid);
1882 ok(pfuncdesc->lprgscode == NULL, "got %p\n", pfuncdesc->lprgscode);
1883 ok(pfuncdesc->lprgelemdescParam != NULL, "got %p\n", pfuncdesc->lprgelemdescParam);
1884 ok(pfuncdesc->funckind == FUNC_PUREVIRTUAL, "got 0x%x\n", pfuncdesc->funckind);
1885 ok(pfuncdesc->invkind == INVOKE_FUNC, "got 0x%x\n", pfuncdesc->invkind);
1886 ok(pfuncdesc->callconv == CC_STDCALL, "got 0x%x\n", pfuncdesc->callconv);
1887 ok(pfuncdesc->cParams == 1, "got %d\n", pfuncdesc->cParams);
1888 ok(pfuncdesc->cParamsOpt == 0, "got %d\n", pfuncdesc->cParamsOpt);
1889 ok(pfuncdesc->oVft == 28 || broken(pfuncdesc->oVft == 40) /* xp64 */,
1890 "got %d\n", pfuncdesc->oVft);
1891 ok(pfuncdesc->cScodes == 0, "got %d\n", pfuncdesc->cScodes);
1892 ok(pfuncdesc->elemdescFunc.tdesc.vt == VT_VOID, "got %d\n", pfuncdesc->elemdescFunc.tdesc.vt);
1893 ok(pfuncdesc->wFuncFlags == 0, "got 0x%x\n", pfuncdesc->wFuncFlags);
1895 edesc = pfuncdesc->lprgelemdescParam;
1896 ok(edesc->tdesc.vt == VT_PTR, "got: %d\n", edesc->tdesc.vt);
1897 ok(U(*edesc).paramdesc.wParamFlags == PARAMFLAG_FIN, "got: 0x%x\n", U(*edesc).paramdesc.wParamFlags);
1898 ok(U(*edesc).paramdesc.pparamdescex == NULL, "got: %p\n", U(*edesc).paramdesc.pparamdescex);
1899 ok(U(edesc->tdesc).lptdesc != NULL, "got: %p\n", U(edesc->tdesc).lptdesc);
1900 ok(U(edesc->tdesc).lptdesc->vt == VT_PTR, "got: %d\n", U(edesc->tdesc).lptdesc->vt);
1901 ok(U(*U(edesc->tdesc).lptdesc).lptdesc != NULL, "got: %p\n", U(*U(edesc->tdesc).lptdesc).lptdesc);
1902 ok(U(*U(edesc->tdesc).lptdesc).lptdesc->vt == VT_BSTR, "got: %d\n", U(*U(edesc->tdesc).lptdesc).lptdesc->vt);
1904 ITypeInfo2_ReleaseFuncDesc(ti2, pfuncdesc);
1906 elemdesc[0].tdesc.vt = VT_INT;
1907 U(elemdesc[0]).paramdesc.wParamFlags = PARAMFLAG_FHASDEFAULT;
1908 U(elemdesc[0]).paramdesc.pparamdescex = &paramdescex;
1909 V_VT(&paramdescex.varDefaultValue) = VT_INT;
1910 V_INT(&paramdescex.varDefaultValue) = 0x123;
1911 hres = ICreateTypeInfo_AddFuncDesc(createti, 3, &funcdesc);
1912 ok(hres == S_OK, "got %08x\n", hres);
1914 hres = ITypeInfo2_GetFuncDesc(ti2, 3, &pfuncdesc);
1915 ok(hres == S_OK, "got %08x\n", hres);
1917 ok(pfuncdesc->memid == 0x60010003, "got %x\n", pfuncdesc->memid);
1918 ok(pfuncdesc->lprgscode == NULL, "got %p\n", pfuncdesc->lprgscode);
1919 ok(pfuncdesc->lprgelemdescParam != NULL, "got %p\n", pfuncdesc->lprgelemdescParam);
1920 ok(pfuncdesc->funckind == FUNC_PUREVIRTUAL, "got 0x%x\n", pfuncdesc->funckind);
1921 ok(pfuncdesc->invkind == INVOKE_FUNC, "got 0x%x\n", pfuncdesc->invkind);
1922 ok(pfuncdesc->callconv == CC_STDCALL, "got 0x%x\n", pfuncdesc->callconv);
1923 ok(pfuncdesc->cParams == 1, "got %d\n", pfuncdesc->cParams);
1924 ok(pfuncdesc->cParamsOpt == 0, "got %d\n", pfuncdesc->cParamsOpt);
1925 ok(pfuncdesc->oVft == 24 || broken(pfuncdesc->oVft == 36) /* xp64 */,
1926 "got %d\n", pfuncdesc->oVft);
1927 ok(pfuncdesc->cScodes == 0, "got %d\n", pfuncdesc->cScodes);
1928 ok(pfuncdesc->elemdescFunc.tdesc.vt == VT_VOID, "got %d\n", pfuncdesc->elemdescFunc.tdesc.vt);
1929 ok(pfuncdesc->wFuncFlags == 0, "got 0x%x\n", pfuncdesc->wFuncFlags);
1931 edesc = pfuncdesc->lprgelemdescParam;
1932 ok(edesc->tdesc.vt == VT_INT, "got: %d\n", edesc->tdesc.vt);
1933 ok(U(*edesc).paramdesc.wParamFlags == PARAMFLAG_FHASDEFAULT, "got: 0x%x\n", U(*edesc).paramdesc.wParamFlags);
1934 ok(U(*edesc).paramdesc.pparamdescex != NULL, "got: %p\n", U(*edesc).paramdesc.pparamdescex);
1935 ok(U(*edesc).paramdesc.pparamdescex->cBytes == sizeof(PARAMDESCEX), "got: %d\n",
1936 U(*edesc).paramdesc.pparamdescex->cBytes);
1937 ok(V_VT(&U(*edesc).paramdesc.pparamdescex->varDefaultValue) == VT_I4, "got: %d\n",
1938 V_VT(&U(*edesc).paramdesc.pparamdescex->varDefaultValue));
1939 ok(V_I4(&U(*edesc).paramdesc.pparamdescex->varDefaultValue) == 0x123, "got: 0x%x\n",
1940 V_I4(&U(*edesc).paramdesc.pparamdescex->varDefaultValue));
1942 ITypeInfo2_ReleaseFuncDesc(ti2, pfuncdesc);
1944 U(elemdesc[0]).idldesc.dwReserved = 0;
1945 U(elemdesc[0]).idldesc.wIDLFlags = IDLFLAG_FIN;
1946 elemdesc[1].tdesc.vt = VT_UI2;
1947 U(elemdesc[1]).paramdesc.wParamFlags = PARAMFLAG_FHASDEFAULT;
1948 U(elemdesc[1]).paramdesc.pparamdescex = &paramdescex;
1949 V_VT(&paramdescex.varDefaultValue) = VT_UI2;
1950 V_UI2(&paramdescex.varDefaultValue) = 0xffff;
1951 funcdesc.cParams = 2;
1952 hres = ICreateTypeInfo_AddFuncDesc(createti, 3, &funcdesc);
1953 ok(hres == S_OK, "got %08x\n", hres);
1955 hres = ITypeInfo2_GetFuncDesc(ti2, 3, &pfuncdesc);
1956 ok(hres == S_OK, "got %08x\n", hres);
1958 ok(pfuncdesc->memid == 0x60010009, "got %x\n", pfuncdesc->memid);
1959 ok(pfuncdesc->lprgscode == NULL, "got %p\n", pfuncdesc->lprgscode);
1960 ok(pfuncdesc->lprgelemdescParam != NULL, "got %p\n", pfuncdesc->lprgelemdescParam);
1961 ok(pfuncdesc->funckind == FUNC_PUREVIRTUAL, "got 0x%x\n", pfuncdesc->funckind);
1962 ok(pfuncdesc->invkind == INVOKE_FUNC, "got 0x%x\n", pfuncdesc->invkind);
1963 ok(pfuncdesc->callconv == CC_STDCALL, "got 0x%x\n", pfuncdesc->callconv);
1964 ok(pfuncdesc->cParams == 2, "got %d\n", pfuncdesc->cParams);
1965 ok(pfuncdesc->cParamsOpt == 0, "got %d\n", pfuncdesc->cParamsOpt);
1966 ok(pfuncdesc->oVft == 24 || broken(pfuncdesc->oVft == 36) /* xp64 */,
1967 "got %d\n", pfuncdesc->oVft);
1968 ok(pfuncdesc->cScodes == 0, "got %d\n", pfuncdesc->cScodes);
1969 ok(pfuncdesc->elemdescFunc.tdesc.vt == VT_VOID, "got %d\n", pfuncdesc->elemdescFunc.tdesc.vt);
1970 ok(pfuncdesc->wFuncFlags == 0, "got 0x%x\n", pfuncdesc->wFuncFlags);
1972 edesc = pfuncdesc->lprgelemdescParam;
1973 ok(edesc->tdesc.vt == VT_INT, "got: %d\n", edesc->tdesc.vt);
1974 ok(U(*edesc).paramdesc.wParamFlags == PARAMFLAG_FIN, "got: 0x%x\n", U(*edesc).paramdesc.wParamFlags);
1975 ok(U(*edesc).paramdesc.pparamdescex == NULL, "got: %p\n", U(*edesc).paramdesc.pparamdescex);
1977 edesc = pfuncdesc->lprgelemdescParam + 1;
1978 ok(edesc->tdesc.vt == VT_UI2, "got: %d\n", edesc->tdesc.vt);
1979 ok(U(*edesc).paramdesc.wParamFlags == PARAMFLAG_FHASDEFAULT, "got: 0x%x\n", U(*edesc).paramdesc.wParamFlags);
1980 ok(U(*edesc).paramdesc.pparamdescex != NULL, "got: %p\n", U(*edesc).paramdesc.pparamdescex);
1981 ok(U(*edesc).paramdesc.pparamdescex->cBytes == sizeof(PARAMDESCEX), "got: %d\n",
1982 U(*edesc).paramdesc.pparamdescex->cBytes);
1983 ok(V_VT(&U(*edesc).paramdesc.pparamdescex->varDefaultValue) == VT_UI2, "got: %d\n",
1984 V_VT(&U(*edesc).paramdesc.pparamdescex->varDefaultValue));
1985 ok(V_UI2(&U(*edesc).paramdesc.pparamdescex->varDefaultValue) == 0xFFFF, "got: 0x%x\n",
1986 V_UI2(&U(*edesc).paramdesc.pparamdescex->varDefaultValue));
1988 ITypeInfo2_ReleaseFuncDesc(ti2, pfuncdesc);
1990 U(elemdesc[0]).paramdesc.wParamFlags = PARAMFLAG_FHASDEFAULT;
1991 U(elemdesc[0]).paramdesc.pparamdescex = &paramdescex;
1992 elemdesc[1].tdesc.vt = VT_INT;
1993 V_VT(&paramdescex.varDefaultValue) = VT_INT;
1994 V_INT(&paramdescex.varDefaultValue) = 0xffffffff;
1995 hres = ICreateTypeInfo_AddFuncDesc(createti, 3, &funcdesc);
1996 ok(hres == S_OK, "got %08x\n", hres);
1998 elemdesc[0].tdesc.vt = VT_BSTR;
1999 elemdesc[1].tdesc.vt = VT_BSTR;
2000 V_VT(&paramdescex.varDefaultValue) = VT_BSTR;
2001 V_BSTR(&paramdescex.varDefaultValue) = SysAllocString(defaultW);
2002 hres = ICreateTypeInfo_AddFuncDesc(createti, 3, &funcdesc);
2003 ok(hres == S_OK, "got %08x\n", hres);
2004 SysFreeString(V_BSTR(&paramdescex.varDefaultValue));
2006 hres = ITypeInfo2_GetFuncDesc(ti2, 3, &pfuncdesc);
2007 ok(hres == S_OK, "got %08x\n", hres);
2009 ok(pfuncdesc->memid == 0x6001000b, "got %x\n", pfuncdesc->memid);
2010 ok(pfuncdesc->lprgscode == NULL, "got %p\n", pfuncdesc->lprgscode);
2011 ok(pfuncdesc->lprgelemdescParam != NULL, "got %p\n", pfuncdesc->lprgelemdescParam);
2012 ok(pfuncdesc->funckind == FUNC_PUREVIRTUAL, "got 0x%x\n", pfuncdesc->funckind);
2013 ok(pfuncdesc->invkind == INVOKE_FUNC, "got 0x%x\n", pfuncdesc->invkind);
2014 ok(pfuncdesc->callconv == CC_STDCALL, "got 0x%x\n", pfuncdesc->callconv);
2015 ok(pfuncdesc->cParams == 2, "got %d\n", pfuncdesc->cParams);
2016 ok(pfuncdesc->cParamsOpt == 0, "got %d\n", pfuncdesc->cParamsOpt);
2017 ok(pfuncdesc->oVft == 24 || broken(pfuncdesc->oVft == 36) /* xp64 */,
2018 "got %d\n", pfuncdesc->oVft);
2019 ok(pfuncdesc->cScodes == 0, "got %d\n", pfuncdesc->cScodes);
2020 ok(pfuncdesc->elemdescFunc.tdesc.vt == VT_VOID, "got %d\n", pfuncdesc->elemdescFunc.tdesc.vt);
2021 ok(pfuncdesc->wFuncFlags == 0, "got 0x%x\n", pfuncdesc->wFuncFlags);
2023 edesc = pfuncdesc->lprgelemdescParam;
2024 ok(edesc->tdesc.vt == VT_BSTR, "got: %d\n", edesc->tdesc.vt);
2025 ok(U(*edesc).paramdesc.wParamFlags == PARAMFLAG_FHASDEFAULT, "got: 0x%x\n", U(*edesc).paramdesc.wParamFlags);
2026 ok(U(*edesc).paramdesc.pparamdescex != NULL, "got: %p\n", U(*edesc).paramdesc.pparamdescex);
2027 ok(U(*edesc).paramdesc.pparamdescex->cBytes == sizeof(PARAMDESCEX), "got: %d\n",
2028 U(*edesc).paramdesc.pparamdescex->cBytes);
2029 ok(V_VT(&U(*edesc).paramdesc.pparamdescex->varDefaultValue) == VT_BSTR, "got: %d\n",
2030 V_VT(&U(*edesc).paramdesc.pparamdescex->varDefaultValue));
2031 ok(!lstrcmpW(V_BSTR(&U(*edesc).paramdesc.pparamdescex->varDefaultValue), defaultQW),
2032 "got: %s\n",
2033 wine_dbgstr_w(V_BSTR(&U(*edesc).paramdesc.pparamdescex->varDefaultValue)));
2035 edesc = pfuncdesc->lprgelemdescParam + 1;
2036 ok(edesc->tdesc.vt == VT_BSTR, "got: %d\n", edesc->tdesc.vt);
2037 ok(U(*edesc).paramdesc.wParamFlags == PARAMFLAG_FHASDEFAULT, "got: 0x%x\n", U(*edesc).paramdesc.wParamFlags);
2038 ok(U(*edesc).paramdesc.pparamdescex != NULL, "got: %p\n", U(*edesc).paramdesc.pparamdescex);
2039 ok(U(*edesc).paramdesc.pparamdescex->cBytes == sizeof(PARAMDESCEX), "got: %d\n",
2040 U(*edesc).paramdesc.pparamdescex->cBytes);
2041 ok(V_VT(&U(*edesc).paramdesc.pparamdescex->varDefaultValue) == VT_BSTR, "got: %d\n",
2042 V_VT(&U(*edesc).paramdesc.pparamdescex->varDefaultValue));
2043 ok(!lstrcmpW(V_BSTR(&U(*edesc).paramdesc.pparamdescex->varDefaultValue), defaultQW),
2044 "got: %s\n",
2045 wine_dbgstr_w(V_BSTR(&U(*edesc).paramdesc.pparamdescex->varDefaultValue)));
2047 ITypeInfo2_ReleaseFuncDesc(ti2, pfuncdesc);
2049 elemdesc[0].tdesc.vt = VT_USERDEFINED;
2050 U(elemdesc[0].tdesc).hreftype = hreftype;
2051 U(elemdesc[0]).paramdesc.pparamdescex = &paramdescex;
2052 U(elemdesc[0]).paramdesc.wParamFlags = PARAMFLAG_FHASDEFAULT;
2053 V_VT(&paramdescex.varDefaultValue) = VT_INT;
2054 V_INT(&paramdescex.varDefaultValue) = 0x789;
2056 funcdesc.lprgelemdescParam = elemdesc;
2057 funcdesc.invkind = INVOKE_FUNC;
2058 funcdesc.cParams = 1;
2059 funcdesc.elemdescFunc.tdesc.vt = VT_VOID;
2061 hres = ICreateTypeInfo_AddFuncDesc(createti, 5, &funcdesc);
2062 ok(hres == S_OK, "got %08x\n", hres);
2064 hres = ITypeInfo2_GetFuncDesc(ti2, 5, &pfuncdesc);
2065 ok(hres == S_OK, "got %08x\n", hres);
2067 ok(pfuncdesc->memid == 0x60010005, "got %x\n", pfuncdesc->memid);
2068 ok(pfuncdesc->lprgscode == NULL, "got %p\n", pfuncdesc->lprgscode);
2069 ok(pfuncdesc->lprgelemdescParam != NULL, "got %p\n", pfuncdesc->lprgelemdescParam);
2070 ok(pfuncdesc->funckind == FUNC_PUREVIRTUAL, "got 0x%x\n", pfuncdesc->funckind);
2071 ok(pfuncdesc->invkind == INVOKE_FUNC, "got 0x%x\n", pfuncdesc->invkind);
2072 ok(pfuncdesc->callconv == CC_STDCALL, "got 0x%x\n", pfuncdesc->callconv);
2073 ok(pfuncdesc->cParams == 1, "got %d\n", pfuncdesc->cParams);
2074 ok(pfuncdesc->cParamsOpt == 0, "got %d\n", pfuncdesc->cParamsOpt);
2075 ok(pfuncdesc->oVft == 32 || broken(pfuncdesc->oVft == 44), /* xp64 */
2076 "got %d\n", pfuncdesc->oVft);
2077 ok(pfuncdesc->cScodes == 0, "got %d\n", pfuncdesc->cScodes);
2078 ok(pfuncdesc->elemdescFunc.tdesc.vt == VT_VOID, "got %d\n", pfuncdesc->elemdescFunc.tdesc.vt);
2079 ok(pfuncdesc->wFuncFlags == 0, "got 0x%x\n", pfuncdesc->wFuncFlags);
2081 edesc = pfuncdesc->lprgelemdescParam;
2082 ok(U(*edesc).paramdesc.pparamdescex != NULL, "got: %p\n", U(*edesc).paramdesc.pparamdescex);
2083 ok(U(*edesc).paramdesc.wParamFlags == PARAMFLAG_FHASDEFAULT,
2084 "got: 0x%x\n", U(*edesc).paramdesc.wParamFlags);
2085 ok(edesc->tdesc.vt == VT_USERDEFINED, "got: %d\n", edesc->tdesc.vt);
2086 ok(U(edesc->tdesc).hreftype == hreftype, "got: 0x%x\n", U(edesc->tdesc).hreftype);
2087 ok(V_VT(&U(*edesc).paramdesc.pparamdescex->varDefaultValue) == VT_INT, "got: %d\n",
2088 V_VT(&U(*edesc).paramdesc.pparamdescex->varDefaultValue));
2089 ok(V_INT(&U(*edesc).paramdesc.pparamdescex->varDefaultValue) == 0x789, "got: %d\n",
2090 V_INT(&U(*edesc).paramdesc.pparamdescex->varDefaultValue));
2092 ITypeInfo2_ReleaseFuncDesc(ti2, pfuncdesc);
2094 elemdesc[0].tdesc.vt = VT_VARIANT;
2095 U(elemdesc[0]).paramdesc.pparamdescex = &paramdescex;
2096 U(elemdesc[0]).paramdesc.wParamFlags = PARAMFLAG_FHASDEFAULT;
2097 V_VT(&paramdescex.varDefaultValue) = VT_INT;
2098 V_INT(&paramdescex.varDefaultValue) = 3;
2100 funcdesc.lprgelemdescParam = elemdesc;
2101 funcdesc.invkind = INVOKE_FUNC;
2102 funcdesc.cParams = 1;
2103 funcdesc.elemdescFunc.tdesc.vt = VT_VARIANT;
2105 hres = ICreateTypeInfo_AddFuncDesc(createti, 6, &funcdesc);
2106 ok(hres == S_OK, "got %08x\n", hres);
2108 hres = ITypeInfo2_GetFuncDesc(ti2, 6, &pfuncdesc);
2109 ok(hres == S_OK, "got %08x\n", hres);
2111 ok(pfuncdesc->memid == 0x60010006, "got %x\n", pfuncdesc->memid);
2112 ok(pfuncdesc->lprgscode == NULL, "got %p\n", pfuncdesc->lprgscode);
2113 ok(pfuncdesc->lprgelemdescParam != NULL, "got %p\n", pfuncdesc->lprgelemdescParam);
2114 ok(pfuncdesc->funckind == FUNC_PUREVIRTUAL, "got 0x%x\n", pfuncdesc->funckind);
2115 ok(pfuncdesc->invkind == INVOKE_FUNC, "got 0x%x\n", pfuncdesc->invkind);
2116 ok(pfuncdesc->callconv == CC_STDCALL, "got 0x%x\n", pfuncdesc->callconv);
2117 ok(pfuncdesc->cParams == 1, "got %d\n", pfuncdesc->cParams);
2118 ok(pfuncdesc->cParamsOpt == 0, "got %d\n", pfuncdesc->cParamsOpt);
2119 ok(pfuncdesc->oVft == 36 || broken(pfuncdesc->oVft == 48), /* xp64 */
2120 "got %d\n", pfuncdesc->oVft);
2121 ok(pfuncdesc->cScodes == 0, "got %d\n", pfuncdesc->cScodes);
2122 ok(pfuncdesc->elemdescFunc.tdesc.vt == VT_VARIANT, "got %d\n", pfuncdesc->elemdescFunc.tdesc.vt);
2123 ok(pfuncdesc->wFuncFlags == 0, "got 0x%x\n", pfuncdesc->wFuncFlags);
2125 edesc = pfuncdesc->lprgelemdescParam;
2126 ok(U(*edesc).paramdesc.pparamdescex != NULL, "got: %p\n", U(*edesc).paramdesc.pparamdescex);
2127 ok(U(*edesc).paramdesc.wParamFlags == PARAMFLAG_FHASDEFAULT,
2128 "got: 0x%x\n", U(*edesc).paramdesc.wParamFlags);
2129 ok(edesc->tdesc.vt == VT_VARIANT, "got: %d\n", edesc->tdesc.vt);
2130 ok(V_VT(&U(*edesc).paramdesc.pparamdescex->varDefaultValue) == VT_INT, "got: %d\n",
2131 V_VT(&U(*edesc).paramdesc.pparamdescex->varDefaultValue));
2132 ok(V_INT(&U(*edesc).paramdesc.pparamdescex->varDefaultValue) == 3, "got: %d\n",
2133 V_INT(&U(*edesc).paramdesc.pparamdescex->varDefaultValue));
2135 ITypeInfo2_ReleaseFuncDesc(ti2, pfuncdesc);
2137 hres = ITypeInfo_GetDocumentation(interface1, 0, &name, &docstring, &helpcontext, &helpfile);
2138 ok(hres == S_OK, "got %08x\n", hres);
2139 ok(name == NULL, "name != NULL\n");
2140 ok(docstring == NULL, "docstring != NULL\n");
2141 ok(helpcontext == 0x201, "helpcontext != 0x201\n");
2142 ok(!memcmp(helpfile, helpfileW, sizeof(helpfileW)), "helpfile = %s\n", wine_dbgstr_w(helpfile));
2144 SysFreeString(helpfile);
2146 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 1000, NULL, 1);
2147 ok(hres == E_INVALIDARG, "got %08x\n", hres);
2149 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 1000, names1, 1);
2150 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
2152 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 0, names1, 2);
2153 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
2155 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 0, names2, 1);
2156 ok(hres == S_OK, "got %08x\n", hres);
2158 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 0, names1, 1);
2159 ok(hres == S_OK, "got %08x\n", hres);
2161 hres = ITypeInfo_GetDocumentation(interface1, 0, &name, NULL, NULL, NULL);
2162 ok(hres == S_OK, "got %08x\n", hres);
2163 ok(!memcmp(name, func1W, sizeof(func1W)), "name = %s\n", wine_dbgstr_w(name));
2165 SysFreeString(name);
2167 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 3, names2, 3);
2168 ok(hres == S_OK, "got %08x\n", hres);
2170 hres = ICreateTypeInfo_SetFuncAndParamNames(createti, 3, names1, 3);
2171 ok(hres == TYPE_E_AMBIGUOUSNAME, "got %08x\n", hres);
2173 ITypeInfo2_Release(ti2);
2174 ICreateTypeInfo_Release(createti);
2176 hres = ICreateTypeLib2_CreateTypeInfo(createtl, interface1W, TKIND_INTERFACE, &createti);
2177 ok(hres == TYPE_E_NAMECONFLICT, "got %08x\n", hres);
2179 hres = ICreateTypeLib2_CreateTypeInfo(createtl, interface2W, TKIND_INTERFACE, &createti);
2180 ok(hres == S_OK, "got %08x\n", hres);
2182 hres = ICreateTypeInfo_QueryInterface(createti, &IID_ITypeInfo, (void**)&interface2);
2183 ok(hres == S_OK, "got %08x\n", hres);
2185 hres = ITypeInfo_GetRefTypeOfImplType(interface2, 0, &hreftype);
2186 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
2188 hres = ICreateTypeInfo_AddRefTypeInfo(createti, interface1, &hreftype);
2189 ok(hres == S_OK, "got %08x\n", hres);
2191 hres = ITypeInfo_GetRefTypeInfo(interface2, 0, &ti);
2192 ok(hres == S_OK, "got %08x\n", hres);
2193 ok(ti == interface1, "Received and added interfaces are different\n");
2195 ITypeInfo_Release(ti);
2197 hres = ICreateTypeInfo_AddImplType(createti, 0, hreftype);
2198 ok(hres == S_OK, "got %08x\n", hres);
2200 hres = ITypeInfo_GetRefTypeOfImplType(interface2, 0, &hreftype);
2201 ok(hres == S_OK, "got %08x\n", hres);
2202 ok(hreftype == 2, "hreftype = %d\n", hreftype);
2204 hres = ITypeInfo_GetRefTypeOfImplType(interface2, -1, &hreftype);
2205 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
2207 hres = ICreateTypeInfo_SetImplTypeFlags(createti, 0, IMPLTYPEFLAG_FDEFAULT);
2208 ok(hres == TYPE_E_BADMODULEKIND, "got %08x\n", hres);
2210 hres = ITypeInfo_GetImplTypeFlags(interface2, 0, &impltypeflags);
2211 ok(hres == S_OK, "got %08x\n", hres);
2212 ok(impltypeflags == 0, "impltypeflags = %x\n", impltypeflags);
2214 hres = ITypeInfo_GetImplTypeFlags(interface2, 1, &impltypeflags);
2215 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
2217 funcdesc.elemdescFunc.tdesc.vt = VT_VOID;
2218 funcdesc.oVft = 0xaaac;
2219 hres = ICreateTypeInfo_AddFuncDesc(createti, 0, &funcdesc);
2220 ok(hres == S_OK, "got %08x\n", hres);
2221 funcdesc.oVft = 0xaaa8;
2222 hres = ICreateTypeInfo_AddFuncDesc(createti, 0, &funcdesc);
2223 ok(hres == S_OK, "got %08x\n", hres);
2225 hres = ICreateTypeInfo_QueryInterface(createti, &IID_ITypeInfo, (void**)&ti2);
2226 ok(hres == S_OK, "got %08x\n", hres);
2228 hres = ITypeInfo2_GetFuncDesc(ti2, 0, &pfuncdesc);
2229 ok(hres == S_OK, "got %08x\n", hres);
2231 ok(pfuncdesc->memid == 0x60020000, "got %x\n", pfuncdesc->memid);
2232 ok(pfuncdesc->lprgscode == NULL, "got %p\n", pfuncdesc->lprgscode);
2233 ok(pfuncdesc->lprgelemdescParam != NULL, "got %p\n", pfuncdesc->lprgelemdescParam);
2234 ok(pfuncdesc->funckind == FUNC_PUREVIRTUAL, "got 0x%x\n", pfuncdesc->funckind);
2235 ok(pfuncdesc->invkind == INVOKE_FUNC, "got 0x%x\n", pfuncdesc->invkind);
2236 ok(pfuncdesc->callconv == CC_STDCALL, "got 0x%x\n", pfuncdesc->callconv);
2237 ok(pfuncdesc->cParams == 1, "got %d\n", pfuncdesc->cParams);
2238 ok(pfuncdesc->cParamsOpt == 0, "got %d\n", pfuncdesc->cParamsOpt);
2239 ok(pfuncdesc->oVft == (short)0xaaa8, "got %d\n", pfuncdesc->oVft);
2240 ok(pfuncdesc->cScodes == 0, "got %d\n", pfuncdesc->cScodes);
2241 ok(pfuncdesc->elemdescFunc.tdesc.vt == VT_VOID, "got %d\n", pfuncdesc->elemdescFunc.tdesc.vt);
2242 ok(pfuncdesc->wFuncFlags == 0, "got 0x%x\n", pfuncdesc->wFuncFlags);
2244 ITypeInfo2_ReleaseFuncDesc(ti2, pfuncdesc);
2245 ITypeInfo2_Release(ti2);
2247 funcdesc.oVft = 0;
2249 ICreateTypeInfo_Release(createti);
2251 VariantInit(&cust_data);
2253 hres = ICreateTypeLib2_CreateTypeInfo(createtl, interface3W, TKIND_INTERFACE, &createti);
2254 ok(hres == S_OK, "got %08x\n", hres);
2256 hres = ICreateTypeInfo_QueryInterface(createti, &IID_ICreateTypeInfo2, (void**)&createti2);
2257 ok(hres == S_OK, "got %08x\n", hres);
2259 hres = ICreateTypeInfo2_QueryInterface(createti2, &IID_ITypeInfo2, (void**)&ti2);
2260 ok(hres == S_OK, "got %08x\n", hres);
2262 hres = ITypeInfo2_GetCustData(ti2, NULL, NULL);
2263 ok(hres == E_INVALIDARG, "got %08x\n", hres);
2265 hres = ITypeInfo2_GetCustData(ti2, &custguid, NULL);
2266 ok(hres == E_INVALIDARG, "got %08x\n", hres);
2268 hres = ITypeInfo2_GetCustData(ti2, &custguid, &cust_data);
2269 ok(hres == S_OK, "got %08x\n", hres);
2271 hres = ICreateTypeInfo2_SetCustData(createti2, NULL, NULL);
2272 ok(hres == E_INVALIDARG, "got %08x\n", hres);
2274 hres = ICreateTypeInfo2_SetCustData(createti2, &custguid, NULL);
2275 ok(hres == E_INVALIDARG, "got %08x\n", hres);
2277 hres = ICreateTypeInfo2_SetCustData(createti2, &custguid, &cust_data);
2278 ok(hres == DISP_E_BADVARTYPE, "got %08x\n", hres);
2280 V_VT(&cust_data) = VT_UI4;
2281 V_I4(&cust_data) = 0xdeadbeef;
2283 hres = ICreateTypeInfo2_SetCustData(createti2, &custguid, &cust_data);
2284 ok(hres == S_OK, "got %08x\n", hres);
2286 V_I4(&cust_data) = 0;
2287 V_VT(&cust_data) = VT_EMPTY;
2289 hres = ITypeInfo2_GetCustData(ti2, &custguid, &cust_data);
2290 ok(hres == S_OK, "got %08x\n", hres);
2292 ok(V_VT(&cust_data) == VT_UI4, "got %d\n", V_VT(&cust_data));
2293 ok(V_I4(&cust_data) == 0xdeadbeef, "got 0x%08x\n", V_I4(&cust_data));
2295 V_VT(&cust_data) = VT_UI4;
2296 V_I4(&cust_data) = 12345678;
2298 hres = ICreateTypeInfo2_SetCustData(createti2, &custguid, &cust_data);
2299 ok(hres == S_OK, "got %08x\n", hres);
2301 V_I4(&cust_data) = 0;
2302 V_VT(&cust_data) = VT_EMPTY;
2304 hres = ITypeInfo2_GetCustData(ti2, &custguid, &cust_data);
2305 ok(hres == S_OK, "got %08x\n", hres);
2307 ok(V_VT(&cust_data) == VT_UI4, "got %d\n", V_VT(&cust_data));
2308 ok(V_I4(&cust_data) == 12345678, "got 0x%08x\n", V_I4(&cust_data));
2310 V_VT(&cust_data) = VT_BSTR;
2311 V_BSTR(&cust_data) = SysAllocString(asdfW);
2313 hres = ICreateTypeInfo2_SetCustData(createti2, &custguid, &cust_data);
2314 ok(hres == S_OK, "got %08x\n", hres);
2316 SysFreeString(V_BSTR(&cust_data));
2317 V_I4(&cust_data) = 0;
2318 V_VT(&cust_data) = VT_EMPTY;
2320 hres = ITypeInfo2_GetCustData(ti2, &custguid, &cust_data);
2321 ok(hres == S_OK, "got %08x\n", hres);
2323 ok(V_VT(&cust_data) == VT_BSTR, "got %d\n", V_VT(&cust_data));
2324 ok(!lstrcmpW(V_BSTR(&cust_data), asdfW), "got %s\n", wine_dbgstr_w(V_BSTR(&cust_data)));
2325 SysFreeString(V_BSTR(&cust_data));
2327 V_VT(&cust_data) = VT_UI4;
2328 V_UI4(&cust_data) = 17;
2330 hres = ITypeInfo2_GetCustData(ti2, &bogusguid, &cust_data);
2331 ok(hres == S_OK, "got %08x\n", hres);
2333 ok(V_VT(&cust_data) == VT_EMPTY, "got: %d\n", V_VT(&cust_data));
2335 ITypeInfo2_Release(ti2);
2336 ICreateTypeInfo2_Release(createti2);
2337 ICreateTypeInfo_Release(createti);
2339 hres = ICreateTypeLib2_CreateTypeInfo(createtl, coclassW, TKIND_COCLASS, &createti);
2340 ok(hres == S_OK, "got %08x\n", hres);
2342 hres = ICreateTypeInfo_AddRefTypeInfo(createti, interface1, &hreftype);
2343 ok(hres == S_OK, "got %08x\n", hres);
2345 hres = ICreateTypeInfo_AddImplType(createti, 0, hreftype);
2346 ok(hres == S_OK, "got %08x\n", hres);
2348 hres = ICreateTypeInfo_AddImplType(createti, 0, hreftype);
2349 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
2351 hres = ICreateTypeInfo_AddRefTypeInfo(createti, unknown, &hreftype);
2352 ok(hres == S_OK, "got %08x\n", hres);
2354 hres = ICreateTypeInfo_AddImplType(createti, 1, hreftype);
2355 ok(hres == S_OK, "got %08x\n", hres);
2357 hres = ICreateTypeInfo_AddImplType(createti, 1, hreftype);
2358 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
2360 hres = ICreateTypeInfo_AddImplType(createti, 2, hreftype);
2361 ok(hres == S_OK, "got %08x\n", hres);
2363 hres = ICreateTypeInfo_SetImplTypeFlags(createti, 0, IMPLTYPEFLAG_FDEFAULT);
2364 ok(hres == S_OK, "got %08x\n", hres);
2366 hres = ICreateTypeInfo_SetImplTypeFlags(createti, 1, IMPLTYPEFLAG_FRESTRICTED);
2367 ok(hres == S_OK, "got %08x\n", hres);
2369 hres = ICreateTypeInfo_QueryInterface(createti, &IID_ITypeInfo, (void**)&ti);
2370 ok(hres == S_OK, "got %08x\n", hres);
2372 hres = ITypeInfo_GetImplTypeFlags(ti, 0, NULL);
2373 ok(hres == E_INVALIDARG, "got %08x\n", hres);
2375 hres = ITypeInfo_GetImplTypeFlags(ti, 0, &impltypeflags);
2376 ok(hres == S_OK, "got %08x\n", hres);
2377 ok(impltypeflags == IMPLTYPEFLAG_FDEFAULT, "impltypeflags = %x\n", impltypeflags);
2379 hres = ITypeInfo_GetImplTypeFlags(ti, 1, &impltypeflags);
2380 ok(hres == S_OK, "got %08x\n", hres);
2381 ok(impltypeflags == IMPLTYPEFLAG_FRESTRICTED, "impltypeflags = %x\n", impltypeflags);
2383 hres = ITypeInfo_GetImplTypeFlags(ti, 2, &impltypeflags);
2384 ok(hres == S_OK, "got %08x\n", hres);
2385 ok(impltypeflags == 0, "impltypeflags = %x\n", impltypeflags);
2387 hres = ITypeInfo_GetRefTypeOfImplType(ti, 0, &hreftype);
2388 ok(hres == S_OK, "got %08x\n", hres);
2389 ok(hreftype == 0, "hreftype = %d\n", hreftype);
2391 hres = ITypeInfo_GetRefTypeOfImplType(ti, 1, &hreftype);
2392 ok(hres == S_OK, "got %08x\n", hres);
2393 ok(hreftype == 1, "hreftype = %d\n", hreftype);
2395 hres = ITypeInfo_GetRefTypeOfImplType(ti, 2, &hreftype);
2396 ok(hres == S_OK, "got %08x\n", hres);
2397 ok(hreftype == 1, "hreftype = %d\n", hreftype);
2399 hres = ITypeInfo_GetRefTypeOfImplType(ti, -1, &hreftype);
2400 ok(hres == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hres);
2402 ITypeInfo_Release(ti);
2404 ICreateTypeInfo_Release(createti);
2406 hres = ICreateTypeLib2_CreateTypeInfo(createtl, dualW, TKIND_INTERFACE, &createti);
2407 ok(hres == S_OK, "got %08x\n", hres);
2409 hres = ICreateTypeInfo_SetTypeFlags(createti, TYPEFLAG_FDUAL);
2410 ok(hres == S_OK, "got %08x\n", hres);
2412 hres = ICreateTypeInfo_AddFuncDesc(createti, 0, &funcdesc);
2413 ok(hres == S_OK, "got %08x\n", hres);
2415 hres = ICreateTypeInfo_AddRefTypeInfo(createti, dispatch, &hreftype);
2416 ok(hres == S_OK, "got %08x\n", hres);
2418 hres = ICreateTypeInfo_AddImplType(createti, 0, hreftype);
2419 ok(hres == S_OK, "got %08x\n", hres);
2421 hres = ICreateTypeInfo_QueryInterface(createti, &IID_ITypeInfo, (void**)&dual);
2422 ok(hres == S_OK, "got %08x\n", hres);
2424 hres = ITypeInfo_GetTypeAttr(dual, &typeattr);
2425 ok(hres == S_OK, "got %08x\n", hres);
2426 ok(typeattr->cbSizeInstance == 4, "cbSizeInstance = %d\n", typeattr->cbSizeInstance);
2427 ok(typeattr->typekind == 3, "typekind = %d\n", typeattr->typekind);
2428 ok(typeattr->cFuncs == 1, "cFuncs = %d\n", typeattr->cFuncs);
2429 ok(typeattr->cVars == 0, "cVars = %d\n", typeattr->cVars);
2430 ok(typeattr->cImplTypes == 1, "cImplTypes = %d\n", typeattr->cImplTypes);
2431 ok(typeattr->cbSizeVft == 32 || broken(typeattr->cbSizeVft == 7 * sizeof(void *) + 4), /* xp64 */
2432 "cbSizeVft = %d\n", typeattr->cbSizeVft);
2433 ok(typeattr->cbAlignment == 4, "cbAlignment = %d\n", typeattr->cbAlignment);
2434 ok(typeattr->wTypeFlags == (TYPEFLAG_FDISPATCHABLE|TYPEFLAG_FDUAL), "wTypeFlags = %d\n", typeattr->wTypeFlags);
2435 ok(typeattr->wMajorVerNum == 0, "wMajorVerNum = %d\n", typeattr->wMajorVerNum);
2436 ok(typeattr->wMinorVerNum == 0, "wMinorVerNum = %d\n", typeattr->wMinorVerNum);
2438 ITypeInfo_ReleaseTypeAttr(dual, typeattr);
2440 hres = ITypeInfo_GetRefTypeOfImplType(dual, -1, &hreftype);
2441 ok(hres == S_OK, "got %08x\n", hres);
2442 ok(hreftype == -2, "got %08x\n", hreftype);
2444 hres = ITypeInfo_GetRefTypeInfo(dual, -2, &ti);
2445 ok(hres == S_OK, "got %08x\n", hres);
2447 hres = ITypeInfo_GetTypeAttr(ti, &typeattr);
2448 ok(hres == S_OK, "got %08x\n", hres);
2449 ok(typeattr->cbSizeInstance == 4, "cbSizeInstance = %d\n", typeattr->cbSizeInstance);
2450 ok(typeattr->typekind == 4, "typekind = %d\n", typeattr->typekind);
2451 ok(typeattr->cFuncs == 8, "cFuncs = %d\n", typeattr->cFuncs);
2452 ok(typeattr->cVars == 0, "cVars = %d\n", typeattr->cVars);
2453 ok(typeattr->cImplTypes == 1, "cImplTypes = %d\n", typeattr->cImplTypes);
2454 ok(typeattr->cbSizeVft == 7 * sizeof(void *), "cbSizeVft = %d\n", typeattr->cbSizeVft);
2455 ok(typeattr->cbAlignment == 4, "cbAlignment = %d\n", typeattr->cbAlignment);
2456 ok(typeattr->wTypeFlags == (TYPEFLAG_FDISPATCHABLE|TYPEFLAG_FDUAL), "wTypeFlags = %d\n", typeattr->wTypeFlags);
2457 ok(typeattr->wMajorVerNum == 0, "wMajorVerNum = %d\n", typeattr->wMajorVerNum);
2458 ok(typeattr->wMinorVerNum == 0, "wMinorVerNum = %d\n", typeattr->wMinorVerNum);
2460 ITypeInfo_ReleaseTypeAttr(ti, typeattr);
2462 ITypeInfo_Release(ti);
2464 ICreateTypeInfo_Release(createti);
2466 hres = ITypeInfo_GetTypeAttr(interface1, &typeattr);
2467 ok(hres == S_OK, "got %08x\n", hres);
2468 ok(typeattr->cbSizeInstance == 4, "cbSizeInstance = %d\n", typeattr->cbSizeInstance);
2469 ok(typeattr->typekind == 3, "typekind = %d\n", typeattr->typekind);
2470 ok(typeattr->cFuncs == 13, "cFuncs = %d\n", typeattr->cFuncs);
2471 ok(typeattr->cVars == 0, "cVars = %d\n", typeattr->cVars);
2472 ok(typeattr->cImplTypes == 1, "cImplTypes = %d\n", typeattr->cImplTypes);
2473 ok(typeattr->cbSizeVft == 64 || broken(typeattr->cbSizeVft == 3 * sizeof(void *) + 52), /* xp64 */
2474 "cbSizeVft = %d\n", typeattr->cbSizeVft);
2475 ok(typeattr->cbAlignment == 4, "cbAlignment = %d\n", typeattr->cbAlignment);
2476 ok(typeattr->wTypeFlags == 0, "wTypeFlags = %d\n", typeattr->wTypeFlags);
2477 ok(typeattr->wMajorVerNum == 0, "wMajorVerNum = %d\n", typeattr->wMajorVerNum);
2478 ok(typeattr->wMinorVerNum == 0, "wMinorVerNum = %d\n", typeattr->wMinorVerNum);
2480 ITypeInfo_ReleaseTypeAttr(interface1, typeattr);
2482 hres = ITypeInfo_GetTypeAttr(interface2, &typeattr);
2483 ok(hres == S_OK, "got %08x\n", hres);
2484 ok(typeattr->cbSizeInstance == 4, "cbSizeInstance = %d\n", typeattr->cbSizeInstance);
2485 ok(typeattr->typekind == 3, "typekind = %d\n", typeattr->typekind);
2486 ok(typeattr->cFuncs == 2, "cFuncs = %d\n", typeattr->cFuncs);
2487 ok(typeattr->cVars == 0, "cVars = %d\n", typeattr->cVars);
2488 ok(typeattr->cImplTypes == 1, "cImplTypes = %d\n", typeattr->cImplTypes);
2489 ok(typeattr->cbSizeVft == 43696, "cbSizeVft = %d\n", typeattr->cbSizeVft);
2490 ok(typeattr->cbAlignment == 4, "cbAlignment = %d\n", typeattr->cbAlignment);
2491 ok(typeattr->wTypeFlags == 0, "wTypeFlags = %d\n", typeattr->wTypeFlags);
2492 ok(typeattr->wMajorVerNum == 0, "wMajorVerNum = %d\n", typeattr->wMajorVerNum);
2493 ok(typeattr->wMinorVerNum == 0, "wMinorVerNum = %d\n", typeattr->wMinorVerNum);
2495 ITypeInfo_ReleaseTypeAttr(interface2, typeattr);
2497 hres = ICreateTypeLib2_SaveAllChanges(createtl);
2498 ok(hres == S_OK, "got %08x\n", hres);
2500 ok(ITypeInfo_Release(interface2)==0, "Object should be freed\n");
2501 ok(ITypeInfo_Release(interface1)==0, "Object should be freed\n");
2502 ok(ITypeInfo_Release(dual)==0, "Object should be freed\n");
2503 ok(ICreateTypeLib2_Release(createtl)==0, "Object should be freed\n");
2505 ok(ITypeInfo_Release(dispatch)==0, "Object should be freed\n");
2506 ok(ITypeInfo_Release(unknown)==0, "Object should be freed\n");
2507 ok(ITypeLib_Release(stdole)==0, "Object should be freed\n");
2509 hres = LoadTypeLibEx(filenameW, REGKIND_NONE, &tl);
2510 ok(hres == S_OK, "got %08x\n", hres);
2511 ok(ITypeLib_Release(tl)==0, "Object should be freed\n");
2513 DeleteFileA(filename);
2516 #if 0 /* use this to generate more tests */
2518 #define OLE_CHECK(x) { HRESULT hr = x; if (FAILED(hr)) { printf(#x "failed - %x\n", hr); return; } }
2520 static char *dump_string(LPWSTR wstr)
2522 int size = lstrlenW(wstr)+3;
2523 char *out = CoTaskMemAlloc(size);
2524 WideCharToMultiByte(20127, 0, wstr, -1, out+1, size, NULL, NULL);
2525 out[0] = '\"';
2526 strcat(out, "\"");
2527 return out;
2530 struct map_entry
2532 DWORD value;
2533 const char *name;
2536 #define MAP_ENTRY(x) { x, #x }
2537 static const struct map_entry tkind_map[] = {
2538 MAP_ENTRY(TKIND_ENUM),
2539 MAP_ENTRY(TKIND_RECORD),
2540 MAP_ENTRY(TKIND_MODULE),
2541 MAP_ENTRY(TKIND_INTERFACE),
2542 MAP_ENTRY(TKIND_DISPATCH),
2543 MAP_ENTRY(TKIND_COCLASS),
2544 MAP_ENTRY(TKIND_ALIAS),
2545 MAP_ENTRY(TKIND_UNION),
2546 MAP_ENTRY(TKIND_MAX),
2547 {0, NULL}
2550 static const struct map_entry funckind_map[] = {
2551 MAP_ENTRY(FUNC_VIRTUAL),
2552 MAP_ENTRY(FUNC_PUREVIRTUAL),
2553 MAP_ENTRY(FUNC_NONVIRTUAL),
2554 MAP_ENTRY(FUNC_STATIC),
2555 MAP_ENTRY(FUNC_DISPATCH),
2556 {0, NULL}
2559 static const struct map_entry invkind_map[] = {
2560 MAP_ENTRY(INVOKE_FUNC),
2561 MAP_ENTRY(INVOKE_PROPERTYGET),
2562 MAP_ENTRY(INVOKE_PROPERTYPUT),
2563 MAP_ENTRY(INVOKE_PROPERTYPUTREF),
2564 {0, NULL}
2567 #undef MAP_ENTRY
2569 static const char *map_value(DWORD val, const struct map_entry *map)
2571 static int map_id;
2572 static char bufs[16][256];
2573 char *buf;
2575 while (map->name)
2577 if (map->value == val)
2578 return map->name;
2579 map++;
2582 buf = bufs[(map_id++)%16];
2583 sprintf(buf, "0x%x", val);
2584 return buf;
2587 static void test_dump_typelib(const char *name)
2589 WCHAR wszString[260];
2590 ITypeInfo *info;
2591 ITypeLib *lib;
2592 int count;
2593 int i;
2595 MultiByteToWideChar(CP_ACP, 0, name, -1, wszString, 260);
2596 OLE_CHECK(LoadTypeLib(wszString, &lib));
2597 count = ITypeLib_GetTypeInfoCount(lib);
2598 printf("/* interfaces count: %d */\n", count);
2599 for (i = 0; i < count; i++)
2601 TYPEATTR *attr;
2602 BSTR name;
2603 int f = 0;
2605 OLE_CHECK(ITypeLib_GetDocumentation(lib, i, &name, NULL, NULL, NULL));
2606 printf("{\n"
2607 " %s,\n", dump_string(name));
2608 SysFreeString(name);
2610 OLE_CHECK(ITypeLib_GetTypeInfo(lib, i, &info));
2611 ITypeInfo_GetTypeAttr(info, &attr);
2612 printf(" /*kind*/ %s, /*flags*/ 0x%x, /*align*/ %d, /*size*/ %d,\n"
2613 " /*#vtbl*/ %d, /*#func*/ %d,\n"
2614 " {\n",
2615 map_value(attr->typekind, tkind_map), attr->wTypeFlags, attr->cbAlignment, attr->cbSizeInstance, attr->cbSizeVft,
2616 attr->cFuncs);
2617 ITypeInfo_ReleaseTypeAttr(info, attr);
2618 while (1)
2620 FUNCDESC *desc;
2621 BSTR tab[256];
2622 UINT cNames;
2623 int p;
2625 if (FAILED(ITypeInfo_GetFuncDesc(info, f, &desc)))
2626 break;
2627 printf(" {\n"
2628 " 0x%x, /*func*/ %s, /*inv*/ %s, /*call*/ 0x%x,\n",
2629 desc->memid, map_value(desc->funckind, funckind_map), map_value(desc->invkind, invkind_map),
2630 desc->callconv);
2631 printf(" /*#param*/ %d, /*#opt*/ %d, /*vtbl*/ %d, /*#scodes*/ %d, /*flags*/ 0x%x,\n",
2632 desc->cParams, desc->cParamsOpt, desc->oVft, desc->cScodes, desc->wFuncFlags);
2633 printf(" {%d, %x}, /* ret */\n", desc->elemdescFunc.tdesc.vt, desc->elemdescFunc.paramdesc.wParamFlags);
2634 printf(" { /* params */\n");
2635 for (p = 0; p < desc->cParams; p++)
2637 ELEMDESC e = desc->lprgelemdescParam[p];
2638 printf(" {%d, %x},\n", e.tdesc.vt, e.paramdesc.wParamFlags);
2640 printf(" {-1, -1}\n");
2641 printf(" },\n");
2642 printf(" { /* names */\n");
2643 OLE_CHECK(ITypeInfo_GetNames(info, desc->memid, tab, 256, &cNames));
2644 for (p = 0; p < cNames; p++)
2646 printf(" %s,\n", dump_string(tab[p]));
2647 SysFreeString(tab[p]);
2649 printf(" NULL,\n");
2650 printf(" },\n");
2651 printf(" },\n");
2652 ITypeInfo_ReleaseFuncDesc(info, desc);
2653 f++;
2655 printf(" }\n");
2656 printf("},\n");
2657 ITypeInfo_Release(info);
2659 ITypeLib_Release(lib);
2662 #else
2664 typedef struct _element_info
2666 VARTYPE vt;
2667 USHORT wParamFlags;
2668 } element_info;
2670 typedef struct _function_info
2672 MEMBERID memid;
2673 FUNCKIND funckind;
2674 INVOKEKIND invkind;
2675 CALLCONV callconv;
2676 short cParams;
2677 short cParamsOpt;
2678 short vtbl_index;
2679 short cScodes;
2680 WORD wFuncFlags;
2681 element_info ret_type;
2682 element_info params[15];
2683 LPCSTR names[15];
2684 } function_info;
2686 typedef struct _interface_info
2688 LPCSTR name;
2689 TYPEKIND type;
2690 WORD wTypeFlags;
2691 USHORT cbAlignment;
2692 USHORT cbSizeInstance;
2693 USHORT cbSizeVft;
2694 USHORT cFuncs;
2695 function_info funcs[20];
2696 } interface_info;
2698 static const interface_info info[] = {
2699 /* interfaces count: 2 */
2701 "IDualIface",
2702 /*kind*/ TKIND_DISPATCH, /*flags*/ 0x1040, /*align*/ 4, /*size*/ 4,
2703 /*#vtbl*/ 7, /*#func*/ 8,
2706 0x60000000, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
2707 /*#param*/ 2, /*#opt*/ 0, /*vtbl*/ 0, /*#scodes*/ 0, /*flags*/ 0x1,
2708 {24, 0}, /* ret */
2709 { /* params */
2710 {26, 1},
2711 {26, 2},
2712 {-1, -1}
2714 { /* names */
2715 "QueryInterface",
2716 "riid",
2717 "ppvObj",
2718 NULL,
2722 0x60000001, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
2723 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 1, /*#scodes*/ 0, /*flags*/ 0x1,
2724 {19, 0}, /* ret */
2725 { /* params */
2726 {-1, -1}
2728 { /* names */
2729 "AddRef",
2730 NULL,
2734 0x60000002, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
2735 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 2, /*#scodes*/ 0, /*flags*/ 0x1,
2736 {19, 0}, /* ret */
2737 { /* params */
2738 {-1, -1}
2740 { /* names */
2741 "Release",
2742 NULL,
2746 0x60010000, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
2747 /*#param*/ 1, /*#opt*/ 0, /*vtbl*/ 3, /*#scodes*/ 0, /*flags*/ 0x1,
2748 {24, 0}, /* ret */
2749 { /* params */
2750 {26, 2},
2751 {-1, -1}
2753 { /* names */
2754 "GetTypeInfoCount",
2755 "pctinfo",
2756 NULL,
2760 0x60010001, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
2761 /*#param*/ 3, /*#opt*/ 0, /*vtbl*/ 4, /*#scodes*/ 0, /*flags*/ 0x1,
2762 {24, 0}, /* ret */
2763 { /* params */
2764 {23, 1},
2765 {19, 1},
2766 {26, 2},
2767 {-1, -1}
2769 { /* names */
2770 "GetTypeInfo",
2771 "itinfo",
2772 "lcid",
2773 "pptinfo",
2774 NULL,
2778 0x60010002, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
2779 /*#param*/ 5, /*#opt*/ 0, /*vtbl*/ 5, /*#scodes*/ 0, /*flags*/ 0x1,
2780 {24, 0}, /* ret */
2781 { /* params */
2782 {26, 1},
2783 {26, 1},
2784 {23, 1},
2785 {19, 1},
2786 {26, 2},
2787 {-1, -1}
2789 { /* names */
2790 "GetIDsOfNames",
2791 "riid",
2792 "rgszNames",
2793 "cNames",
2794 "lcid",
2795 "rgdispid",
2796 NULL,
2800 0x60010003, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
2801 /*#param*/ 8, /*#opt*/ 0, /*vtbl*/ 6, /*#scodes*/ 0, /*flags*/ 0x1,
2802 {24, 0}, /* ret */
2803 { /* params */
2804 {3, 1},
2805 {26, 1},
2806 {19, 1},
2807 {18, 1},
2808 {26, 1},
2809 {26, 2},
2810 {26, 2},
2811 {26, 2},
2812 {-1, -1}
2814 { /* names */
2815 "Invoke",
2816 "dispidMember",
2817 "riid",
2818 "lcid",
2819 "wFlags",
2820 "pdispparams",
2821 "pvarResult",
2822 "pexcepinfo",
2823 "puArgErr",
2824 NULL,
2828 0x60020000, /*func*/ FUNC_DISPATCH, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
2829 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 7, /*#scodes*/ 0, /*flags*/ 0x0,
2830 {24, 0}, /* ret */
2831 { /* params */
2832 {-1, -1}
2834 { /* names */
2835 "Test",
2836 NULL,
2842 "ISimpleIface",
2843 /*kind*/ TKIND_INTERFACE, /*flags*/ 0x1000, /*align*/ 4, /*size*/ 4,
2844 /*#vtbl*/ 8, /*#func*/ 1,
2847 0x60020000, /*func*/ FUNC_PUREVIRTUAL, /*inv*/ INVOKE_FUNC, /*call*/ 0x4,
2848 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 7, /*#scodes*/ 0, /*flags*/ 0x0,
2849 {25, 0}, /* ret */
2850 { /* params */
2851 {-1, -1}
2853 { /* names */
2854 "Test",
2855 NULL,
2862 #define check_type(elem, info) { \
2863 expect_int((elem)->tdesc.vt, (info)->vt); \
2864 expect_hex(U(*(elem)).paramdesc.wParamFlags, (info)->wParamFlags); \
2867 static void test_dump_typelib(const char *name)
2869 WCHAR wszName[MAX_PATH];
2870 ITypeLib *typelib;
2871 int ifcount = sizeof(info)/sizeof(info[0]);
2872 int iface, func;
2874 MultiByteToWideChar(CP_ACP, 0, name, -1, wszName, MAX_PATH);
2875 ole_check(LoadTypeLibEx(wszName, REGKIND_NONE, &typelib));
2876 expect_eq(ITypeLib_GetTypeInfoCount(typelib), ifcount, UINT, "%d");
2877 for (iface = 0; iface < ifcount; iface++)
2879 const interface_info *if_info = &info[iface];
2880 ITypeInfo *typeinfo;
2881 TYPEATTR *typeattr;
2882 BSTR bstrIfName;
2884 trace("Interface %s\n", if_info->name);
2885 ole_check(ITypeLib_GetTypeInfo(typelib, iface, &typeinfo));
2886 ole_check(ITypeLib_GetDocumentation(typelib, iface, &bstrIfName, NULL, NULL, NULL));
2887 expect_wstr_acpval(bstrIfName, if_info->name);
2888 SysFreeString(bstrIfName);
2890 ole_check(ITypeInfo_GetTypeAttr(typeinfo, &typeattr));
2891 expect_int(typeattr->typekind, if_info->type);
2892 expect_hex(typeattr->wTypeFlags, if_info->wTypeFlags);
2893 expect_int(typeattr->cbAlignment, if_info->cbAlignment);
2894 expect_int(typeattr->cbSizeInstance, if_info->cbSizeInstance);
2895 expect_int(typeattr->cbSizeVft, if_info->cbSizeVft * sizeof(void*));
2896 expect_int(typeattr->cFuncs, if_info->cFuncs);
2898 for (func = 0; func < typeattr->cFuncs; func++)
2900 function_info *fn_info = (function_info *)&if_info->funcs[func];
2901 FUNCDESC *desc;
2902 BSTR namesTab[256];
2903 UINT cNames;
2904 int i;
2906 trace("Function %s\n", fn_info->names[0]);
2907 ole_check(ITypeInfo_GetFuncDesc(typeinfo, func, &desc));
2908 expect_int(desc->memid, fn_info->memid);
2909 expect_int(desc->funckind, fn_info->funckind);
2910 expect_int(desc->invkind, fn_info->invkind);
2911 expect_int(desc->callconv, fn_info->callconv);
2912 expect_int(desc->cParams, fn_info->cParams);
2913 expect_int(desc->cParamsOpt, fn_info->cParamsOpt);
2914 ok( desc->oVft == fn_info->vtbl_index * sizeof(void*) ||
2915 broken(desc->oVft == fn_info->vtbl_index * 4), /* xp64 */
2916 "desc->oVft got %u\n", desc->oVft );
2917 expect_int(desc->cScodes, fn_info->cScodes);
2918 expect_int(desc->wFuncFlags, fn_info->wFuncFlags);
2919 ole_check(ITypeInfo_GetNames(typeinfo, desc->memid, namesTab, 256, &cNames));
2920 for (i = 0; i < cNames; i++)
2922 expect_wstr_acpval(namesTab[i], fn_info->names[i]);
2923 SysFreeString(namesTab[i]);
2925 expect_null(fn_info->names[cNames]);
2927 check_type(&desc->elemdescFunc, &fn_info->ret_type);
2928 for (i = 0 ; i < desc->cParams; i++)
2930 check_type(&desc->lprgelemdescParam[i], &fn_info->params[i]);
2932 expect_int(fn_info->params[desc->cParams].vt, (VARTYPE)-1);
2934 ITypeInfo_ReleaseFuncDesc(typeinfo, desc);
2937 ITypeInfo_ReleaseTypeAttr(typeinfo, typeattr);
2938 ITypeInfo_Release(typeinfo);
2940 ITypeLib_Release(typelib);
2943 #endif
2945 static void test_create_typelib_lcid(LCID lcid)
2947 char filename[MAX_PATH];
2948 WCHAR name[MAX_PATH];
2949 HRESULT hr;
2950 ICreateTypeLib2 *tl;
2951 HANDLE file;
2952 DWORD msft_header[5]; /* five is enough for now */
2953 DWORD read;
2955 GetTempFileNameA( ".", "tlb", 0, filename );
2956 MultiByteToWideChar(CP_ACP, 0, filename, -1, name, MAX_PATH);
2958 hr = CreateTypeLib2(SYS_WIN32, name, &tl);
2959 ok(hr == S_OK, "got %08x\n", hr);
2961 hr = ICreateTypeLib2_SetLcid(tl, lcid);
2962 ok(hr == S_OK, "got %08x\n", hr);
2964 hr = ICreateTypeLib2_SaveAllChanges(tl);
2965 ok(hr == S_OK, "got %08x\n", hr);
2967 ICreateTypeLib2_Release(tl);
2969 file = CreateFileA( filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0 );
2970 ok( file != INVALID_HANDLE_VALUE, "file creation failed\n" );
2972 ReadFile( file, msft_header, sizeof(msft_header), &read, NULL );
2973 ok(read == sizeof(msft_header), "read %d\n", read);
2974 CloseHandle( file );
2976 ok(msft_header[0] == 0x5446534d, "got %08x\n", msft_header[0]);
2977 ok(msft_header[1] == 0x00010002, "got %08x\n", msft_header[1]);
2978 ok(msft_header[2] == 0xffffffff, "got %08x\n", msft_header[2]);
2979 ok(msft_header[3] == (lcid ? lcid : 0x409), "got %08x (lcid %08x)\n", msft_header[3], lcid);
2980 ok(msft_header[4] == lcid, "got %08x (lcid %08x)\n", msft_header[4], lcid);
2982 DeleteFileA(filename);
2985 static void test_create_typelibs(void)
2987 test_create_typelib_lcid(LOCALE_SYSTEM_DEFAULT);
2988 test_create_typelib_lcid(LOCALE_USER_DEFAULT);
2989 test_create_typelib_lcid(LOCALE_NEUTRAL);
2991 test_create_typelib_lcid(0x009);
2992 test_create_typelib_lcid(0x409);
2993 test_create_typelib_lcid(0x809);
2995 test_create_typelib_lcid(0x007);
2996 test_create_typelib_lcid(0x407);
3000 static void test_register_typelib(BOOL system_registration)
3002 HRESULT hr;
3003 WCHAR filename[MAX_PATH];
3004 const char *filenameA;
3005 ITypeLib *typelib;
3006 WCHAR uuidW[40];
3007 char key_name[MAX_PATH], uuid[40];
3008 LONG ret, expect_ret;
3009 UINT count, i;
3010 HKEY hkey;
3011 struct
3013 TYPEKIND kind;
3014 WORD flags;
3015 } attrs[12] =
3017 { TKIND_INTERFACE, 0 },
3018 { TKIND_INTERFACE, TYPEFLAG_FDISPATCHABLE },
3019 { TKIND_INTERFACE, TYPEFLAG_FOLEAUTOMATION },
3020 { TKIND_INTERFACE, TYPEFLAG_FDISPATCHABLE | TYPEFLAG_FOLEAUTOMATION },
3021 { TKIND_DISPATCH, 0 /* TYPEFLAG_FDUAL - widl clears this flag for non-IDispatch derived interfaces */ },
3022 { TKIND_DISPATCH, 0 /* TYPEFLAG_FDUAL - widl clears this flag for non-IDispatch derived interfaces */ },
3023 { TKIND_DISPATCH, TYPEFLAG_FDISPATCHABLE | TYPEFLAG_FDUAL },
3024 { TKIND_DISPATCH, TYPEFLAG_FDISPATCHABLE | TYPEFLAG_FDUAL },
3025 { TKIND_DISPATCH, TYPEFLAG_FDISPATCHABLE },
3026 { TKIND_DISPATCH, TYPEFLAG_FDISPATCHABLE },
3027 { TKIND_DISPATCH, TYPEFLAG_FDISPATCHABLE },
3028 { TKIND_INTERFACE, TYPEFLAG_FDISPATCHABLE }
3031 trace("Starting %s typelib registration tests\n",
3032 system_registration ? "system" : "user");
3034 if (!system_registration && (!pRegisterTypeLibForUser || !pUnRegisterTypeLibForUser))
3036 win_skip("User typelib registration functions are not available\n");
3037 return;
3040 filenameA = create_test_typelib(3);
3041 MultiByteToWideChar(CP_ACP, 0, filenameA, -1, filename, MAX_PATH);
3043 hr = LoadTypeLibEx(filename, REGKIND_NONE, &typelib);
3044 ok(hr == S_OK, "got %08x\n", hr);
3046 if (system_registration)
3047 hr = RegisterTypeLib(typelib, filename, NULL);
3048 else
3049 hr = pRegisterTypeLibForUser(typelib, filename, NULL);
3050 if (hr == TYPE_E_REGISTRYACCESS)
3052 win_skip("Insufficient privileges to register typelib in the registry\n");
3053 ITypeLib_Release(typelib);
3054 DeleteFileA(filenameA);
3055 return;
3057 ok(hr == S_OK, "got %08x\n", hr);
3059 count = ITypeLib_GetTypeInfoCount(typelib);
3060 ok(count == 12, "got %d\n", count);
3062 for(i = 0; i < count; i++)
3064 ITypeInfo *typeinfo;
3065 TYPEATTR *attr;
3067 hr = ITypeLib_GetTypeInfo(typelib, i, &typeinfo);
3068 ok(hr == S_OK, "got %08x\n", hr);
3070 hr = ITypeInfo_GetTypeAttr(typeinfo, &attr);
3071 ok(hr == S_OK, "got %08x\n", hr);
3073 ok(attr->typekind == attrs[i].kind, "%d: got kind %d\n", i, attr->typekind);
3074 ok(attr->wTypeFlags == attrs[i].flags, "%d: got flags %04x\n", i, attr->wTypeFlags);
3076 if(attr->typekind == TKIND_DISPATCH && (attr->wTypeFlags & TYPEFLAG_FDUAL))
3078 HREFTYPE reftype;
3079 ITypeInfo *dual_info;
3080 TYPEATTR *dual_attr;
3082 hr = ITypeInfo_GetRefTypeOfImplType(typeinfo, -1, &reftype);
3083 ok(hr == S_OK, "got %08x\n", hr);
3085 hr = ITypeInfo_GetRefTypeInfo(typeinfo, reftype, &dual_info);
3086 ok(hr == S_OK, "got %08x\n", hr);
3088 hr = ITypeInfo_GetTypeAttr(dual_info, &dual_attr);
3089 ok(hr == S_OK, "got %08x\n", hr);
3091 ok(dual_attr->typekind == TKIND_INTERFACE, "%d: got kind %d\n", i, dual_attr->typekind);
3092 ok(dual_attr->wTypeFlags == (TYPEFLAG_FDISPATCHABLE | TYPEFLAG_FOLEAUTOMATION | TYPEFLAG_FDUAL), "%d: got flags %04x\n", i, dual_attr->wTypeFlags);
3094 ITypeInfo_ReleaseTypeAttr(dual_info, dual_attr);
3095 ITypeInfo_Release(dual_info);
3099 StringFromGUID2(&attr->guid, uuidW, sizeof(uuidW) / sizeof(uuidW[0]));
3100 WideCharToMultiByte(CP_ACP, 0, uuidW, -1, uuid, sizeof(uuid), NULL, NULL);
3101 sprintf(key_name, "Interface\\%s", uuid);
3103 /* All dispinterfaces will be registered (this includes dual interfaces) as well
3104 as oleautomation interfaces */
3105 if((attr->typekind == TKIND_INTERFACE && (attr->wTypeFlags & TYPEFLAG_FOLEAUTOMATION)) ||
3106 attr->typekind == TKIND_DISPATCH)
3107 expect_ret = ERROR_SUCCESS;
3108 else
3109 expect_ret = ERROR_FILE_NOT_FOUND;
3111 ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, key_name, 0, KEY_READ, &hkey);
3112 ok(ret == expect_ret, "%d: got %d\n", i, ret);
3113 if(ret == ERROR_SUCCESS) RegCloseKey(hkey);
3115 ITypeInfo_ReleaseTypeAttr(typeinfo, attr);
3116 ITypeInfo_Release(typeinfo);
3119 if (system_registration)
3120 hr = UnRegisterTypeLib(&LIBID_register_test, 1, 0, LOCALE_NEUTRAL, is_win64 ? SYS_WIN64 : SYS_WIN32);
3121 else
3122 hr = pUnRegisterTypeLibForUser(&LIBID_register_test, 1, 0, LOCALE_NEUTRAL, is_win64 ? SYS_WIN64 : SYS_WIN32);
3123 ok(hr == S_OK, "got %08x\n", hr);
3125 ITypeLib_Release(typelib);
3126 DeleteFileA( filenameA );
3129 static void test_LoadTypeLib(void)
3131 ITypeLib *tl;
3132 HRESULT hres;
3134 static const WCHAR kernel32_dllW[] = {'k','e','r','n','e','l','3','2','.','d','l','l',0};
3136 hres = LoadTypeLib(kernel32_dllW, &tl);
3137 ok(hres == TYPE_E_CANTLOADLIBRARY, "LoadTypeLib returned: %08x, expected TYPE_E_CANTLOADLIBRARY\n", hres);
3140 static void test_SetVarHelpContext(void)
3142 static OLECHAR nameW[] = {'n','a','m','e',0};
3143 CHAR filenameA[MAX_PATH];
3144 WCHAR filenameW[MAX_PATH];
3145 ICreateTypeLib2 *ctl;
3146 ICreateTypeInfo *cti;
3147 VARDESC desc;
3148 HRESULT hr;
3149 VARIANT v;
3151 GetTempFileNameA(".", "tlb", 0, filenameA);
3152 MultiByteToWideChar(CP_ACP, 0, filenameA, -1, filenameW, MAX_PATH);
3154 hr = CreateTypeLib2(SYS_WIN32, filenameW, &ctl);
3155 ok(hr == S_OK, "got %08x\n", hr);
3157 hr = ICreateTypeLib2_CreateTypeInfo(ctl, nameW, TKIND_ENUM, &cti);
3158 ok(hr == S_OK, "got %08x\n", hr);
3160 hr = ICreateTypeInfo_SetVarHelpContext(cti, 0, 0);
3161 ok(hr == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hr);
3163 memset(&desc, 0, sizeof(desc));
3164 desc.elemdescVar.tdesc.vt = VT_INT;
3165 desc.varkind = VAR_CONST;
3167 V_VT(&v) = VT_INT;
3168 V_INT(&v) = 1;
3169 U(desc).lpvarValue = &v;
3170 hr = ICreateTypeInfo_AddVarDesc(cti, 0, &desc);
3171 ok(hr == S_OK, "got %08x\n", hr);
3173 hr = ICreateTypeInfo_SetVarHelpContext(cti, 0, 0);
3174 ok(hr == S_OK, "got %08x\n", hr);
3176 /* another time */
3177 hr = ICreateTypeInfo_SetVarHelpContext(cti, 0, 1);
3178 ok(hr == S_OK, "got %08x\n", hr);
3180 /* wrong index now */
3181 hr = ICreateTypeInfo_SetVarHelpContext(cti, 1, 0);
3182 ok(hr == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hr);
3184 ICreateTypeInfo_Release(cti);
3185 ICreateTypeLib2_Release(ctl);
3186 DeleteFileA(filenameA);
3189 static void test_SetFuncAndParamNames(void)
3191 static OLECHAR nameW[] = {'n','a','m','e',0};
3192 static OLECHAR prop[] = {'p','r','o','p',0};
3193 static OLECHAR *propW[] = {prop};
3194 CHAR filenameA[MAX_PATH];
3195 WCHAR filenameW[MAX_PATH];
3196 ICreateTypeLib2 *ctl;
3197 ICreateTypeInfo *cti;
3198 FUNCDESC funcdesc;
3199 ELEMDESC edesc;
3200 HRESULT hr;
3202 GetTempFileNameA(".", "tlb", 0, filenameA);
3203 MultiByteToWideChar(CP_ACP, 0, filenameA, -1, filenameW, MAX_PATH);
3205 hr = CreateTypeLib2(SYS_WIN32, filenameW, &ctl);
3206 ok(hr == S_OK, "got %08x\n", hr);
3208 hr = ICreateTypeLib2_CreateTypeInfo(ctl, nameW, TKIND_DISPATCH, &cti);
3209 ok(hr == S_OK, "got %08x\n", hr);
3211 /* get method */
3212 memset(&funcdesc, 0, sizeof(FUNCDESC));
3213 funcdesc.funckind = FUNC_DISPATCH;
3214 funcdesc.callconv = CC_STDCALL;
3215 funcdesc.elemdescFunc.tdesc.vt = VT_VOID;
3216 funcdesc.wFuncFlags = FUNCFLAG_FBINDABLE;
3218 /* put method */
3219 memset(&edesc, 0, sizeof(edesc));
3220 edesc.tdesc.vt = VT_BSTR;
3221 U(edesc).idldesc.dwReserved = 0;
3222 U(edesc).idldesc.wIDLFlags = IDLFLAG_FIN;
3224 funcdesc.lprgelemdescParam = &edesc;
3225 funcdesc.invkind = INVOKE_PROPERTYPUT;
3226 funcdesc.cParams = 1;
3228 hr = ICreateTypeInfo_AddFuncDesc(cti, 0, &funcdesc);
3229 ok(hr == S_OK, "got 0x%08x\n", hr);
3231 /* setter name */
3232 hr = ICreateTypeInfo_SetFuncAndParamNames(cti, 0, propW, 1);
3233 ok(hr == S_OK, "got 0x%08x\n", hr);
3235 /* putref method */
3236 funcdesc.invkind = INVOKE_PROPERTYPUTREF;
3237 hr = ICreateTypeInfo_AddFuncDesc(cti, 1, &funcdesc);
3238 ok(hr == S_OK, "got 0x%08x\n", hr);
3240 /* putref name */
3241 hr = ICreateTypeInfo_SetFuncAndParamNames(cti, 1, propW, 1);
3242 ok(hr == S_OK, "got 0x%08x\n", hr);
3244 funcdesc.invkind = INVOKE_PROPERTYGET;
3245 funcdesc.cParams = 0;
3246 hr = ICreateTypeInfo_AddFuncDesc(cti, 2, &funcdesc);
3247 ok(hr == S_OK, "got 0x%08x\n", hr);
3249 /* getter name */
3250 hr = ICreateTypeInfo_SetFuncAndParamNames(cti, 2, propW, 1);
3251 ok(hr == S_OK, "got 0x%08x\n", hr);
3253 hr = ICreateTypeInfo_AddFuncDesc(cti, 3, &funcdesc);
3254 ok(hr == S_OK, "got 0x%08x\n", hr);
3256 /* getter name again */
3257 hr = ICreateTypeInfo_SetFuncAndParamNames(cti, 3, propW, 1);
3258 ok(hr == TYPE_E_AMBIGUOUSNAME, "got 0x%08x\n", hr);
3260 ICreateTypeInfo_Release(cti);
3261 ICreateTypeLib2_Release(ctl);
3262 DeleteFileA(filenameA);
3265 static void test_SetVarDocString(void)
3267 static OLECHAR nameW[] = {'n','a','m','e',0};
3268 static OLECHAR doc1W[] = {'d','o','c','1',0};
3269 static OLECHAR doc2W[] = {'d','o','c','2',0};
3270 CHAR filenameA[MAX_PATH];
3271 WCHAR filenameW[MAX_PATH];
3272 ICreateTypeLib2 *ctl;
3273 ICreateTypeInfo *cti;
3274 VARDESC desc;
3275 HRESULT hr;
3276 VARIANT v;
3278 GetTempFileNameA(".", "tlb", 0, filenameA);
3279 MultiByteToWideChar(CP_ACP, 0, filenameA, -1, filenameW, MAX_PATH);
3281 hr = CreateTypeLib2(SYS_WIN32, filenameW, &ctl);
3282 ok(hr == S_OK, "got %08x\n", hr);
3284 hr = ICreateTypeLib2_CreateTypeInfo(ctl, nameW, TKIND_ENUM, &cti);
3285 ok(hr == S_OK, "got %08x\n", hr);
3287 hr = ICreateTypeInfo_SetVarDocString(cti, 0, doc1W);
3288 ok(hr == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hr);
3290 hr = ICreateTypeInfo_SetVarDocString(cti, 0, NULL);
3291 ok(hr == E_INVALIDARG, "got %08x\n", hr);
3293 memset(&desc, 0, sizeof(desc));
3294 desc.elemdescVar.tdesc.vt = VT_INT;
3295 desc.varkind = VAR_CONST;
3297 V_VT(&v) = VT_INT;
3298 V_INT(&v) = 1;
3299 U(desc).lpvarValue = &v;
3300 hr = ICreateTypeInfo_AddVarDesc(cti, 0, &desc);
3301 ok(hr == S_OK, "got %08x\n", hr);
3303 hr = ICreateTypeInfo_SetVarDocString(cti, 0, NULL);
3304 ok(hr == E_INVALIDARG, "got %08x\n", hr);
3306 hr = ICreateTypeInfo_SetVarDocString(cti, 0, doc1W);
3307 ok(hr == S_OK, "got %08x\n", hr);
3309 /* already set */
3310 hr = ICreateTypeInfo_SetVarDocString(cti, 0, doc2W);
3311 ok(hr == S_OK, "got %08x\n", hr);
3313 /* wrong index now */
3314 hr = ICreateTypeInfo_SetVarDocString(cti, 1, doc1W);
3315 ok(hr == TYPE_E_ELEMENTNOTFOUND, "got %08x\n", hr);
3317 ICreateTypeInfo_Release(cti);
3318 ICreateTypeLib2_Release(ctl);
3319 DeleteFileA(filenameA);
3322 static void test_FindName(void)
3324 static const WCHAR invalidW[] = {'i','n','v','a','l','i','d',0};
3325 WCHAR buffW[100];
3326 MEMBERID memid;
3327 ITypeInfo *ti;
3328 ITypeLib *tl;
3329 HRESULT hr;
3330 UINT16 c;
3332 hr = LoadTypeLib(wszStdOle2, &tl);
3333 ok(hr == S_OK, "got 0x%08x\n", hr);
3335 hr = ITypeLib_FindName(tl, NULL, 0, NULL, NULL, NULL);
3336 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3338 lstrcpyW(buffW, wszGUID);
3339 hr = ITypeLib_FindName(tl, buffW, 0, NULL, NULL, NULL);
3340 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3342 c = 0;
3343 ti = (void*)0xdeadbeef;
3344 hr = ITypeLib_FindName(tl, buffW, 0, &ti, NULL, &c);
3345 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3346 ok(c == 0, "got %d\n", c);
3347 ok(ti == (void*)0xdeadbeef, "got %p\n", ti);
3349 c = 1;
3350 ti = (void*)0xdeadbeef;
3351 hr = ITypeLib_FindName(tl, buffW, 0, &ti, NULL, &c);
3352 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
3353 ok(c == 1, "got %d\n", c);
3354 ok(ti == (void*)0xdeadbeef, "got %p\n", ti);
3356 c = 1;
3357 memid = 0;
3358 ti = (void*)0xdeadbeef;
3359 hr = ITypeLib_FindName(tl, buffW, 0, &ti, &memid, &c);
3360 ok(hr == S_OK, "got 0x%08x\n", hr);
3361 todo_wine
3362 ok(memid == -1, "got %d\n", memid);
3363 ok(!lstrcmpW(buffW, wszGUID), "got %s\n", wine_dbgstr_w(buffW));
3364 ok(c == 1, "got %d\n", c);
3365 ITypeInfo_Release(ti);
3367 c = 1;
3368 memid = 0;
3369 lstrcpyW(buffW, wszguid);
3370 ti = (void*)0xdeadbeef;
3371 hr = ITypeLib_FindName(tl, buffW, 0, &ti, &memid, &c);
3372 ok(hr == S_OK, "got 0x%08x\n", hr);
3373 todo_wine {
3374 ok(memid == -1, "got %d\n", memid);
3375 ok(!lstrcmpW(buffW, wszGUID), "got %s\n", wine_dbgstr_w(buffW));
3376 ok(c == 1, "got %d\n", c);
3378 if (c == 1)
3379 ITypeInfo_Release(ti);
3381 c = 1;
3382 memid = -1;
3383 lstrcpyW(buffW, invalidW);
3384 ti = (void*)0xdeadbeef;
3385 hr = ITypeLib_FindName(tl, buffW, 0, &ti, &memid, &c);
3386 ok(hr == S_OK, "got 0x%08x\n", hr);
3387 ok(memid == -1, "got %d\n", memid);
3388 ok(!lstrcmpW(buffW, invalidW), "got %s\n", wine_dbgstr_w(buffW));
3389 ok(c == 0, "got %d\n", c);
3390 ok(ti == (void*)0xdeadbeef, "got %p\n", ti);
3392 ITypeLib_Release(tl);
3395 static void test_TypeInfo2_GetContainingTypeLib(void)
3397 static const WCHAR test[] = {'t','e','s','t','.','t','l','b',0};
3398 static OLECHAR testTI[] = {'t','e','s','t','T','y','p','e','I','n','f','o',0};
3400 ICreateTypeLib2 *ctl2;
3401 ICreateTypeInfo *cti;
3402 ITypeInfo2 *ti2;
3403 ITypeLib *tl;
3404 UINT Index;
3405 HRESULT hr;
3407 hr = CreateTypeLib2(SYS_WIN32, test, &ctl2);
3408 ok_ole_success(hr, CreateTypeLib2);
3410 hr = ICreateTypeLib2_CreateTypeInfo(ctl2, testTI, TKIND_DISPATCH, &cti);
3411 ok_ole_success(hr, ICreateTypeLib2_CreateTypeInfo);
3413 hr = ICreateTypeInfo_QueryInterface(cti, &IID_ITypeInfo2, (void**)&ti2);
3414 ok_ole_success(hr, ICreateTypeInfo2_QueryInterface);
3416 tl = NULL;
3417 Index = 888;
3418 hr = ITypeInfo2_GetContainingTypeLib(ti2, &tl, &Index);
3419 ok_ole_success(hr, ITypeInfo2_GetContainingTypeLib);
3420 ok(tl != NULL, "ITypeInfo2_GetContainingTypeLib returned empty TypeLib\n");
3421 ok(Index == 0, "ITypeInfo2_GetContainingTypeLib returned Index = %u, expected 0\n", Index);
3422 if(tl) ITypeLib_Release(tl);
3424 tl = NULL;
3425 hr = ITypeInfo2_GetContainingTypeLib(ti2, &tl, NULL);
3426 ok_ole_success(hr, ITypeInfo2_GetContainingTypeLib);
3427 ok(tl != NULL, "ITypeInfo2_GetContainingTypeLib returned empty TypeLib\n");
3428 if(tl) ITypeLib_Release(tl);
3430 Index = 888;
3431 hr = ITypeInfo2_GetContainingTypeLib(ti2, NULL, &Index);
3432 ok_ole_success(hr, ITypeInfo2_GetContainingTypeLib);
3433 ok(Index == 0, "ITypeInfo2_GetContainingTypeLib returned Index = %u, expected 0\n", Index);
3435 hr = ITypeInfo2_GetContainingTypeLib(ti2, NULL, NULL);
3436 ok_ole_success(hr, ITypeInfo2_GetContainingTypeLib);
3438 ITypeInfo2_Release(ti2);
3439 ICreateTypeInfo_Release(cti);
3440 ICreateTypeLib2_Release(ctl2);
3443 START_TEST(typelib)
3445 const char *filename;
3447 init_function_pointers();
3449 ref_count_test(wszStdOle2);
3450 test_TypeComp();
3451 test_CreateDispTypeInfo();
3452 test_TypeInfo();
3453 test_DispCallFunc();
3454 test_QueryPathOfRegTypeLib(32);
3455 if(sizeof(void*) == 8)
3456 test_QueryPathOfRegTypeLib(64);
3457 test_inheritance();
3458 test_CreateTypeLib();
3459 test_SetVarHelpContext();
3460 test_SetFuncAndParamNames();
3461 test_SetVarDocString();
3462 test_FindName();
3464 if ((filename = create_test_typelib(2)))
3466 test_dump_typelib( filename );
3467 DeleteFile( filename );
3470 test_register_typelib(TRUE);
3471 test_register_typelib(FALSE);
3472 test_create_typelibs();
3473 test_LoadTypeLib();
3474 test_TypeInfo2_GetContainingTypeLib();