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
24 #include <wine/test.h>
37 #define expect_eq(expr, value, type, format) { type _ret = (expr); ok((value) == _ret, #expr " expected " format " got " format "\n", value, _ret); }
38 #define expect_int(expr, value) expect_eq(expr, (int)(value), int, "%d")
39 #define expect_hex(expr, value) expect_eq(expr, (int)(value), int, "0x%x")
40 #define expect_null(expr) expect_eq(expr, NULL, const void *, "%p")
42 #define expect_wstr_acpval(expr, value) \
45 expect_eq(!WideCharToMultiByte(CP_ACP, 0, (expr), -1, buf, 260, NULL, NULL), 0, int, "%d"); \
46 ok(lstrcmp(value, buf) == 0, #expr " expected \"%s\" got \"%s\"\n", value, buf); \
49 #define ole_expect(expr, expect) { \
51 ok(r == (expect), #expr " returned %x, expected %s (%x)\n", r, #expect, expect); \
54 #define ole_check(expr) ole_expect(expr, S_OK);
56 #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%08x\n", hr)
58 static const WCHAR wszStdOle2
[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
60 static void ref_count_test(LPCWSTR type_lib
)
63 ITypeInfo
*iti1
, *iti2
;
67 trace("Loading type library\n");
68 hRes
= LoadTypeLib(type_lib
, &iface
);
69 ok(hRes
== S_OK
, "Could not load type library\n");
73 hRes
= ITypeLib_GetTypeInfo(iface
, 1, &iti1
);
74 ok(hRes
== S_OK
, "ITypeLib_GetTypeInfo failed on index = 1\n");
75 ok(ref_count
=ITypeLib_Release(iface
) > 0, "ITypeLib destroyed while ITypeInfo has back pointer\n");
79 hRes
= ITypeLib_GetTypeInfo(iface
, 1, &iti2
);
80 ok(hRes
== S_OK
, "ITypeLib_GetTypeInfo failed on index = 1\n");
81 ok(iti1
== iti2
, "ITypeLib_GetTypeInfo returned different pointers for same indexes\n");
83 ITypeLib_AddRef(iface
);
84 ITypeInfo_Release(iti2
);
85 ITypeInfo_Release(iti1
);
86 ok(ITypeLib_Release(iface
) == 0, "ITypeLib should be destroyed here.\n");
89 static void test_TypeComp(void)
98 ITypeInfo
*pFontTypeInfo
;
99 static WCHAR wszStdFunctions
[] = {'S','t','d','F','u','n','c','t','i','o','n','s',0};
100 static WCHAR wszSavePicture
[] = {'S','a','v','e','P','i','c','t','u','r','e',0};
101 static WCHAR wszOLE_TRISTATE
[] = {'O','L','E','_','T','R','I','S','T','A','T','E',0};
102 static WCHAR wszUnchecked
[] = {'U','n','c','h','e','c','k','e','d',0};
103 static WCHAR wszIUnknown
[] = {'I','U','n','k','n','o','w','n',0};
104 static WCHAR wszFont
[] = {'F','o','n','t',0};
105 static WCHAR wszGUID
[] = {'G','U','I','D',0};
106 static WCHAR wszStdPicture
[] = {'S','t','d','P','i','c','t','u','r','e',0};
107 static WCHAR wszOLE_COLOR
[] = {'O','L','E','_','C','O','L','O','R',0};
108 static WCHAR wszClone
[] = {'C','l','o','n','e',0};
109 static WCHAR wszclone
[] = {'c','l','o','n','e',0};
111 hr
= LoadTypeLib(wszStdOle2
, &pTypeLib
);
112 ok_ole_success(hr
, LoadTypeLib
);
114 hr
= ITypeLib_GetTypeComp(pTypeLib
, &pTypeComp
);
115 ok_ole_success(hr
, ITypeLib_GetTypeComp
);
117 /* test getting a TKIND_MODULE */
118 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszStdFunctions
);
119 hr
= ITypeComp_Bind(pTypeComp
, wszStdFunctions
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
120 ok_ole_success(hr
, ITypeComp_Bind
);
122 ok(desckind
== DESCKIND_TYPECOMP
,
123 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
125 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
127 ITypeComp_Release(bindptr
.lptcomp
);
129 /* test getting a TKIND_MODULE with INVOKE_PROPERTYGET */
130 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszStdFunctions
);
131 hr
= ITypeComp_Bind(pTypeComp
, wszStdFunctions
, ulHash
, INVOKE_PROPERTYGET
, &pTypeInfo
, &desckind
, &bindptr
);
132 ok_ole_success(hr
, ITypeComp_Bind
);
134 ok(desckind
== DESCKIND_TYPECOMP
,
135 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
137 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
138 ITypeComp_Release(bindptr
.lptcomp
);
140 /* test getting a function within a TKIND_MODULE */
141 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszSavePicture
);
142 hr
= ITypeComp_Bind(pTypeComp
, wszSavePicture
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
143 ok_ole_success(hr
, ITypeComp_Bind
);
145 ok(desckind
== DESCKIND_FUNCDESC
,
146 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
148 ok(bindptr
.lpfuncdesc
!= NULL
, "bindptr.lpfuncdesc should not have been set to NULL\n");
149 ITypeInfo_ReleaseFuncDesc(pTypeInfo
, bindptr
.lpfuncdesc
);
150 ITypeInfo_Release(pTypeInfo
);
152 /* test getting a function within a TKIND_MODULE with INVOKE_PROPERTYGET */
153 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszSavePicture
);
154 hr
= ITypeComp_Bind(pTypeComp
, wszSavePicture
, ulHash
, INVOKE_PROPERTYGET
, &pTypeInfo
, &desckind
, &bindptr
);
155 ok(hr
== TYPE_E_TYPEMISMATCH
,
156 "ITypeComp_Bind should have failed with TYPE_E_TYPEMISMATCH instead of 0x%08x\n",
159 ok(desckind
== DESCKIND_NONE
,
160 "desckind should have been DESCKIND_NONE instead of %d\n",
162 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
163 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
165 /* test getting a TKIND_ENUM */
166 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszOLE_TRISTATE
);
167 hr
= ITypeComp_Bind(pTypeComp
, wszOLE_TRISTATE
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
168 ok_ole_success(hr
, ITypeComp_Bind
);
170 ok(desckind
== DESCKIND_TYPECOMP
,
171 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
173 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
175 ITypeComp_Release(bindptr
.lptcomp
);
177 /* test getting a value within a TKIND_ENUM */
178 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszUnchecked
);
179 hr
= ITypeComp_Bind(pTypeComp
, wszUnchecked
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
180 ok_ole_success(hr
, ITypeComp_Bind
);
182 ok(desckind
== DESCKIND_VARDESC
,
183 "desckind should have been DESCKIND_VARDESC instead of %d\n",
185 ITypeInfo_ReleaseVarDesc(pTypeInfo
, bindptr
.lpvardesc
);
186 ITypeInfo_Release(pTypeInfo
);
188 /* test getting a TKIND_INTERFACE */
189 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszIUnknown
);
190 hr
= ITypeComp_Bind(pTypeComp
, wszIUnknown
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
191 ok_ole_success(hr
, ITypeComp_Bind
);
193 ok(desckind
== DESCKIND_NONE
,
194 "desckind should have been DESCKIND_NONE instead of %d\n",
196 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
197 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
199 /* test getting a TKIND_DISPATCH */
200 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszFont
);
201 hr
= ITypeComp_Bind(pTypeComp
, wszFont
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
202 ok_ole_success(hr
, ITypeComp_Bind
);
204 ok(desckind
== DESCKIND_NONE
,
205 "desckind should have been DESCKIND_NONE instead of %d\n",
207 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
208 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
210 /* test getting a TKIND_RECORD/TKIND_ALIAS */
211 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszGUID
);
212 hr
= ITypeComp_Bind(pTypeComp
, wszGUID
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
213 ok_ole_success(hr
, ITypeComp_Bind
);
215 ok(desckind
== DESCKIND_NONE
,
216 "desckind should have been DESCKIND_NONE instead of %d\n",
218 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
219 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
221 /* test getting a TKIND_ALIAS */
222 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszOLE_COLOR
);
223 hr
= ITypeComp_Bind(pTypeComp
, wszOLE_COLOR
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
224 ok_ole_success(hr
, ITypeComp_Bind
);
226 ok(desckind
== DESCKIND_NONE
,
227 "desckind should have been DESCKIND_NONE instead of %d\n",
229 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
230 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
232 /* test getting a TKIND_COCLASS */
233 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszStdPicture
);
234 hr
= ITypeComp_Bind(pTypeComp
, wszStdPicture
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
235 ok_ole_success(hr
, ITypeComp_Bind
);
237 ok(desckind
== DESCKIND_NONE
,
238 "desckind should have been DESCKIND_NONE instead of %d\n",
240 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
241 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
243 ITypeComp_Release(pTypeComp
);
245 /* tests for ITypeComp on an interface */
246 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, &IID_IFont
, &pFontTypeInfo
);
247 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
249 hr
= ITypeInfo_GetTypeComp(pFontTypeInfo
, &pTypeComp
);
250 ok_ole_success(hr
, ITypeLib_GetTypeComp
);
252 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszClone
);
253 hr
= ITypeComp_Bind(pTypeComp
, wszClone
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
254 ok_ole_success(hr
, ITypeComp_Bind
);
256 ok(desckind
== DESCKIND_FUNCDESC
,
257 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
259 ok(bindptr
.lpfuncdesc
!= NULL
, "bindptr.lpfuncdesc should not have been set to NULL\n");
260 ITypeInfo_ReleaseFuncDesc(pTypeInfo
, bindptr
.lpfuncdesc
);
261 ITypeInfo_Release(pTypeInfo
);
263 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszClone
);
264 hr
= ITypeComp_Bind(pTypeComp
, wszClone
, ulHash
, INVOKE_PROPERTYGET
, &pTypeInfo
, &desckind
, &bindptr
);
265 ok(hr
== TYPE_E_TYPEMISMATCH
, "ITypeComp_Bind should have failed with TYPE_E_TYPEMISMATCH instead of 0x%08x\n", hr
);
267 ok(desckind
== DESCKIND_NONE
,
268 "desckind should have been DESCKIND_NONE instead of %d\n",
270 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
271 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
273 /* tests that the compare is case-insensitive */
274 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszclone
);
275 hr
= ITypeComp_Bind(pTypeComp
, wszclone
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
276 ok_ole_success(hr
, ITypeComp_Bind
);
278 ok(desckind
== DESCKIND_FUNCDESC
,
279 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
281 ok(bindptr
.lpfuncdesc
!= NULL
, "bindptr.lpfuncdesc should not have been set to NULL\n");
282 ITypeInfo_ReleaseFuncDesc(pTypeInfo
, bindptr
.lpfuncdesc
);
283 ITypeInfo_Release(pTypeInfo
);
285 ITypeComp_Release(pTypeComp
);
286 ITypeInfo_Release(pFontTypeInfo
);
287 ITypeLib_Release(pTypeLib
);
290 static void test_CreateDispTypeInfo(void)
292 ITypeInfo
*pTypeInfo
, *pTI2
;
294 INTERFACEDATA ifdata
;
295 METHODDATA methdata
[4];
303 static WCHAR func1
[] = {'f','u','n','c','1',0};
304 static const WCHAR func2
[] = {'f','u','n','c','2',0};
305 static const WCHAR func3
[] = {'f','u','n','c','3',0};
306 static const WCHAR parm1
[] = {'p','a','r','m','1',0};
307 static const WCHAR parm2
[] = {'p','a','r','m','2',0};
308 OLECHAR
*name
= func1
;
310 ifdata
.pmethdata
= methdata
;
311 ifdata
.cMembers
= sizeof(methdata
) / sizeof(methdata
[0]);
313 methdata
[0].szName
= SysAllocString(func1
);
314 methdata
[0].ppdata
= parms1
;
315 methdata
[0].dispid
= 0x123;
316 methdata
[0].iMeth
= 0;
317 methdata
[0].cc
= CC_STDCALL
;
318 methdata
[0].cArgs
= 2;
319 methdata
[0].wFlags
= DISPATCH_METHOD
;
320 methdata
[0].vtReturn
= VT_HRESULT
;
321 parms1
[0].szName
= SysAllocString(parm1
);
322 parms1
[0].vt
= VT_I4
;
323 parms1
[1].szName
= SysAllocString(parm2
);
324 parms1
[1].vt
= VT_BSTR
;
326 methdata
[1].szName
= SysAllocString(func2
);
327 methdata
[1].ppdata
= NULL
;
328 methdata
[1].dispid
= 0x124;
329 methdata
[1].iMeth
= 1;
330 methdata
[1].cc
= CC_STDCALL
;
331 methdata
[1].cArgs
= 0;
332 methdata
[1].wFlags
= DISPATCH_PROPERTYGET
;
333 methdata
[1].vtReturn
= VT_I4
;
335 methdata
[2].szName
= SysAllocString(func3
);
336 methdata
[2].ppdata
= parms3
;
337 methdata
[2].dispid
= 0x125;
338 methdata
[2].iMeth
= 3;
339 methdata
[2].cc
= CC_STDCALL
;
340 methdata
[2].cArgs
= 1;
341 methdata
[2].wFlags
= DISPATCH_PROPERTYPUT
;
342 methdata
[2].vtReturn
= VT_HRESULT
;
343 parms3
[0].szName
= SysAllocString(parm1
);
344 parms3
[0].vt
= VT_I4
;
346 methdata
[3].szName
= SysAllocString(func3
);
347 methdata
[3].ppdata
= NULL
;
348 methdata
[3].dispid
= 0x125;
349 methdata
[3].iMeth
= 4;
350 methdata
[3].cc
= CC_STDCALL
;
351 methdata
[3].cArgs
= 0;
352 methdata
[3].wFlags
= DISPATCH_PROPERTYGET
;
353 methdata
[3].vtReturn
= VT_I4
;
355 hr
= CreateDispTypeInfo(&ifdata
, LOCALE_NEUTRAL
, &pTypeInfo
);
356 ok(hr
== S_OK
, "hr %08x\n", hr
);
358 hr
= ITypeInfo_GetTypeAttr(pTypeInfo
, &pTypeAttr
);
359 ok(hr
== S_OK
, "hr %08x\n", hr
);
361 ok(pTypeAttr
->typekind
== TKIND_COCLASS
, "typekind %0x\n", pTypeAttr
->typekind
);
362 ok(pTypeAttr
->cImplTypes
== 1, "cImplTypes %d\n", pTypeAttr
->cImplTypes
);
363 ok(pTypeAttr
->cFuncs
== 0, "cFuncs %d\n", pTypeAttr
->cFuncs
);
364 ok(pTypeAttr
->wTypeFlags
== 0, "wTypeFlags %04x\n", pTypeAttr
->cFuncs
);
365 ITypeInfo_ReleaseTypeAttr(pTypeInfo
, pTypeAttr
);
367 hr
= ITypeInfo_GetRefTypeOfImplType(pTypeInfo
, 0, &href
);
368 ok(hr
== S_OK
, "hr %08x\n", hr
);
369 ok(href
== 0, "href = 0x%x\n", href
);
370 hr
= ITypeInfo_GetRefTypeInfo(pTypeInfo
, href
, &pTI2
);
371 ok(hr
== S_OK
, "hr %08x\n", hr
);
372 hr
= ITypeInfo_GetTypeAttr(pTI2
, &pTypeAttr
);
373 ok(hr
== S_OK
, "hr %08x\n", hr
);
374 ok(pTypeAttr
->typekind
== TKIND_INTERFACE
, "typekind %0x\n", pTypeAttr
->typekind
);
375 ok(pTypeAttr
->cFuncs
== 4, "cFuncs %d\n", pTypeAttr
->cFuncs
);
376 ok(IsEqualGUID(&pTypeAttr
->guid
, &GUID_NULL
), "guid {%08x-...}\n", pTypeAttr
->guid
.Data1
);
377 ok(pTypeAttr
->wTypeFlags
== 0, "typeflags %08x\n", pTypeAttr
->wTypeFlags
);
379 ITypeInfo_ReleaseTypeAttr(pTI2
, pTypeAttr
);
381 hr
= ITypeInfo_GetFuncDesc(pTI2
, 0, &pFuncDesc
);
382 ok(hr
== S_OK
, "hr %08x\n", hr
);
383 ok(pFuncDesc
->memid
== 0x123, "memid %x\n", pFuncDesc
->memid
);
384 ok(pFuncDesc
->funckind
== FUNC_VIRTUAL
, "funckind %d\n", pFuncDesc
->funckind
);
385 ok(pFuncDesc
->invkind
== methdata
[0].wFlags
, "invkind %d\n", pFuncDesc
->invkind
);
386 ok(pFuncDesc
->callconv
== methdata
[0].cc
, "callconv %d\n", pFuncDesc
->callconv
);
387 ok(pFuncDesc
->cParams
== methdata
[0].cArgs
, "cParams %d\n", pFuncDesc
->cParams
);
388 ok(pFuncDesc
->oVft
== 0, "oVft %d\n", pFuncDesc
->oVft
);
389 ok(pFuncDesc
->wFuncFlags
== 0, "oVft %d\n", pFuncDesc
->wFuncFlags
);
390 ok(pFuncDesc
->elemdescFunc
.tdesc
.vt
== VT_HRESULT
, "ret vt %x\n", pFuncDesc
->elemdescFunc
.tdesc
.vt
);
391 ok(pFuncDesc
->lprgelemdescParam
[0].tdesc
.vt
== VT_I4
, "parm 0 vt %x\n", pFuncDesc
->lprgelemdescParam
[0].tdesc
.vt
);
392 ok(U(pFuncDesc
->lprgelemdescParam
[0]).paramdesc
.wParamFlags
== PARAMFLAG_NONE
, "parm 0 flags %x\n", U(pFuncDesc
->lprgelemdescParam
[0]).paramdesc
.wParamFlags
);
394 ok(pFuncDesc
->lprgelemdescParam
[1].tdesc
.vt
== VT_BSTR
, "parm 1 vt %x\n", pFuncDesc
->lprgelemdescParam
[1].tdesc
.vt
);
395 ok(U(pFuncDesc
->lprgelemdescParam
[1]).paramdesc
.wParamFlags
== PARAMFLAG_NONE
, "parm 1 flags %x\n", U(pFuncDesc
->lprgelemdescParam
[1]).paramdesc
.wParamFlags
);
396 ITypeInfo_ReleaseFuncDesc(pTI2
, pFuncDesc
);
398 hr
= ITypeInfo_GetFuncDesc(pTI2
, 1, &pFuncDesc
);
399 ok(hr
== S_OK
, "hr %08x\n", hr
);
400 ok(pFuncDesc
->funckind
== FUNC_VIRTUAL
, "funckind %d\n", pFuncDesc
->funckind
);
401 ok(pFuncDesc
->invkind
== methdata
[1].wFlags
, "invkind %d\n", pFuncDesc
->invkind
);
402 ok(pFuncDesc
->callconv
== methdata
[1].cc
, "callconv %d\n", pFuncDesc
->callconv
);
403 ok(pFuncDesc
->cParams
== methdata
[1].cArgs
, "cParams %d\n", pFuncDesc
->cParams
);
404 ok(pFuncDesc
->oVft
== sizeof(void *), "oVft %d\n", pFuncDesc
->oVft
);
405 ok(pFuncDesc
->wFuncFlags
== 0, "oVft %d\n", pFuncDesc
->wFuncFlags
);
406 ok(pFuncDesc
->elemdescFunc
.tdesc
.vt
== VT_I4
, "ret vt %x\n", pFuncDesc
->elemdescFunc
.tdesc
.vt
);
407 ITypeInfo_ReleaseFuncDesc(pTI2
, pFuncDesc
);
409 hr
= ITypeInfo_GetFuncDesc(pTI2
, 2, &pFuncDesc
);
410 ok(hr
== S_OK
, "hr %08x\n", hr
);
411 ok(pFuncDesc
->funckind
== FUNC_VIRTUAL
, "funckind %d\n", pFuncDesc
->funckind
);
412 ok(pFuncDesc
->invkind
== methdata
[2].wFlags
, "invkind %d\n", pFuncDesc
->invkind
);
413 ok(pFuncDesc
->callconv
== methdata
[2].cc
, "callconv %d\n", pFuncDesc
->callconv
);
414 ok(pFuncDesc
->cParams
== methdata
[2].cArgs
, "cParams %d\n", pFuncDesc
->cParams
);
415 ok(pFuncDesc
->oVft
== 3 * sizeof(void *), "oVft %d\n", pFuncDesc
->oVft
);
416 ok(pFuncDesc
->wFuncFlags
== 0, "oVft %d\n", pFuncDesc
->wFuncFlags
);
417 ok(pFuncDesc
->elemdescFunc
.tdesc
.vt
== VT_HRESULT
, "ret vt %x\n", pFuncDesc
->elemdescFunc
.tdesc
.vt
);
418 ok(pFuncDesc
->lprgelemdescParam
[0].tdesc
.vt
== VT_I4
, "parm 0 vt %x\n", pFuncDesc
->lprgelemdescParam
[0].tdesc
.vt
);
419 ok(U(pFuncDesc
->lprgelemdescParam
[0]).paramdesc
.wParamFlags
== PARAMFLAG_NONE
, "parm 0 flags %x\n", U(pFuncDesc
->lprgelemdescParam
[0]).paramdesc
.wParamFlags
);
420 ITypeInfo_ReleaseFuncDesc(pTI2
, pFuncDesc
);
422 hr
= ITypeInfo_GetFuncDesc(pTI2
, 3, &pFuncDesc
);
423 ok(hr
== S_OK
, "hr %08x\n", hr
);
424 ok(pFuncDesc
->funckind
== FUNC_VIRTUAL
, "funckind %d\n", pFuncDesc
->funckind
);
425 ok(pFuncDesc
->invkind
== methdata
[3].wFlags
, "invkind %d\n", pFuncDesc
->invkind
);
426 ok(pFuncDesc
->callconv
== methdata
[3].cc
, "callconv %d\n", pFuncDesc
->callconv
);
427 ok(pFuncDesc
->cParams
== methdata
[3].cArgs
, "cParams %d\n", pFuncDesc
->cParams
);
428 ok(pFuncDesc
->oVft
== 4 * sizeof(void *), "oVft %d\n", pFuncDesc
->oVft
);
429 ok(pFuncDesc
->wFuncFlags
== 0, "oVft %d\n", pFuncDesc
->wFuncFlags
);
430 ok(pFuncDesc
->elemdescFunc
.tdesc
.vt
== VT_I4
, "ret vt %x\n", pFuncDesc
->elemdescFunc
.tdesc
.vt
);
431 ITypeInfo_ReleaseFuncDesc(pTI2
, pFuncDesc
);
433 /* test GetIDsOfNames on a coclass to see if it searches its interfaces */
434 hr
= ITypeInfo_GetIDsOfNames(pTypeInfo
, &name
, 1, &memid
);
435 ok(hr
== S_OK
, "hr 0x%08x\n", hr
);
436 ok(memid
== 0x123, "memid 0x%08x\n", memid
);
438 ITypeInfo_Release(pTI2
);
439 ITypeInfo_Release(pTypeInfo
);
441 SysFreeString(parms1
[0].szName
);
442 SysFreeString(parms1
[1].szName
);
443 SysFreeString(parms3
[0].szName
);
444 SysFreeString(methdata
[0].szName
);
445 SysFreeString(methdata
[1].szName
);
446 SysFreeString(methdata
[2].szName
);
447 SysFreeString(methdata
[3].szName
);
450 static void test_TypeInfo(void)
453 ITypeInfo
*pTypeInfo
;
454 ITypeInfo2
*pTypeInfo2
;
456 static WCHAR wszBogus
[] = { 'b','o','g','u','s',0 };
457 static WCHAR wszGetTypeInfo
[] = { 'G','e','t','T','y','p','e','I','n','f','o',0 };
458 static WCHAR wszClone
[] = {'C','l','o','n','e',0};
459 OLECHAR
* bogus
= wszBogus
;
460 OLECHAR
* pwszGetTypeInfo
= wszGetTypeInfo
;
461 OLECHAR
* pwszClone
= wszClone
;
463 DISPPARAMS dispparams
;
464 GUID bogusguid
= {0x806afb4f,0x13f7,0x42d2,{0x89,0x2c,0x6c,0x97,0xc3,0x6a,0x36,0xc1}};
467 hr
= LoadTypeLib(wszStdOle2
, &pTypeLib
);
468 ok_ole_success(hr
, LoadTypeLib
);
470 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, &IID_IFont
, &pTypeInfo
);
471 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
473 /* test nonexistent method name */
474 hr
= ITypeInfo_GetIDsOfNames(pTypeInfo
, &bogus
, 1, &dispidMember
);
475 ok(hr
== DISP_E_UNKNOWNNAME
,
476 "ITypeInfo_GetIDsOfNames should have returned DISP_E_UNKNOWNNAME instead of 0x%08x\n",
479 /* test invalid memberid */
480 dispparams
.cNamedArgs
= 0;
481 dispparams
.cArgs
= 0;
482 dispparams
.rgdispidNamedArgs
= NULL
;
483 dispparams
.rgvarg
= NULL
;
484 hr
= ITypeInfo_Invoke(pTypeInfo
, (void *)0xdeadbeef, 0xdeadbeef, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
485 ok(hr
== DISP_E_MEMBERNOTFOUND
, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr
);
487 hr
= ITypeInfo_GetIDsOfNames(pTypeInfo
, &pwszClone
, 1, &dispidMember
);
488 ok_ole_success(hr
, ITypeInfo_GetIDsOfNames
);
490 /* test correct memberid, but wrong flags */
491 hr
= ITypeInfo_Invoke(pTypeInfo
, (void *)0xdeadbeef, dispidMember
, DISPATCH_PROPERTYGET
, &dispparams
, NULL
, NULL
, NULL
);
492 ok(hr
== DISP_E_MEMBERNOTFOUND
, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr
);
494 /* test NULL dispparams */
495 hr
= ITypeInfo_Invoke(pTypeInfo
, (void *)0xdeadbeef, dispidMember
, DISPATCH_METHOD
, NULL
, NULL
, NULL
, NULL
);
496 ok(hr
== E_INVALIDARG
, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
498 /* test dispparams->cNamedArgs being bigger than dispparams->cArgs */
499 dispparams
.cNamedArgs
= 1;
500 hr
= ITypeInfo_Invoke(pTypeInfo
, (void *)0xdeadbeef, dispidMember
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
501 ok(hr
== E_INVALIDARG
, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
503 ITypeInfo_Release(pTypeInfo
);
505 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, &IID_IDispatch
, &pTypeInfo
);
506 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
508 hr
= ITypeInfo_GetIDsOfNames(pTypeInfo
, &pwszGetTypeInfo
, 1, &dispidMember
);
509 ok_ole_success(hr
, ITypeInfo_GetIDsOfNames
);
511 hr
= ITypeInfo_QueryInterface(pTypeInfo
, &IID_ITypeInfo2
, (void**)&pTypeInfo2
);
512 ok_ole_success(hr
, ITypeInfo_QueryInterface
);
520 /* test unknown guid passed to GetCustData */
521 hr
= ITypeInfo2_GetCustData(pTypeInfo2
, &bogusguid
, &var
);
522 ok_ole_success(hr
, ITypeInfo_GetCustData
);
523 ok(V_VT(&var
) == VT_EMPTY
, "got %i, expected VT_EMPTY\n", V_VT(&var
));
525 ITypeInfo2_Release(pTypeInfo2
);
530 /* test invoking a method with a [restricted] keyword */
531 hr
= ITypeInfo_Invoke(pTypeInfo
, NULL
, dispidMember
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
533 ok(hr
== DISP_E_MEMBERNOTFOUND
, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr
);
536 ITypeInfo_Release(pTypeInfo
);
537 ITypeLib_Release(pTypeLib
);
540 /* RegDeleteTreeW from dlls/advapi32/registry.c */
541 static LSTATUS
myRegDeleteTreeW(HKEY hKey
, LPCWSTR lpszSubKey
)
544 DWORD dwMaxSubkeyLen
, dwMaxValueLen
;
545 DWORD dwMaxLen
, dwSize
;
546 WCHAR szNameBuf
[MAX_PATH
], *lpszName
= szNameBuf
;
551 ret
= RegOpenKeyExW(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
555 ret
= RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, NULL
,
556 &dwMaxSubkeyLen
, NULL
, NULL
, &dwMaxValueLen
, NULL
, NULL
, NULL
);
557 if (ret
) goto cleanup
;
561 dwMaxLen
= max(dwMaxSubkeyLen
, dwMaxValueLen
);
562 if (dwMaxLen
> sizeof(szNameBuf
)/sizeof(WCHAR
))
564 /* Name too big: alloc a buffer for it */
565 if (!(lpszName
= HeapAlloc( GetProcessHeap(), 0, dwMaxLen
*sizeof(WCHAR
))))
567 ret
= ERROR_NOT_ENOUGH_MEMORY
;
572 /* Recursively delete all the subkeys */
576 if (RegEnumKeyExW(hSubKey
, 0, lpszName
, &dwSize
, NULL
,
577 NULL
, NULL
, NULL
)) break;
579 ret
= myRegDeleteTreeW(hSubKey
, lpszName
);
580 if (ret
) goto cleanup
;
584 ret
= RegDeleteKeyW(hKey
, lpszSubKey
);
589 if (RegEnumValueW(hKey
, 0, lpszName
, &dwSize
,
590 NULL
, NULL
, NULL
, NULL
)) break;
592 ret
= RegDeleteValueW(hKey
, lpszName
);
593 if (ret
) goto cleanup
;
597 if (lpszName
!= szNameBuf
)
598 HeapFree(GetProcessHeap(), 0, lpszName
);
600 RegCloseKey(hSubKey
);
604 static BOOL
do_typelib_reg_key(GUID
*uid
, WORD maj
, WORD min
, LPCWSTR base
, BOOL remove
)
606 static const WCHAR typelibW
[] = {'T','y','p','e','l','i','b','\\',0};
607 static const WCHAR formatW
[] = {'\\','%','u','.','%','u','\\','0','\\','w','i','n','3','2',0};
608 static const WCHAR format2W
[] = {'%','s','_','%','u','_','%','u','.','d','l','l',0};
614 memcpy(buf
, typelibW
, sizeof(typelibW
));
615 StringFromGUID2(uid
, buf
+ lstrlenW(buf
), 40);
619 ok(myRegDeleteTreeW(HKEY_CLASSES_ROOT
, buf
) == ERROR_SUCCESS
, "SHDeleteKey failed\n");
623 wsprintfW(buf
+ lstrlenW(buf
), formatW
, maj
, min
);
625 SetLastError(0xdeadbeef);
626 res
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, buf
, 0, NULL
, 0,
627 KEY_WRITE
, NULL
, &hkey
, NULL
);
628 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
630 win_skip("W-calls are not implemented\n");
634 if (res
!= ERROR_SUCCESS
)
636 trace("RegCreateKeyExW failed\n");
640 wsprintfW(buf
, format2W
, base
, maj
, min
);
641 if (RegSetValueExW(hkey
, NULL
, 0, REG_SZ
,
642 (BYTE
*)buf
, (lstrlenW(buf
) + 1) * sizeof(WCHAR
)) != ERROR_SUCCESS
)
644 trace("RegSetValueExW failed\n");
651 static void test_QueryPathOfRegTypeLib(void)
653 static const struct test_data
657 const WCHAR path
[16];
659 { 1, 0, TYPE_E_LIBNOTREGISTERED
, { 0 } },
660 { 3, 0, S_OK
, {'f','a','k','e','_','3','_','0','.','d','l','l',0 } },
661 { 3, 1, S_OK
, {'f','a','k','e','_','3','_','1','.','d','l','l',0 } },
662 { 3, 22, S_OK
, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
663 { 3, 37, S_OK
, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
664 { 3, 40, S_OK
, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
665 { 0xffff, 0xffff, S_OK
, {'f','a','k','e','_','5','_','3','7','.','d','l','l',0 } },
666 { 0xffff, 0, TYPE_E_LIBNOTREGISTERED
, { 0 } },
667 { 3, 0xffff, TYPE_E_LIBNOTREGISTERED
, { 0 } },
668 { 5, 0xffff, TYPE_E_LIBNOTREGISTERED
, { 0 } },
669 { 4, 0, TYPE_E_LIBNOTREGISTERED
, { 0 } }
671 static const WCHAR base
[] = {'f','a','k','e',0};
679 status
= UuidCreate(&uid
);
680 ok(!status
|| status
== RPC_S_UUID_LOCAL_ONLY
, "UuidCreate error %08x\n", status
);
682 StringFromGUID2(&uid
, uid_str
, 40);
683 /*trace("GUID: %s\n", wine_dbgstr_w(uid_str));*/
685 if (!do_typelib_reg_key(&uid
, 3, 0, base
, 0)) return;
686 if (!do_typelib_reg_key(&uid
, 3, 1, base
, 0)) return;
687 if (!do_typelib_reg_key(&uid
, 3, 37, base
, 0)) return;
688 if (!do_typelib_reg_key(&uid
, 5, 37, base
, 0)) return;
690 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
692 ret
= QueryPathOfRegTypeLib(&uid
, td
[i
].maj
, td
[i
].min
, 0, &path
);
693 ok(ret
== td
[i
].ret
, "QueryPathOfRegTypeLib(%u.%u) returned %08x\n", td
[i
].maj
, td
[i
].min
, ret
);
696 ok(!lstrcmpW(td
[i
].path
, path
), "typelib %u.%u path doesn't match\n", td
[i
].maj
, td
[i
].min
);
701 do_typelib_reg_key(&uid
, 0, 0, NULL
, 1);
704 static void test_inheritance(void)
708 ITypeInfo
*pTI
, *pTI_p
;
712 WCHAR path
[MAX_PATH
];
713 CHAR pathA
[MAX_PATH
];
714 static const WCHAR tl_path
[] = {'.','\\','m','i','d','l','_','t','m','a','r','s','h','a','l','.','t','l','b',0};
716 BOOL use_midl_tlb
= 0;
718 GetModuleFileNameA(NULL
, pathA
, MAX_PATH
);
719 MultiByteToWideChar(CP_ACP
, 0, pathA
, -1, path
, MAX_PATH
);
722 memcpy(path
, tl_path
, sizeof(tl_path
));
724 hr
= LoadTypeLib(path
, &pTL
);
725 if(FAILED(hr
)) return;
728 /* ItestIF3 is a syntax 2 dispinterface */
729 hr
= ITypeLib_GetTypeInfoOfGuid(pTL
, &DIID_ItestIF3
, &pTI
);
730 ok(hr
== S_OK
, "hr %08x\n", hr
);
732 hr
= ITypeInfo_GetTypeAttr(pTI
, &pTA
);
733 ok(hr
== S_OK
, "hr %08x\n", hr
);
734 ok(pTA
->typekind
== TKIND_DISPATCH
, "kind %04x\n", pTA
->typekind
);
735 ok(pTA
->cbSizeVft
== 7 * sizeof(void *), "sizevft %d\n", pTA
->cbSizeVft
);
736 ok(pTA
->wTypeFlags
== TYPEFLAG_FDISPATCHABLE
, "typeflags %x\n", pTA
->wTypeFlags
);
738 ok(pTA
->cFuncs
== 6, "cfuncs %d\n", pTA
->cFuncs
);
739 ok(pTA
->cImplTypes
== 1, "cimpltypes %d\n", pTA
->cImplTypes
);
741 ITypeInfo_ReleaseTypeAttr(pTI
, pTA
);
744 hr
= ITypeInfo_GetRefTypeOfImplType(pTI
, 0, &href
);
745 ok(hr
== S_OK
, "hr %08x\n", hr
);
746 hr
= ITypeInfo_GetRefTypeInfo(pTI
, href
, &pTI_p
);
747 ok(hr
== S_OK
, "hr %08x\n", hr
);
748 hr
= ITypeInfo_GetTypeAttr(pTI_p
, &pTA
);
749 ok(IsEqualGUID(&pTA
->guid
, &IID_IDispatch
), "guid {%08x-....\n", pTA
->guid
.Data1
);
750 ITypeInfo_ReleaseTypeAttr(pTI_p
, pTA
);
751 ITypeInfo_Release(pTI_p
);
753 /* Should have six methods */
754 hr
= ITypeInfo_GetFuncDesc(pTI
, 6, &pFD
);
755 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "hr %08x\n", hr
);
756 hr
= ITypeInfo_GetFuncDesc(pTI
, 5, &pFD
);
757 ok(hr
== S_OK
, "hr %08x\n", hr
);
758 ok(pFD
->memid
== 0x60020000, "memid %08x\n", pFD
->memid
);
759 ok(pFD
->oVft
== 5 * sizeof(void *), "oVft %d\n", pFD
->oVft
);
760 ITypeInfo_ReleaseFuncDesc(pTI
, pFD
);
762 ITypeInfo_Release(pTI
);
765 /* ItestIF4 is a syntax 1 dispinterface */
766 hr
= ITypeLib_GetTypeInfoOfGuid(pTL
, &DIID_ItestIF4
, &pTI
);
767 ok(hr
== S_OK
, "hr %08x\n", hr
);
769 hr
= ITypeInfo_GetTypeAttr(pTI
, &pTA
);
770 ok(hr
== S_OK
, "hr %08x\n", hr
);
771 ok(pTA
->typekind
== TKIND_DISPATCH
, "kind %04x\n", pTA
->typekind
);
772 ok(pTA
->cbSizeVft
== 7 * sizeof(void *), "sizevft %d\n", pTA
->cbSizeVft
);
773 ok(pTA
->wTypeFlags
== TYPEFLAG_FDISPATCHABLE
, "typeflags %x\n", pTA
->wTypeFlags
);
774 ok(pTA
->cFuncs
== 1, "cfuncs %d\n", pTA
->cFuncs
);
775 ok(pTA
->cImplTypes
== 1, "cimpltypes %d\n", pTA
->cImplTypes
);
776 ITypeInfo_ReleaseTypeAttr(pTI
, pTA
);
778 hr
= ITypeInfo_GetRefTypeOfImplType(pTI
, 0, &href
);
779 ok(hr
== S_OK
, "hr %08x\n", hr
);
780 hr
= ITypeInfo_GetRefTypeInfo(pTI
, href
, &pTI_p
);
781 ok(hr
== S_OK
, "hr %08x\n", hr
);
782 hr
= ITypeInfo_GetTypeAttr(pTI_p
, &pTA
);
783 ok(IsEqualGUID(&pTA
->guid
, &IID_IDispatch
), "guid {%08x-....\n", pTA
->guid
.Data1
);
784 ITypeInfo_ReleaseTypeAttr(pTI_p
, pTA
);
785 ITypeInfo_Release(pTI_p
);
786 hr
= ITypeInfo_GetFuncDesc(pTI
, 1, &pFD
);
787 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "hr %08x\n", hr
);
788 hr
= ITypeInfo_GetFuncDesc(pTI
, 0, &pFD
);
789 ok(hr
== S_OK
, "hr %08x\n", hr
);
790 ok(pFD
->memid
== 0x1c, "memid %08x\n", pFD
->memid
);
791 ITypeInfo_ReleaseFuncDesc(pTI
, pFD
);
792 ITypeInfo_Release(pTI
);
795 /* ItestIF5 is dual with inherited ifaces which derive from IUnknown but not IDispatch */
796 hr
= ITypeLib_GetTypeInfoOfGuid(pTL
, &IID_ItestIF5
, &pTI
);
797 ok(hr
== S_OK
, "hr %08x\n", hr
);
799 hr
= ITypeInfo_GetTypeAttr(pTI
, &pTA
);
800 ok(hr
== S_OK
, "hr %08x\n", hr
);
803 ok(pTA
->typekind
== TKIND_DISPATCH
, "kind %04x\n", pTA
->typekind
);
804 ok(pTA
->cbSizeVft
== 7 * sizeof(void *), "sizevft %d\n", pTA
->cbSizeVft
);
806 ok(pTA
->wTypeFlags
== TYPEFLAG_FDUAL
, "typeflags %x\n", pTA
->wTypeFlags
);
808 ok(pTA
->cFuncs
== 8, "cfuncs %d\n", pTA
->cFuncs
);
809 ok(pTA
->cImplTypes
== 1, "cimpltypes %d\n", pTA
->cImplTypes
);
810 ITypeInfo_ReleaseTypeAttr(pTI
, pTA
);
812 hr
= ITypeInfo_GetRefTypeOfImplType(pTI
, 0, &href
);
813 ok(hr
== S_OK
, "hr %08x\n", hr
);
814 hr
= ITypeInfo_GetRefTypeInfo(pTI
, href
, &pTI_p
);
815 ok(hr
== S_OK
, "hr %08x\n", hr
);
816 hr
= ITypeInfo_GetTypeAttr(pTI_p
, &pTA
);
817 ok(IsEqualGUID(&pTA
->guid
, &IID_IDispatch
), "guid {%08x-....\n", pTA
->guid
.Data1
);
818 ITypeInfo_ReleaseTypeAttr(pTI_p
, pTA
);
819 ITypeInfo_Release(pTI_p
);
821 hr
= ITypeInfo_GetFuncDesc(pTI
, 6, &pFD
);
822 ok(hr
== S_OK
, "hr %08x\n", hr
);
823 ok(pFD
->memid
== 0x1234, "memid %08x\n", pFD
->memid
);
824 ITypeInfo_ReleaseFuncDesc(pTI
, pFD
);
826 ITypeInfo_Release(pTI
);
828 /* ItestIF7 is dual with inherited ifaces which derive from Dispatch */
829 hr
= ITypeLib_GetTypeInfoOfGuid(pTL
, &IID_ItestIF7
, &pTI
);
830 ok(hr
== S_OK
, "hr %08x\n", hr
);
832 hr
= ITypeInfo_GetTypeAttr(pTI
, &pTA
);
833 ok(hr
== S_OK
, "hr %08x\n", hr
);
834 ok(pTA
->typekind
== TKIND_DISPATCH
, "kind %04x\n", pTA
->typekind
);
835 ok(pTA
->cbSizeVft
== 7 * sizeof(void *), "sizevft %d\n", pTA
->cbSizeVft
);
836 ok(pTA
->wTypeFlags
== (TYPEFLAG_FDISPATCHABLE
|TYPEFLAG_FDUAL
), "typeflags %x\n", pTA
->wTypeFlags
);
837 ok(pTA
->cFuncs
== 10, "cfuncs %d\n", pTA
->cFuncs
);
838 ok(pTA
->cImplTypes
== 1, "cimpltypes %d\n", pTA
->cImplTypes
);
839 ITypeInfo_ReleaseTypeAttr(pTI
, pTA
);
841 hr
= ITypeInfo_GetRefTypeOfImplType(pTI
, 0, &href
);
842 ok(hr
== S_OK
, "hr %08x\n", hr
);
843 hr
= ITypeInfo_GetRefTypeInfo(pTI
, href
, &pTI_p
);
844 ok(hr
== S_OK
, "hr %08x\n", hr
);
845 hr
= ITypeInfo_GetTypeAttr(pTI_p
, &pTA
);
846 ok(IsEqualGUID(&pTA
->guid
, &IID_IDispatch
), "guid {%08x-....\n", pTA
->guid
.Data1
);
847 ITypeInfo_ReleaseTypeAttr(pTI_p
, pTA
);
848 ITypeInfo_Release(pTI_p
);
850 hr
= ITypeInfo_GetFuncDesc(pTI
, 9, &pFD
);
851 ok(hr
== S_OK
, "hr %08x\n", hr
);
852 ok(pFD
->memid
== 0x1236, "memid %08x\n", pFD
->memid
);
853 ITypeInfo_ReleaseFuncDesc(pTI
, pFD
);
854 ITypeInfo_Release(pTI
);
856 /* ItestIF10 is a syntax 2 dispinterface which doesn't derive from IUnknown */
857 hr
= ITypeLib_GetTypeInfoOfGuid(pTL
, &DIID_ItestIF10
, &pTI
);
858 ok(hr
== S_OK
, "hr %08x\n", hr
);
860 hr
= ITypeInfo_GetTypeAttr(pTI
, &pTA
);
861 ok(hr
== S_OK
, "hr %08x\n", hr
);
862 ok(pTA
->typekind
== TKIND_DISPATCH
, "kind %04x\n", pTA
->typekind
);
863 ok(pTA
->cbSizeVft
== 7 * sizeof(void *), "sizevft %d\n", pTA
->cbSizeVft
);
864 ok(pTA
->wTypeFlags
== TYPEFLAG_FDISPATCHABLE
, "typeflags %x\n", pTA
->wTypeFlags
);
866 ok(pTA
->cFuncs
== 3, "cfuncs %d\n", pTA
->cFuncs
);
867 ok(pTA
->cImplTypes
== 1, "cimpltypes %d\n", pTA
->cImplTypes
);
869 ITypeInfo_ReleaseTypeAttr(pTI
, pTA
);
872 hr
= ITypeInfo_GetRefTypeOfImplType(pTI
, -1, &href
);
873 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "hr %08x\n", hr
);
874 hr
= ITypeInfo_GetRefTypeOfImplType(pTI
, 0, &href
);
875 ok(hr
== S_OK
, "hr %08x\n", hr
);
876 hr
= ITypeInfo_GetRefTypeInfo(pTI
, href
, &pTI_p
);
877 ok(hr
== S_OK
, "hr %08x\n", hr
);
878 hr
= ITypeInfo_GetTypeAttr(pTI_p
, &pTA
);
879 ok(IsEqualGUID(&pTA
->guid
, &IID_IDispatch
), "guid {%08x-....\n", pTA
->guid
.Data1
);
880 ITypeInfo_ReleaseTypeAttr(pTI_p
, pTA
);
881 ITypeInfo_Release(pTI_p
);
883 /* Should have three methods */
884 hr
= ITypeInfo_GetFuncDesc(pTI
, 3, &pFD
);
885 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "hr %08x\n", hr
);
886 hr
= ITypeInfo_GetFuncDesc(pTI
, 2, &pFD
);
887 ok(hr
== S_OK
, "hr %08x\n", hr
);
888 ok(pFD
->memid
== 0x60010000, "memid %08x\n", pFD
->memid
);
889 ok(pFD
->oVft
== 2 * sizeof(void *), "oVft %d\n", pFD
->oVft
);
890 ITypeInfo_ReleaseFuncDesc(pTI
, pFD
);
892 ITypeInfo_Release(pTI
);
894 /* ItestIF11 is a syntax 2 dispinterface which derives from IDispatch */
895 hr
= ITypeLib_GetTypeInfoOfGuid(pTL
, &DIID_ItestIF11
, &pTI
);
896 ok(hr
== S_OK
, "hr %08x\n", hr
);
898 hr
= ITypeInfo_GetTypeAttr(pTI
, &pTA
);
899 ok(hr
== S_OK
, "hr %08x\n", hr
);
900 ok(pTA
->typekind
== TKIND_DISPATCH
, "kind %04x\n", pTA
->typekind
);
901 ok(pTA
->cbSizeVft
== 7 * sizeof(void *), "sizevft %d\n", pTA
->cbSizeVft
);
902 ok(pTA
->wTypeFlags
== TYPEFLAG_FDISPATCHABLE
, "typeflags %x\n", pTA
->wTypeFlags
);
904 ok(pTA
->cFuncs
== 10, "cfuncs %d\n", pTA
->cFuncs
);
905 ok(pTA
->cImplTypes
== 1, "cimpltypes %d\n", pTA
->cImplTypes
);
907 ITypeInfo_ReleaseTypeAttr(pTI
, pTA
);
910 hr
= ITypeInfo_GetRefTypeOfImplType(pTI
, 0, &href
);
911 ok(hr
== S_OK
, "hr %08x\n", hr
);
912 hr
= ITypeInfo_GetRefTypeInfo(pTI
, href
, &pTI_p
);
913 ok(hr
== S_OK
, "hr %08x\n", hr
);
914 hr
= ITypeInfo_GetTypeAttr(pTI_p
, &pTA
);
915 ok(IsEqualGUID(&pTA
->guid
, &IID_IDispatch
), "guid {%08x-....\n", pTA
->guid
.Data1
);
916 ITypeInfo_ReleaseTypeAttr(pTI_p
, pTA
);
917 ITypeInfo_Release(pTI_p
);
919 /* Should have ten methods */
920 hr
= ITypeInfo_GetFuncDesc(pTI
, 10, &pFD
);
921 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "hr %08x\n", hr
);
922 hr
= ITypeInfo_GetFuncDesc(pTI
, 9, &pFD
);
923 ok(hr
== S_OK
, "hr %08x\n", hr
);
924 ok(pFD
->memid
== 0x1236, "memid %08x\n", pFD
->memid
);
925 ok(pFD
->oVft
== 9 * sizeof(void *), "oVft %d\n", pFD
->oVft
);
927 /* first argument to 10th function is an HREFTYPE from the impl type */
928 ok(pFD
->cParams
== 1, "cParams %i\n", pFD
->cParams
);
929 ok(pFD
->lprgelemdescParam
[0].tdesc
.vt
== VT_USERDEFINED
,
930 "vt 0x%x\n", pFD
->lprgelemdescParam
[0].tdesc
.vt
);
931 href
= U(pFD
->lprgelemdescParam
[0].tdesc
).hreftype
;
932 ok((href
& 0xff000000) == 0x04000000, "href 0x%08x\n", href
);
933 hr
= ITypeInfo_GetRefTypeInfo(pTI
, href
, &pTI_p
);
934 ok(SUCCEEDED(hr
), "hr %08x\n", hr
);
935 if (SUCCEEDED(hr
)) ITypeInfo_Release(pTI_p
);
936 ITypeInfo_ReleaseFuncDesc(pTI
, pFD
);
938 ITypeInfo_Release(pTI
);
941 /* ItestIF2 is an interface which derives from IUnknown */
942 hr
= ITypeLib_GetTypeInfoOfGuid(pTL
, &IID_ItestIF2
, &pTI
);
943 ok(hr
== S_OK
, "hr %08x\n", hr
);
945 hr
= ITypeInfo_GetTypeAttr(pTI
, &pTA
);
946 ok(hr
== S_OK
, "hr %08x\n", hr
);
947 ok(pTA
->typekind
== TKIND_INTERFACE
, "kind %04x\n", pTA
->typekind
);
948 ok(pTA
->cbSizeVft
== 6 * sizeof(void *), "sizevft %d\n", pTA
->cbSizeVft
);
949 ok(pTA
->wTypeFlags
== 0, "typeflags %x\n", pTA
->wTypeFlags
);
951 ok(pTA
->cFuncs
== 1, "cfuncs %d\n", pTA
->cFuncs
);
952 ok(pTA
->cImplTypes
== 1, "cimpltypes %d\n", pTA
->cImplTypes
);
954 ITypeInfo_ReleaseTypeAttr(pTI
, pTA
);
957 /* Should have one method */
958 hr
= ITypeInfo_GetFuncDesc(pTI
, 1, &pFD
);
959 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "hr %08x\n", hr
);
960 hr
= ITypeInfo_GetFuncDesc(pTI
, 0, &pFD
);
961 ok(hr
== S_OK
, "hr %08x\n", hr
);
962 ok(pFD
->memid
== 0x60020000, "memid %08x\n", pFD
->memid
);
963 ok(pFD
->oVft
== 5 * sizeof(void *), "oVft %d\n", pFD
->oVft
);
964 ITypeInfo_ReleaseFuncDesc(pTI
, pFD
);
966 ITypeInfo_Release(pTI
);
968 ITypeLib_Release(pTL
);
973 static void test_CreateTypeLib(void) {
974 static const WCHAR stdoleW
[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
975 static OLECHAR typelibW
[] = {'t','y','p','e','l','i','b',0};
976 static OLECHAR helpfileW
[] = {'C',':','\\','b','o','g','u','s','.','h','l','p',0};
977 static OLECHAR interface1W
[] = {'i','n','t','e','r','f','a','c','e','1',0};
978 static OLECHAR interface2W
[] = {'i','n','t','e','r','f','a','c','e','2',0};
979 static OLECHAR interface3W
[] = {'i','n','t','e','r','f','a','c','e','3',0};
980 static OLECHAR dualW
[] = {'d','u','a','l',0};
981 static OLECHAR coclassW
[] = {'c','o','c','l','a','s','s',0};
982 static WCHAR defaultW
[] = {'d','e','f','a','u','l','t',0x3213,0};
983 static OLECHAR func1W
[] = {'f','u','n','c','1',0};
984 static OLECHAR func2W
[] = {'f','u','n','c','2',0};
985 static OLECHAR prop1W
[] = {'P','r','o','p','1',0};
986 static OLECHAR param1W
[] = {'p','a','r','a','m','1',0};
987 static OLECHAR param2W
[] = {'p','a','r','a','m','2',0};
988 static OLECHAR
*names1
[] = {func1W
, param1W
, param2W
};
989 static OLECHAR
*names2
[] = {func2W
, param1W
, param2W
};
990 static OLECHAR
*propname
[] = {prop1W
, param1W
};
991 static const GUID custguid
= {0xbf611abe,0x5b38,0x11df,{0x91,0x5c,0x08,0x02,0x79,0x79,0x94,0x70}};
993 char filename
[MAX_PATH
];
994 WCHAR filenameW
[MAX_PATH
];
995 ICreateTypeLib2
*createtl
;
996 ICreateTypeInfo
*createti
;
997 ICreateTypeInfo2
*createti2
;
998 ITypeLib
*tl
, *stdole
;
999 ITypeInfo
*interface1
, *interface2
, *dual
, *unknown
, *dispatch
, *ti
;
1002 ELEMDESC elemdesc
[5];
1003 PARAMDESCEX paramdescex
;
1004 TYPEDESC typedesc1
, typedesc2
;
1008 BSTR name
, docstring
, helpfile
;
1014 trace("CreateTypeLib tests\n");
1016 hres
= LoadTypeLib(stdoleW
, &stdole
);
1017 ok(hres
== S_OK
, "got %08x\n", hres
);
1019 hres
= ITypeLib_GetTypeInfoOfGuid(stdole
, &IID_IUnknown
, &unknown
);
1020 ok(hres
== S_OK
, "got %08x\n", hres
);
1022 hres
= ITypeLib_GetTypeInfoOfGuid(stdole
, &IID_IDispatch
, &dispatch
);
1023 ok(hres
== S_OK
, "got %08x\n", hres
);
1025 GetTempFileNameA(".", "tlb", 0, filename
);
1026 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, filenameW
, MAX_PATH
);
1028 hres
= CreateTypeLib2(SYS_WIN32
, filenameW
, &createtl
);
1029 ok(hres
== S_OK
, "got %08x\n", hres
);
1031 hres
= ICreateTypeLib_QueryInterface(createtl
, &IID_ITypeLib
, (void**)&tl
);
1032 ok(hres
== S_OK
, "got %08x\n", hres
);
1034 hres
= ITypeLib_GetLibAttr(tl
, &libattr
);
1035 ok(hres
== S_OK
, "got %08x\n", hres
);
1037 ok(libattr
->syskind
== SYS_WIN32
, "syskind = %d\n", libattr
->syskind
);
1038 ok(libattr
->wMajorVerNum
== 0, "wMajorVer = %d\n", libattr
->wMajorVerNum
);
1039 ok(libattr
->wMinorVerNum
== 0, "wMinorVerNum = %d\n", libattr
->wMinorVerNum
);
1040 ok(libattr
->wLibFlags
== 0, "wLibFlags = %d\n", libattr
->wLibFlags
);
1042 ITypeLib_ReleaseTLibAttr(tl
, libattr
);
1044 name
= (BSTR
)0xdeadbeef;
1045 hres
= ITypeLib_GetDocumentation(tl
, -1, &name
, &docstring
, &helpcontext
, &helpfile
);
1046 ok(hres
== S_OK
, "got %08x\n", hres
);
1047 ok(name
== NULL
, "name != NULL\n");
1048 ok(docstring
== NULL
, "docstring != NULL\n");
1049 ok(helpcontext
== 0, "helpcontext != 0\n");
1050 ok(helpfile
== NULL
, "helpfile != NULL\n");
1052 hres
= ITypeLib_GetDocumentation(tl
, 0, &name
, NULL
, NULL
, NULL
);
1053 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1055 hres
= ICreateTypeLib_SetName(createtl
, typelibW
);
1056 ok(hres
== S_OK
, "got %08x\n", hres
);
1058 hres
= ICreateTypeLib_SetHelpFileName(createtl
, helpfileW
);
1059 ok(hres
== S_OK
, "got %08x\n", hres
);
1061 hres
= ITypeLib_GetDocumentation(tl
, -1, NULL
, NULL
, NULL
, NULL
);
1062 ok(hres
== S_OK
, "got %08x\n", hres
);
1064 hres
= ITypeLib_GetDocumentation(tl
, -1, &name
, NULL
, NULL
, &helpfile
);
1065 ok(hres
== S_OK
, "got %08x\n", hres
);
1066 ok(!memcmp(name
, typelibW
, sizeof(typelibW
)), "name = %s\n", wine_dbgstr_w(name
));
1067 ok(!memcmp(helpfile
, helpfileW
, sizeof(helpfileW
)), "helpfile = %s\n", wine_dbgstr_w(helpfile
));
1069 SysFreeString(name
);
1070 SysFreeString(helpfile
);
1072 hres
= ICreateTypeLib_CreateTypeInfo(createtl
, interface1W
, TKIND_INTERFACE
, &createti
);
1073 ok(hres
== S_OK
, "got %08x\n", hres
);
1075 hres
= ICreateTypeInfo_QueryInterface(createti
, &IID_ITypeInfo
, (void**)&interface1
);
1076 ok(hres
== S_OK
, "got %08x\n", hres
);
1078 hres
= ITypeLib_GetDocumentation(tl
, 0, &name
, NULL
, NULL
, NULL
);
1079 ok(hres
== S_OK
, "got %08x\n", hres
);
1080 ok(!memcmp(name
, interface1W
, sizeof(interface1W
)), "name = %s\n", wine_dbgstr_w(name
));
1082 SysFreeString(name
);
1084 ITypeLib_Release(tl
);
1086 name
= (BSTR
)0xdeadbeef;
1087 helpfile
= (BSTR
)0xdeadbeef;
1088 hres
= ITypeInfo_GetDocumentation(interface1
, -1, &name
, &docstring
, &helpcontext
, &helpfile
);
1089 ok(hres
== S_OK
, "got %08x\n", hres
);
1090 ok(!memcmp(name
, interface1W
, sizeof(interface1W
)), "name = %s\n", wine_dbgstr_w(name
));
1091 ok(docstring
== NULL
, "docstring != NULL\n");
1092 ok(helpcontext
== 0, "helpcontext != 0\n");
1093 ok(!memcmp(helpfile
, helpfileW
, sizeof(helpfileW
)), "helpfile = %s\n", wine_dbgstr_w(helpfile
));
1095 SysFreeString(name
);
1096 SysFreeString(helpfile
);
1098 hres
= ITypeInfo_GetDocumentation(interface1
, 0, &name
, NULL
, NULL
, NULL
);
1099 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1101 hres
= ITypeInfo_GetRefTypeInfo(interface1
, 0, NULL
);
1102 ok(hres
== E_INVALIDARG
, "got %08x\n", hres
);
1105 hres
= ICreateTypeInfo_LayOut(createti
);
1106 ok(hres
== S_OK
, "got %08x\n", hres
);
1108 hres
= ICreateTypeInfo_AddRefTypeInfo(createti
, NULL
, &hreftype
);
1109 ok(hres
== E_INVALIDARG
, "got %08x\n", hres
);
1111 hres
= ICreateTypeInfo_AddRefTypeInfo(createti
, unknown
, NULL
);
1112 ok(hres
== E_INVALIDARG
, "got %08x\n", hres
);
1114 hres
= ICreateTypeInfo_AddRefTypeInfo(createti
, unknown
, &hreftype
);
1115 ok(hres
== S_OK
, "got %08x\n", hres
);
1117 skip("Skipping some tests\n");
1121 hres
= ICreateTypeInfo_AddImplType(createti
, 1, hreftype
);
1122 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1124 hres
= ICreateTypeInfo_AddImplType(createti
, 0, hreftype
);
1125 ok(hres
== S_OK
, "got %08x\n", hres
);
1127 hres
= ITypeInfo_GetRefTypeOfImplType(interface1
, 0, &hreftype
);
1128 ok(hres
== S_OK
, "got %08x\n", hres
);
1129 ok(hreftype
== 3, "hreftype = %d\n", hreftype
);
1131 hres
= ITypeInfo_GetRefTypeOfImplType(interface1
, -1, &hreftype
);
1132 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1134 memset(&funcdesc
, 0, sizeof(FUNCDESC
));
1135 funcdesc
.funckind
= FUNC_PUREVIRTUAL
;
1136 funcdesc
.invkind
= INVOKE_PROPERTYGET
;
1137 funcdesc
.callconv
= CC_STDCALL
;
1138 funcdesc
.elemdescFunc
.tdesc
.vt
= VT_BSTR
;
1139 U(funcdesc
.elemdescFunc
).idldesc
.wIDLFlags
= IDLFLAG_NONE
;
1141 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 0, NULL
);
1142 ok(hres
== E_INVALIDARG
, "got %08x\n", hres
);
1144 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 1, &funcdesc
);
1145 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1147 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 0, &funcdesc
);
1148 ok(hres
== S_OK
, "got %08x\n", hres
);
1150 hres
= ICreateTypeInfo_SetFuncHelpContext(createti
, 0, 0xabcdefab);
1151 ok(hres
== S_OK
, "got %08x\n", hres
);
1153 funcdesc
.invkind
= INVOKE_PROPERTYPUT
;
1154 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 1, &funcdesc
);
1155 ok(hres
== TYPE_E_INCONSISTENTPROPFUNCS
, "got %08x\n", hres
);
1157 funcdesc
.invkind
= INVOKE_PROPERTYPUTREF
;
1158 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 1, &funcdesc
);
1159 ok(hres
== TYPE_E_INCONSISTENTPROPFUNCS
, "got %08x\n", hres
);
1161 elemdesc
[0].tdesc
.vt
= VT_BSTR
;
1162 U(elemdesc
[0]).idldesc
.dwReserved
= 0;
1163 U(elemdesc
[0]).idldesc
.wIDLFlags
= IDLFLAG_FIN
;
1165 funcdesc
.lprgelemdescParam
= elemdesc
;
1166 funcdesc
.invkind
= INVOKE_PROPERTYPUT
;
1167 funcdesc
.cParams
= 1;
1168 funcdesc
.elemdescFunc
.tdesc
.vt
= VT_VOID
;
1170 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 1, &funcdesc
);
1171 ok(hres
== S_OK
, "got %08x\n", hres
);
1173 hres
= ICreateTypeInfo_SetFuncHelpContext(createti
, 1, 0xabcdefab);
1174 ok(hres
== S_OK
, "got %08x\n", hres
);
1176 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 0, propname
, 1);
1177 ok(hres
== S_OK
, "got %08x\n", hres
);
1179 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 1, propname
, 1);
1180 ok(hres
== S_OK
, "got %08x\n", hres
);
1182 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 1, propname
, 2);
1183 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1186 funcdesc
.invkind
= INVOKE_PROPERTYPUTREF
;
1187 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 0, &funcdesc
);
1188 ok(hres
== S_OK
, "got %08x\n", hres
);
1190 hres
= ICreateTypeInfo_SetFuncHelpContext(createti
, 0, 0xabcdefab);
1191 ok(hres
== S_OK
, "got %08x\n", hres
);
1193 hres
= ICreateTypeInfo_SetFuncHelpContext(createti
, 0, 0x201);
1194 ok(hres
== S_OK
, "got %08x\n", hres
);
1197 funcdesc
.lprgelemdescParam
= NULL
;
1198 funcdesc
.invkind
= INVOKE_FUNC
;
1199 funcdesc
.cParams
= 0;
1200 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 1, &funcdesc
);
1201 ok(hres
== S_OK
, "got %08x\n", hres
);
1203 funcdesc
.memid
= MEMBERID_NIL
;
1204 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 1, &funcdesc
);
1205 ok(hres
== S_OK
, "got %08x\n", hres
);
1207 elemdesc
[0].tdesc
.vt
= VT_PTR
;
1208 U(elemdesc
[0].tdesc
).lptdesc
= &typedesc1
;
1209 typedesc1
.vt
= VT_BSTR
;
1210 funcdesc
.cParams
= 1;
1211 funcdesc
.lprgelemdescParam
= elemdesc
;
1212 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 4, &funcdesc
);
1213 ok(hres
== S_OK
, "got %08x\n", hres
);
1215 U(elemdesc
[0].tdesc
).lptdesc
= &typedesc2
;
1216 typedesc2
.vt
= VT_PTR
;
1217 U(typedesc2
).lptdesc
= &typedesc1
;
1218 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 4, &funcdesc
);
1219 ok(hres
== S_OK
, "got %08x\n", hres
);
1221 elemdesc
[0].tdesc
.vt
= VT_INT
;
1222 U(elemdesc
[0]).paramdesc
.wParamFlags
= PARAMFLAG_FHASDEFAULT
;
1223 U(elemdesc
[0]).paramdesc
.pparamdescex
= ¶mdescex
;
1224 V_VT(¶mdescex
.varDefaultValue
) = VT_INT
;
1225 V_INT(¶mdescex
.varDefaultValue
) = 0x123;
1226 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 3, &funcdesc
);
1227 ok(hres
== S_OK
, "got %08x\n", hres
);
1229 U(elemdesc
[0]).idldesc
.dwReserved
= 0;
1230 U(elemdesc
[0]).idldesc
.wIDLFlags
= IDLFLAG_FIN
;
1231 elemdesc
[1].tdesc
.vt
= VT_UI2
;
1232 U(elemdesc
[1]).paramdesc
.wParamFlags
= PARAMFLAG_FHASDEFAULT
;
1233 U(elemdesc
[1]).paramdesc
.pparamdescex
= ¶mdescex
;
1234 V_VT(¶mdescex
.varDefaultValue
) = VT_UI2
;
1235 V_UI2(¶mdescex
.varDefaultValue
) = 0xffff;
1236 funcdesc
.cParams
= 2;
1237 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 3, &funcdesc
);
1238 ok(hres
== S_OK
, "got %08x\n", hres
);
1240 U(elemdesc
[0]).paramdesc
.wParamFlags
= PARAMFLAG_FHASDEFAULT
;
1241 U(elemdesc
[0]).paramdesc
.pparamdescex
= ¶mdescex
;
1242 elemdesc
[1].tdesc
.vt
= VT_INT
;
1243 V_VT(¶mdescex
.varDefaultValue
) = VT_INT
;
1244 V_INT(¶mdescex
.varDefaultValue
) = 0xffffffff;
1245 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 3, &funcdesc
);
1246 ok(hres
== S_OK
, "got %08x\n", hres
);
1248 elemdesc
[0].tdesc
.vt
= VT_BSTR
;
1249 elemdesc
[1].tdesc
.vt
= VT_BSTR
;
1250 V_VT(¶mdescex
.varDefaultValue
) = VT_BSTR
;
1251 V_BSTR(¶mdescex
.varDefaultValue
) = SysAllocString(defaultW
);
1252 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 3, &funcdesc
);
1253 ok(hres
== S_OK
, "got %08x\n", hres
);
1255 hres
= ITypeInfo_GetDocumentation(interface1
, 0, &name
, &docstring
, &helpcontext
, &helpfile
);
1256 ok(hres
== S_OK
, "got %08x\n", hres
);
1257 ok(name
== NULL
, "name != NULL\n");
1258 ok(docstring
== NULL
, "docstring != NULL\n");
1259 ok(helpcontext
== 0x201, "helpcontext != 0x201\n");
1260 ok(!memcmp(helpfile
, helpfileW
, sizeof(helpfileW
)), "helpfile = %s\n", wine_dbgstr_w(helpfile
));
1262 SysFreeString(helpfile
);
1264 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 1000, NULL
, 1);
1265 ok(hres
== E_INVALIDARG
, "got %08x\n", hres
);
1267 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 1000, names1
, 1);
1268 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1270 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 0, names1
, 2);
1271 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1273 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 0, names2
, 1);
1274 ok(hres
== S_OK
, "got %08x\n", hres
);
1276 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 0, names1
, 1);
1277 ok(hres
== S_OK
, "got %08x\n", hres
);
1279 hres
= ITypeInfo_GetDocumentation(interface1
, 0, &name
, NULL
, NULL
, NULL
);
1280 ok(hres
== S_OK
, "got %08x\n", hres
);
1281 ok(!memcmp(name
, func1W
, sizeof(func1W
)), "name = %s\n", wine_dbgstr_w(name
));
1283 SysFreeString(name
);
1285 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 3, names2
, 3);
1286 ok(hres
== S_OK
, "got %08x\n", hres
);
1288 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 3, names1
, 3);
1289 ok(hres
== TYPE_E_AMBIGUOUSNAME
, "got %08x\n", hres
);
1291 ICreateTypeInfo_Release(createti
);
1293 hres
= ICreateTypeLib_CreateTypeInfo(createtl
, interface1W
, TKIND_INTERFACE
, &createti
);
1294 ok(hres
== TYPE_E_NAMECONFLICT
, "got %08x\n", hres
);
1296 hres
= ICreateTypeLib_CreateTypeInfo(createtl
, interface2W
, TKIND_INTERFACE
, &createti
);
1297 ok(hres
== S_OK
, "got %08x\n", hres
);
1299 hres
= ICreateTypeInfo_QueryInterface(createti
, &IID_ITypeInfo
, (void**)&interface2
);
1300 ok(hres
== S_OK
, "got %08x\n", hres
);
1302 hres
= ITypeInfo_GetRefTypeOfImplType(interface2
, 0, &hreftype
);
1303 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1305 hres
= ICreateTypeInfo_AddRefTypeInfo(createti
, interface1
, &hreftype
);
1306 ok(hres
== S_OK
, "got %08x\n", hres
);
1308 hres
= ITypeInfo_GetRefTypeInfo(interface2
, 0, &ti
);
1309 ok(hres
== S_OK
, "got %08x\n", hres
);
1310 ok(ti
== interface1
, "Received and added interfaces are different\n");
1312 ITypeInfo_Release(ti
);
1314 hres
= ICreateTypeInfo_AddImplType(createti
, 0, hreftype
);
1315 ok(hres
== S_OK
, "got %08x\n", hres
);
1317 hres
= ITypeInfo_GetRefTypeOfImplType(interface2
, 0, &hreftype
);
1318 ok(hres
== S_OK
, "got %08x\n", hres
);
1319 ok(hreftype
== 2, "hreftype = %d\n", hreftype
);
1321 hres
= ITypeInfo_GetRefTypeOfImplType(interface2
, -1, &hreftype
);
1322 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1324 hres
= ICreateTypeInfo_SetImplTypeFlags(createti
, 0, IMPLTYPEFLAG_FDEFAULT
);
1325 ok(hres
== TYPE_E_BADMODULEKIND
, "got %08x\n", hres
);
1327 hres
= ITypeInfo_GetImplTypeFlags(interface2
, 0, &impltypeflags
);
1328 ok(hres
== S_OK
, "got %08x\n", hres
);
1329 ok(impltypeflags
== 0, "impltypeflags = %x\n", impltypeflags
);
1331 hres
= ITypeInfo_GetImplTypeFlags(interface2
, 1, &impltypeflags
);
1332 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1334 funcdesc
.oVft
= 0xaaac;
1335 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 0, &funcdesc
);
1336 ok(hres
== S_OK
, "got %08x\n", hres
);
1337 funcdesc
.oVft
= 0xaaa8;
1338 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 0, &funcdesc
);
1339 ok(hres
== S_OK
, "got %08x\n", hres
);
1342 ICreateTypeInfo_Release(createti
);
1344 VariantInit(&cust_data
);
1346 hres
= ICreateTypeLib_CreateTypeInfo(createtl
, interface3W
, TKIND_INTERFACE
, &createti
);
1347 ok(hres
== S_OK
, "got %08x\n", hres
);
1349 hres
= ICreateTypeInfo_QueryInterface(createti
, &IID_ICreateTypeInfo2
, (void**)&createti2
);
1350 ok(hres
== S_OK
, "got %08x\n", hres
);
1352 hres
= ICreateTypeInfo2_QueryInterface(createti2
, &IID_ITypeInfo2
, (void**)&ti2
);
1353 ok(hres
== S_OK
, "got %08x\n", hres
);
1355 hres
= ITypeInfo2_GetCustData(ti2
, NULL
, NULL
);
1357 ok(hres
== E_INVALIDARG
, "got %08x\n", hres
);
1359 hres
= ITypeInfo2_GetCustData(ti2
, &custguid
, NULL
);
1361 ok(hres
== E_INVALIDARG
, "got %08x\n", hres
);
1363 hres
= ITypeInfo2_GetCustData(ti2
, &custguid
, &cust_data
);
1365 ok(hres
== S_OK
, "got %08x\n", hres
);
1367 hres
= ICreateTypeInfo2_SetCustData(createti2
, NULL
, NULL
);
1368 ok(hres
== E_INVALIDARG
, "got %08x\n", hres
);
1370 hres
= ICreateTypeInfo2_SetCustData(createti2
, &custguid
, NULL
);
1371 ok(hres
== E_INVALIDARG
, "got %08x\n", hres
);
1373 hres
= ICreateTypeInfo2_SetCustData(createti2
, &custguid
, &cust_data
);
1374 ok(hres
== DISP_E_BADVARTYPE
, "got %08x\n", hres
);
1376 V_VT(&cust_data
) = VT_UI4
;
1377 V_I4(&cust_data
) = 0xdeadbeef;
1379 hres
= ICreateTypeInfo2_SetCustData(createti2
, &custguid
, &cust_data
);
1380 ok(hres
== S_OK
, "got %08x\n", hres
);
1382 V_I4(&cust_data
) = 0;
1383 V_VT(&cust_data
) = VT_EMPTY
;
1385 hres
= ITypeInfo2_GetCustData(ti2
, &custguid
, &cust_data
);
1387 ok(hres
== S_OK
, "got %08x\n", hres
);
1390 ok(V_VT(&cust_data
) == VT_UI4
, "got %d\n", V_VT(&cust_data
));
1392 ok(V_I4(&cust_data
) == 0xdeadbeef, "got 0x%08x\n", V_I4(&cust_data
));
1394 V_VT(&cust_data
) = VT_UI4
;
1395 V_I4(&cust_data
) = 12345678;
1397 hres
= ICreateTypeInfo2_SetCustData(createti2
, &custguid
, &cust_data
);
1398 ok(hres
== S_OK
, "got %08x\n", hres
);
1400 V_I4(&cust_data
) = 0;
1401 V_VT(&cust_data
) = VT_EMPTY
;
1403 hres
= ITypeInfo2_GetCustData(ti2
, &custguid
, &cust_data
);
1405 ok(hres
== S_OK
, "got %08x\n", hres
);
1408 ok(V_VT(&cust_data
) == VT_UI4
, "got %d\n", V_VT(&cust_data
));
1410 ok(V_I4(&cust_data
) == 12345678, "got 0x%08x\n", V_I4(&cust_data
));
1412 ITypeInfo2_Release(ti2
);
1413 ICreateTypeInfo2_Release(createti2
);
1414 ICreateTypeInfo_Release(createti
);
1416 hres
= ICreateTypeLib_CreateTypeInfo(createtl
, coclassW
, TKIND_COCLASS
, &createti
);
1417 ok(hres
== S_OK
, "got %08x\n", hres
);
1419 hres
= ICreateTypeInfo_AddRefTypeInfo(createti
, interface1
, &hreftype
);
1420 ok(hres
== S_OK
, "got %08x\n", hres
);
1422 hres
= ICreateTypeInfo_AddImplType(createti
, 0, hreftype
);
1423 ok(hres
== S_OK
, "got %08x\n", hres
);
1425 hres
= ICreateTypeInfo_AddImplType(createti
, 0, hreftype
);
1426 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1428 hres
= ICreateTypeInfo_AddRefTypeInfo(createti
, unknown
, &hreftype
);
1429 ok(hres
== S_OK
, "got %08x\n", hres
);
1431 hres
= ICreateTypeInfo_AddImplType(createti
, 1, hreftype
);
1432 ok(hres
== S_OK
, "got %08x\n", hres
);
1434 hres
= ICreateTypeInfo_AddImplType(createti
, 1, hreftype
);
1435 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1437 hres
= ICreateTypeInfo_AddImplType(createti
, 2, hreftype
);
1438 ok(hres
== S_OK
, "got %08x\n", hres
);
1440 hres
= ICreateTypeInfo_SetImplTypeFlags(createti
, 0, IMPLTYPEFLAG_FDEFAULT
);
1441 ok(hres
== S_OK
, "got %08x\n", hres
);
1443 hres
= ICreateTypeInfo_SetImplTypeFlags(createti
, 1, IMPLTYPEFLAG_FRESTRICTED
);
1444 ok(hres
== S_OK
, "got %08x\n", hres
);
1446 hres
= ICreateTypeInfo_QueryInterface(createti
, &IID_ITypeInfo
, (void**)&ti
);
1447 ok(hres
== S_OK
, "got %08x\n", hres
);
1449 hres
= ITypeInfo_GetImplTypeFlags(ti
, 0, NULL
);
1450 ok(hres
== E_INVALIDARG
, "got %08x\n", hres
);
1452 hres
= ITypeInfo_GetImplTypeFlags(ti
, 0, &impltypeflags
);
1453 ok(hres
== S_OK
, "got %08x\n", hres
);
1454 ok(impltypeflags
== IMPLTYPEFLAG_FDEFAULT
, "impltypeflags = %x\n", impltypeflags
);
1456 hres
= ITypeInfo_GetImplTypeFlags(ti
, 1, &impltypeflags
);
1457 ok(hres
== S_OK
, "got %08x\n", hres
);
1458 ok(impltypeflags
== IMPLTYPEFLAG_FRESTRICTED
, "impltypeflags = %x\n", impltypeflags
);
1460 hres
= ITypeInfo_GetImplTypeFlags(ti
, 2, &impltypeflags
);
1461 ok(hres
== S_OK
, "got %08x\n", hres
);
1462 ok(impltypeflags
== 0, "impltypeflags = %x\n", impltypeflags
);
1464 hres
= ITypeInfo_GetRefTypeOfImplType(ti
, 0, &hreftype
);
1465 ok(hres
== S_OK
, "got %08x\n", hres
);
1466 ok(hreftype
== 0, "hreftype = %d\n", hreftype
);
1468 hres
= ITypeInfo_GetRefTypeOfImplType(ti
, 1, &hreftype
);
1469 ok(hres
== S_OK
, "got %08x\n", hres
);
1470 ok(hreftype
== 1, "hreftype = %d\n", hreftype
);
1472 hres
= ITypeInfo_GetRefTypeOfImplType(ti
, 2, &hreftype
);
1473 ok(hres
== S_OK
, "got %08x\n", hres
);
1474 ok(hreftype
== 1, "hreftype = %d\n", hreftype
);
1476 hres
= ITypeInfo_GetRefTypeOfImplType(ti
, -1, &hreftype
);
1477 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1479 ITypeInfo_Release(ti
);
1481 ICreateTypeInfo_Release(createti
);
1483 hres
= ICreateTypeLib_CreateTypeInfo(createtl
, dualW
, TKIND_INTERFACE
, &createti
);
1484 ok(hres
== S_OK
, "got %08x\n", hres
);
1486 hres
= ICreateTypeInfo_SetTypeFlags(createti
, TYPEFLAG_FDUAL
);
1487 ok(hres
== S_OK
, "got %08x\n", hres
);
1489 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 0, &funcdesc
);
1490 ok(hres
== S_OK
, "got %08x\n", hres
);
1492 hres
= ICreateTypeInfo_AddRefTypeInfo(createti
, dispatch
, &hreftype
);
1493 ok(hres
== S_OK
, "got %08x\n", hres
);
1495 hres
= ICreateTypeInfo_AddImplType(createti
, 0, hreftype
);
1496 ok(hres
== S_OK
, "got %08x\n", hres
);
1498 hres
= ICreateTypeInfo_QueryInterface(createti
, &IID_ITypeInfo
, (void**)&dual
);
1499 ok(hres
== S_OK
, "got %08x\n", hres
);
1501 hres
= ITypeInfo_GetTypeAttr(dual
, &typeattr
);
1502 ok(hres
== S_OK
, "got %08x\n", hres
);
1503 ok(typeattr
->cbSizeInstance
== 4, "cbSizeInstance = %d\n", typeattr
->cbSizeInstance
);
1504 ok(typeattr
->typekind
== 3, "typekind = %d\n", typeattr
->typekind
);
1505 ok(typeattr
->cFuncs
== 1, "cFuncs = %d\n", typeattr
->cFuncs
);
1506 ok(typeattr
->cVars
== 0, "cVars = %d\n", typeattr
->cVars
);
1507 ok(typeattr
->cImplTypes
== 1, "cImplTypes = %d\n", typeattr
->cImplTypes
);
1508 ok(typeattr
->cbSizeVft
== 32 || broken(typeattr
->cbSizeVft
== 7 * sizeof(void *) + 4), /* xp64 */
1509 "cbSizeVft = %d\n", typeattr
->cbSizeVft
);
1510 ok(typeattr
->cbAlignment
== 4, "cbAlignment = %d\n", typeattr
->cbAlignment
);
1511 ok(typeattr
->wTypeFlags
== (TYPEFLAG_FDISPATCHABLE
|TYPEFLAG_FDUAL
), "wTypeFlags = %d\n", typeattr
->wTypeFlags
);
1512 ok(typeattr
->wMajorVerNum
== 0, "wMajorVerNum = %d\n", typeattr
->wMajorVerNum
);
1513 ok(typeattr
->wMinorVerNum
== 0, "wMinorVerNum = %d\n", typeattr
->wMinorVerNum
);
1515 ITypeInfo_ReleaseTypeAttr(dual
, typeattr
);
1517 hres
= ITypeInfo_GetRefTypeOfImplType(dual
, -1, &hreftype
);
1518 ok(hres
== S_OK
, "got %08x\n", hres
);
1519 ok(hreftype
== -2, "got %08x\n", hreftype
);
1521 hres
= ITypeInfo_GetRefTypeInfo(dual
, -2, &ti
);
1522 ok(hres
== S_OK
, "got %08x\n", hres
);
1524 hres
= ITypeInfo_GetTypeAttr(ti
, &typeattr
);
1525 ok(hres
== S_OK
, "got %08x\n", hres
);
1526 ok(typeattr
->cbSizeInstance
== 4, "cbSizeInstance = %d\n", typeattr
->cbSizeInstance
);
1527 ok(typeattr
->typekind
== 4, "typekind = %d\n", typeattr
->typekind
);
1528 ok(typeattr
->cFuncs
== 8, "cFuncs = %d\n", typeattr
->cFuncs
);
1529 ok(typeattr
->cVars
== 0, "cVars = %d\n", typeattr
->cVars
);
1530 ok(typeattr
->cImplTypes
== 1, "cImplTypes = %d\n", typeattr
->cImplTypes
);
1531 ok(typeattr
->cbSizeVft
== 7 * sizeof(void *), "cbSizeVft = %d\n", typeattr
->cbSizeVft
);
1532 ok(typeattr
->cbAlignment
== 4, "cbAlignment = %d\n", typeattr
->cbAlignment
);
1533 ok(typeattr
->wTypeFlags
== (TYPEFLAG_FDISPATCHABLE
|TYPEFLAG_FDUAL
), "wTypeFlags = %d\n", typeattr
->wTypeFlags
);
1534 ok(typeattr
->wMajorVerNum
== 0, "wMajorVerNum = %d\n", typeattr
->wMajorVerNum
);
1535 ok(typeattr
->wMinorVerNum
== 0, "wMinorVerNum = %d\n", typeattr
->wMinorVerNum
);
1537 ITypeInfo_ReleaseTypeAttr(ti
, typeattr
);
1539 ITypeInfo_Release(ti
);
1541 ICreateTypeInfo_Release(createti
);
1543 hres
= ITypeInfo_GetTypeAttr(interface1
, &typeattr
);
1544 ok(hres
== S_OK
, "got %08x\n", hres
);
1545 ok(typeattr
->cbSizeInstance
== 4, "cbSizeInstance = %d\n", typeattr
->cbSizeInstance
);
1546 ok(typeattr
->typekind
== 3, "typekind = %d\n", typeattr
->typekind
);
1547 ok(typeattr
->cFuncs
== 11, "cFuncs = %d\n", typeattr
->cFuncs
);
1548 ok(typeattr
->cVars
== 0, "cVars = %d\n", typeattr
->cVars
);
1549 ok(typeattr
->cImplTypes
== 1, "cImplTypes = %d\n", typeattr
->cImplTypes
);
1550 ok(typeattr
->cbSizeVft
== 56 || broken(typeattr
->cbSizeVft
== 3 * sizeof(void *) + 44), /* xp64 */
1551 "cbSizeVft = %d\n", typeattr
->cbSizeVft
);
1552 ok(typeattr
->cbAlignment
== 4, "cbAlignment = %d\n", typeattr
->cbAlignment
);
1553 ok(typeattr
->wTypeFlags
== 0, "wTypeFlags = %d\n", typeattr
->wTypeFlags
);
1554 ok(typeattr
->wMajorVerNum
== 0, "wMajorVerNum = %d\n", typeattr
->wMajorVerNum
);
1555 ok(typeattr
->wMinorVerNum
== 0, "wMinorVerNum = %d\n", typeattr
->wMinorVerNum
);
1557 ITypeInfo_ReleaseTypeAttr(interface1
, typeattr
);
1559 hres
= ITypeInfo_GetTypeAttr(interface2
, &typeattr
);
1560 ok(hres
== S_OK
, "got %08x\n", hres
);
1561 ok(typeattr
->cbSizeInstance
== 4, "cbSizeInstance = %d\n", typeattr
->cbSizeInstance
);
1562 ok(typeattr
->typekind
== 3, "typekind = %d\n", typeattr
->typekind
);
1563 ok(typeattr
->cFuncs
== 2, "cFuncs = %d\n", typeattr
->cFuncs
);
1564 ok(typeattr
->cVars
== 0, "cVars = %d\n", typeattr
->cVars
);
1565 ok(typeattr
->cImplTypes
== 1, "cImplTypes = %d\n", typeattr
->cImplTypes
);
1566 ok(typeattr
->cbSizeVft
== 43696, "cbSizeVft = %d\n", typeattr
->cbSizeVft
);
1567 ok(typeattr
->cbAlignment
== 4, "cbAlignment = %d\n", typeattr
->cbAlignment
);
1568 ok(typeattr
->wTypeFlags
== 0, "wTypeFlags = %d\n", typeattr
->wTypeFlags
);
1569 ok(typeattr
->wMajorVerNum
== 0, "wMajorVerNum = %d\n", typeattr
->wMajorVerNum
);
1570 ok(typeattr
->wMinorVerNum
== 0, "wMinorVerNum = %d\n", typeattr
->wMinorVerNum
);
1572 ITypeInfo_ReleaseTypeAttr(interface2
, typeattr
);
1574 hres
= ICreateTypeLib2_SaveAllChanges(createtl
);
1575 ok(hres
== S_OK
, "got %08x\n", hres
);
1577 ok(ITypeInfo_Release(interface2
)==0, "Object should be freed\n");
1578 ok(ITypeInfo_Release(interface1
)==0, "Object should be freed\n");
1579 ok(ITypeInfo_Release(dual
)==0, "Object should be freed\n");
1580 ok(ICreateTypeLib2_Release(createtl
)==0, "Object should be freed\n");
1582 ok(ITypeInfo_Release(dispatch
)==0, "Object should be freed\n");
1583 ok(ITypeInfo_Release(unknown
)==0, "Object should be freed\n");
1584 ok(ITypeLib_Release(stdole
)==0, "Object should be freed\n");
1586 hres
= LoadTypeLibEx(filenameW
, REGKIND_NONE
, &tl
);
1587 ok(hres
== S_OK
, "got %08x\n", hres
);
1588 ok(ITypeLib_Release(tl
)==0, "Object should be freed\n");
1590 DeleteFileA(filename
);
1593 #if 0 /* use this to generate more tests */
1595 #define OLE_CHECK(x) { HRESULT hr = x; if (FAILED(hr)) { printf(#x "failed - %x\n", hr); return; } }
1597 static char *dump_string(LPWSTR wstr
)
1599 int size
= lstrlenW(wstr
)+3;
1600 char *out
= CoTaskMemAlloc(size
);
1601 WideCharToMultiByte(20127, 0, wstr
, -1, out
+1, size
, NULL
, NULL
);
1613 #define MAP_ENTRY(x) { x, #x }
1614 static const struct map_entry tkind_map
[] = {
1615 MAP_ENTRY(TKIND_ENUM
),
1616 MAP_ENTRY(TKIND_RECORD
),
1617 MAP_ENTRY(TKIND_MODULE
),
1618 MAP_ENTRY(TKIND_INTERFACE
),
1619 MAP_ENTRY(TKIND_DISPATCH
),
1620 MAP_ENTRY(TKIND_COCLASS
),
1621 MAP_ENTRY(TKIND_ALIAS
),
1622 MAP_ENTRY(TKIND_UNION
),
1623 MAP_ENTRY(TKIND_MAX
),
1627 static const struct map_entry funckind_map
[] = {
1628 MAP_ENTRY(FUNC_VIRTUAL
),
1629 MAP_ENTRY(FUNC_PUREVIRTUAL
),
1630 MAP_ENTRY(FUNC_NONVIRTUAL
),
1631 MAP_ENTRY(FUNC_STATIC
),
1632 MAP_ENTRY(FUNC_DISPATCH
),
1636 static const struct map_entry invkind_map
[] = {
1637 MAP_ENTRY(INVOKE_FUNC
),
1638 MAP_ENTRY(INVOKE_PROPERTYGET
),
1639 MAP_ENTRY(INVOKE_PROPERTYPUT
),
1640 MAP_ENTRY(INVOKE_PROPERTYPUTREF
),
1646 static const char *map_value(DWORD val
, const struct map_entry
*map
)
1649 static char bufs
[16][256];
1654 if (map
->value
== val
)
1659 buf
= bufs
[(map_id
++)%16];
1660 sprintf(buf
, "0x%x", val
);
1664 static void test_dump_typelib(const char *name
)
1666 WCHAR wszString
[260];
1672 MultiByteToWideChar(CP_ACP
, 0, name
, -1, wszString
, 260);
1673 OLE_CHECK(LoadTypeLib(wszString
, &lib
));
1674 count
= ITypeLib_GetTypeInfoCount(lib
);
1675 printf("/* interfaces count: %d */\n", count
);
1676 for (i
= 0; i
< count
; i
++)
1682 OLE_CHECK(ITypeLib_GetDocumentation(lib
, i
, &name
, NULL
, NULL
, NULL
));
1684 " %s,\n", dump_string(name
));
1685 SysFreeString(name
);
1687 OLE_CHECK(ITypeLib_GetTypeInfo(lib
, i
, &info
));
1688 ITypeInfo_GetTypeAttr(info
, &attr
);
1689 printf(" /*kind*/ %s, /*flags*/ 0x%x, /*align*/ %d, /*size*/ %d,\n"
1690 " /*#vtbl*/ %d, /*#func*/ %d,\n"
1692 map_value(attr
->typekind
, tkind_map
), attr
->wTypeFlags
, attr
->cbAlignment
, attr
->cbSizeInstance
, attr
->cbSizeVft
,
1694 ITypeInfo_ReleaseTypeAttr(info
, attr
);
1702 if (FAILED(ITypeInfo_GetFuncDesc(info
, f
, &desc
)))
1705 " 0x%x, /*func*/ %s, /*inv*/ %s, /*call*/ 0x%x,\n",
1706 desc
->memid
, map_value(desc
->funckind
, funckind_map
), map_value(desc
->invkind
, invkind_map
),
1708 printf(" /*#param*/ %d, /*#opt*/ %d, /*vtbl*/ %d, /*#scodes*/ %d, /*flags*/ 0x%x,\n",
1709 desc
->cParams
, desc
->cParamsOpt
, desc
->oVft
, desc
->cScodes
, desc
->wFuncFlags
);
1710 printf(" {%d, %x}, /* ret */\n", desc
->elemdescFunc
.tdesc
.vt
, desc
->elemdescFunc
.paramdesc
.wParamFlags
);
1711 printf(" { /* params */\n");
1712 for (p
= 0; p
< desc
->cParams
; p
++)
1714 ELEMDESC e
= desc
->lprgelemdescParam
[p
];
1715 printf(" {%d, %x},\n", e
.tdesc
.vt
, e
.paramdesc
.wParamFlags
);
1717 printf(" {-1, -1}\n");
1719 printf(" { /* names */\n");
1720 OLE_CHECK(ITypeInfo_GetNames(info
, desc
->memid
, tab
, 256, &cNames
));
1721 for (p
= 0; p
< cNames
; p
++)
1723 printf(" %s,\n", dump_string(tab
[p
]));
1724 SysFreeString(tab
[p
]);
1729 ITypeInfo_ReleaseFuncDesc(info
, desc
);
1734 ITypeInfo_Release(info
);
1736 ITypeLib_Release(lib
);
1741 typedef struct _element_info
1747 typedef struct _function_info
1758 element_info ret_type
;
1759 element_info params
[15];
1763 typedef struct _interface_info
1769 USHORT cbSizeInstance
;
1772 function_info funcs
[20];
1775 static const interface_info info
[] = {
1776 /* interfaces count: 2 */
1779 /*kind*/ TKIND_DISPATCH
, /*flags*/ 0x1040, /*align*/ 4, /*size*/ 4,
1780 /*#vtbl*/ 7, /*#func*/ 8,
1783 0x60000000, /*func*/ FUNC_DISPATCH
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1784 /*#param*/ 2, /*#opt*/ 0, /*vtbl*/ 0, /*#scodes*/ 0, /*flags*/ 0x1,
1799 0x60000001, /*func*/ FUNC_DISPATCH
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1800 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 1, /*#scodes*/ 0, /*flags*/ 0x1,
1811 0x60000002, /*func*/ FUNC_DISPATCH
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1812 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 2, /*#scodes*/ 0, /*flags*/ 0x1,
1823 0x60010000, /*func*/ FUNC_DISPATCH
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1824 /*#param*/ 1, /*#opt*/ 0, /*vtbl*/ 3, /*#scodes*/ 0, /*flags*/ 0x1,
1837 0x60010001, /*func*/ FUNC_DISPATCH
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1838 /*#param*/ 3, /*#opt*/ 0, /*vtbl*/ 4, /*#scodes*/ 0, /*flags*/ 0x1,
1855 0x60010002, /*func*/ FUNC_DISPATCH
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1856 /*#param*/ 5, /*#opt*/ 0, /*vtbl*/ 5, /*#scodes*/ 0, /*flags*/ 0x1,
1877 0x60010003, /*func*/ FUNC_DISPATCH
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1878 /*#param*/ 8, /*#opt*/ 0, /*vtbl*/ 6, /*#scodes*/ 0, /*flags*/ 0x1,
1905 0x60020000, /*func*/ FUNC_DISPATCH
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1906 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 7, /*#scodes*/ 0, /*flags*/ 0x0,
1920 /*kind*/ TKIND_INTERFACE
, /*flags*/ 0x1000, /*align*/ 4, /*size*/ 4,
1921 /*#vtbl*/ 8, /*#func*/ 1,
1924 0x60020000, /*func*/ FUNC_PUREVIRTUAL
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1925 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 7, /*#scodes*/ 0, /*flags*/ 0x0,
1939 #define check_type(elem, info) { \
1940 expect_int((elem)->tdesc.vt, (info)->vt); \
1941 expect_hex(U(*(elem)).paramdesc.wParamFlags, (info)->wParamFlags); \
1944 static void test_dump_typelib(const char *name
)
1946 WCHAR wszName
[MAX_PATH
];
1948 int ifcount
= sizeof(info
)/sizeof(info
[0]);
1951 MultiByteToWideChar(CP_ACP
, 0, name
, -1, wszName
, MAX_PATH
);
1952 ole_check(LoadTypeLibEx(wszName
, REGKIND_NONE
, &typelib
));
1953 expect_eq(ITypeLib_GetTypeInfoCount(typelib
), ifcount
, UINT
, "%d");
1954 for (iface
= 0; iface
< ifcount
; iface
++)
1956 const interface_info
*if_info
= &info
[iface
];
1957 ITypeInfo
*typeinfo
;
1961 trace("Interface %s\n", if_info
->name
);
1962 ole_check(ITypeLib_GetTypeInfo(typelib
, iface
, &typeinfo
));
1963 ole_check(ITypeLib_GetDocumentation(typelib
, iface
, &bstrIfName
, NULL
, NULL
, NULL
));
1964 expect_wstr_acpval(bstrIfName
, if_info
->name
);
1965 SysFreeString(bstrIfName
);
1967 ole_check(ITypeInfo_GetTypeAttr(typeinfo
, &typeattr
));
1968 expect_int(typeattr
->typekind
, if_info
->type
);
1969 expect_hex(typeattr
->wTypeFlags
, if_info
->wTypeFlags
);
1970 expect_int(typeattr
->cbAlignment
, if_info
->cbAlignment
);
1971 expect_int(typeattr
->cbSizeInstance
, if_info
->cbSizeInstance
);
1972 expect_int(typeattr
->cbSizeVft
, if_info
->cbSizeVft
* sizeof(void*));
1973 expect_int(typeattr
->cFuncs
, if_info
->cFuncs
);
1975 for (func
= 0; func
< typeattr
->cFuncs
; func
++)
1977 function_info
*fn_info
= (function_info
*)&if_info
->funcs
[func
];
1983 trace("Function %s\n", fn_info
->names
[0]);
1984 ole_check(ITypeInfo_GetFuncDesc(typeinfo
, func
, &desc
));
1985 expect_int(desc
->memid
, fn_info
->memid
);
1986 expect_int(desc
->funckind
, fn_info
->funckind
);
1987 expect_int(desc
->invkind
, fn_info
->invkind
);
1988 expect_int(desc
->callconv
, fn_info
->callconv
);
1989 expect_int(desc
->cParams
, fn_info
->cParams
);
1990 expect_int(desc
->cParamsOpt
, fn_info
->cParamsOpt
);
1991 ok( desc
->oVft
== fn_info
->vtbl_index
* sizeof(void*) ||
1992 broken(desc
->oVft
== fn_info
->vtbl_index
* 4), /* xp64 */
1993 "desc->oVft got %u\n", desc
->oVft
);
1994 expect_int(desc
->cScodes
, fn_info
->cScodes
);
1995 expect_int(desc
->wFuncFlags
, fn_info
->wFuncFlags
);
1996 ole_check(ITypeInfo_GetNames(typeinfo
, desc
->memid
, namesTab
, 256, &cNames
));
1997 for (i
= 0; i
< cNames
; i
++)
1999 expect_wstr_acpval(namesTab
[i
], fn_info
->names
[i
]);
2000 SysFreeString(namesTab
[i
]);
2002 expect_null(fn_info
->names
[cNames
]);
2004 check_type(&desc
->elemdescFunc
, &fn_info
->ret_type
);
2005 for (i
= 0 ; i
< desc
->cParams
; i
++)
2007 check_type(&desc
->lprgelemdescParam
[i
], &fn_info
->params
[i
]);
2009 expect_int(fn_info
->params
[desc
->cParams
].vt
, (VARTYPE
)-1);
2011 ITypeInfo_ReleaseFuncDesc(typeinfo
, desc
);
2014 ITypeInfo_ReleaseTypeAttr(typeinfo
, typeattr
);
2015 ITypeInfo_Release(typeinfo
);
2017 ITypeLib_Release(typelib
);
2022 static const char *create_test_typelib(int res_no
)
2024 static char filename
[MAX_PATH
];
2030 GetTempFileNameA( ".", "tlb", 0, filename
);
2031 file
= CreateFile( filename
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0 );
2032 ok( file
!= INVALID_HANDLE_VALUE
, "file creation failed\n" );
2033 if (file
== INVALID_HANDLE_VALUE
) return NULL
;
2034 res
= FindResource( GetModuleHandle(0), MAKEINTRESOURCE(res_no
), "TYPELIB" );
2035 ok( res
!= 0, "couldn't find resource\n" );
2036 ptr
= LockResource( LoadResource( GetModuleHandle(0), res
));
2037 WriteFile( file
, ptr
, SizeofResource( GetModuleHandle(0), res
), &written
, NULL
);
2038 ok( written
== SizeofResource( GetModuleHandle(0), res
), "couldn't write resource\n" );
2039 CloseHandle( file
);
2043 static void test_create_typelib_lcid(LCID lcid
)
2045 char filename
[MAX_PATH
];
2046 WCHAR name
[MAX_PATH
];
2048 ICreateTypeLib2
*tl
;
2050 DWORD msft_header
[5]; /* five is enough for now */
2053 GetTempFileNameA( ".", "tlb", 0, filename
);
2054 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, name
, MAX_PATH
);
2056 hr
= CreateTypeLib2(SYS_WIN32
, name
, &tl
);
2057 ok(hr
== S_OK
, "got %08x\n", hr
);
2059 hr
= ICreateTypeLib2_SetLcid(tl
, lcid
);
2060 ok(hr
== S_OK
, "got %08x\n", hr
);
2062 hr
= ICreateTypeLib2_SaveAllChanges(tl
);
2063 ICreateTypeLib2_Release(tl
);
2065 file
= CreateFileA( filename
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, 0 );
2066 ok( file
!= INVALID_HANDLE_VALUE
, "file creation failed\n" );
2068 ReadFile( file
, msft_header
, sizeof(msft_header
), &read
, NULL
);
2069 ok(read
== sizeof(msft_header
), "read %d\n", read
);
2070 CloseHandle( file
);
2072 ok(msft_header
[0] == 0x5446534d, "got %08x\n", msft_header
[0]);
2073 ok(msft_header
[1] == 0x00010002, "got %08x\n", msft_header
[1]);
2074 ok(msft_header
[2] == 0xffffffff, "got %08x\n", msft_header
[2]);
2075 ok(msft_header
[3] == (lcid
? lcid
: 0x409), "got %08x (lcid %08x)\n", msft_header
[3], lcid
);
2076 ok(msft_header
[4] == lcid
, "got %08x (lcid %08x)\n", msft_header
[4], lcid
);
2078 DeleteFileA(filename
);
2081 static void test_create_typelibs(void)
2083 test_create_typelib_lcid(LOCALE_SYSTEM_DEFAULT
);
2084 test_create_typelib_lcid(LOCALE_USER_DEFAULT
);
2085 test_create_typelib_lcid(LOCALE_NEUTRAL
);
2087 test_create_typelib_lcid(0x009);
2088 test_create_typelib_lcid(0x409);
2089 test_create_typelib_lcid(0x809);
2091 test_create_typelib_lcid(0x007);
2092 test_create_typelib_lcid(0x407);
2096 static void test_register_typelib(void)
2099 WCHAR filename
[MAX_PATH
];
2100 const char *filenameA
;
2103 char key_name
[MAX_PATH
], uuid
[40];
2104 LONG ret
, expect_ret
;
2113 { TKIND_INTERFACE
, 0 },
2114 { TKIND_INTERFACE
, TYPEFLAG_FDISPATCHABLE
},
2115 { TKIND_INTERFACE
, TYPEFLAG_FOLEAUTOMATION
},
2116 { TKIND_INTERFACE
, TYPEFLAG_FDISPATCHABLE
| TYPEFLAG_FOLEAUTOMATION
},
2117 { TKIND_DISPATCH
, 0 /* TYPEFLAG_FDUAL - widl clears this flag for non-IDispatch derived interfaces */ },
2118 { TKIND_DISPATCH
, 0 /* TYPEFLAG_FDUAL - widl clears this flag for non-IDispatch derived interfaces */ },
2119 { TKIND_DISPATCH
, TYPEFLAG_FDISPATCHABLE
| TYPEFLAG_FDUAL
},
2120 { TKIND_DISPATCH
, TYPEFLAG_FDISPATCHABLE
| TYPEFLAG_FDUAL
},
2121 { TKIND_DISPATCH
, TYPEFLAG_FDISPATCHABLE
},
2122 { TKIND_DISPATCH
, TYPEFLAG_FDISPATCHABLE
},
2123 { TKIND_DISPATCH
, TYPEFLAG_FDISPATCHABLE
}
2126 filenameA
= create_test_typelib(3);
2127 MultiByteToWideChar(CP_ACP
, 0, filenameA
, -1, filename
, MAX_PATH
);
2129 hr
= LoadTypeLibEx(filename
, REGKIND_NONE
, &typelib
);
2130 ok(SUCCEEDED(hr
), "got %08x\n", hr
);
2132 hr
= RegisterTypeLib(typelib
, filename
, NULL
);
2133 ok(SUCCEEDED(hr
), "got %08x\n", hr
);
2135 count
= ITypeLib_GetTypeInfoCount(typelib
);
2136 ok(count
== 11, "got %d\n", count
);
2138 for(i
= 0; i
< count
; i
++)
2140 ITypeInfo
*typeinfo
;
2143 hr
= ITypeLib_GetTypeInfo(typelib
, i
, &typeinfo
);
2144 ok(SUCCEEDED(hr
), "got %08x\n", hr
);
2146 hr
= ITypeInfo_GetTypeAttr(typeinfo
, &attr
);
2147 ok(SUCCEEDED(hr
), "got %08x\n", hr
);
2149 ok(attr
->typekind
== attrs
[i
].kind
, "%d: got kind %d\n", i
, attr
->typekind
);
2150 ok(attr
->wTypeFlags
== attrs
[i
].flags
, "%d: got flags %04x\n", i
, attr
->wTypeFlags
);
2152 if(attr
->typekind
== TKIND_DISPATCH
&& (attr
->wTypeFlags
& TYPEFLAG_FDUAL
))
2155 ITypeInfo
*dual_info
;
2156 TYPEATTR
*dual_attr
;
2158 hr
= ITypeInfo_GetRefTypeOfImplType(typeinfo
, -1, &reftype
);
2159 ok(SUCCEEDED(hr
), "got %08x\n", hr
);
2161 hr
= ITypeInfo_GetRefTypeInfo(typeinfo
, reftype
, &dual_info
);
2162 ok(SUCCEEDED(hr
), "got %08x\n", hr
);
2164 hr
= ITypeInfo_GetTypeAttr(dual_info
, &dual_attr
);
2165 ok(SUCCEEDED(hr
), "got %08x\n", hr
);
2167 ok(dual_attr
->typekind
== TKIND_INTERFACE
, "%d: got kind %d\n", i
, dual_attr
->typekind
);
2168 ok(dual_attr
->wTypeFlags
== (TYPEFLAG_FDISPATCHABLE
| TYPEFLAG_FOLEAUTOMATION
| TYPEFLAG_FDUAL
), "%d: got flags %04x\n", i
, dual_attr
->wTypeFlags
);
2170 ITypeInfo_ReleaseTypeAttr(dual_info
, dual_attr
);
2171 ITypeInfo_Release(dual_info
);
2175 StringFromGUID2(&attr
->guid
, uuidW
, sizeof(uuidW
) / sizeof(uuidW
[0]));
2176 WideCharToMultiByte(CP_ACP
, 0, uuidW
, -1, uuid
, sizeof(uuid
), NULL
, NULL
);
2177 sprintf(key_name
, "Interface\\%s", uuid
);
2179 /* All dispinterfaces will be registered (this includes dual interfaces) as well
2180 as oleautomation interfaces */
2181 if((attr
->typekind
== TKIND_INTERFACE
&& (attr
->wTypeFlags
& TYPEFLAG_FOLEAUTOMATION
)) ||
2182 attr
->typekind
== TKIND_DISPATCH
)
2183 expect_ret
= ERROR_SUCCESS
;
2185 expect_ret
= ERROR_FILE_NOT_FOUND
;
2187 ret
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, key_name
, 0, KEY_READ
, &hkey
);
2188 ok(ret
== expect_ret
, "%d: got %d\n", i
, ret
);
2189 if(ret
== ERROR_SUCCESS
) RegCloseKey(hkey
);
2191 ITypeInfo_ReleaseTypeAttr(typeinfo
, attr
);
2192 ITypeInfo_Release(typeinfo
);
2195 hr
= UnRegisterTypeLib(&LIBID_register_test
, 1, 0, LOCALE_NEUTRAL
, sizeof(void*) == 8 ? SYS_WIN64
: SYS_WIN32
);
2196 ok(SUCCEEDED(hr
), "got %08x\n", hr
);
2198 ITypeLib_Release(typelib
);
2199 DeleteFileA( filenameA
);
2204 const char *filename
;
2206 ref_count_test(wszStdOle2
);
2208 test_CreateDispTypeInfo();
2210 test_QueryPathOfRegTypeLib();
2212 test_CreateTypeLib();
2214 if ((filename
= create_test_typelib(2)))
2216 test_dump_typelib( filename
);
2217 DeleteFile( filename
);
2220 test_register_typelib();
2221 test_create_typelibs();