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>
35 #define expect_eq(expr, value, type, format) { type _ret = (expr); ok((value) == _ret, #expr " expected " format " got " format "\n", value, _ret); }
36 #define expect_int(expr, value) expect_eq(expr, (int)(value), int, "%d")
37 #define expect_hex(expr, value) expect_eq(expr, (int)(value), int, "0x%x")
38 #define expect_null(expr) expect_eq(expr, NULL, const void *, "%p")
40 #define expect_wstr_acpval(expr, value) \
43 expect_eq(!WideCharToMultiByte(CP_ACP, 0, (expr), -1, buf, 260, NULL, NULL), 0, int, "%d"); \
44 ok(lstrcmp(value, buf) == 0, #expr " expected \"%s\" got \"%s\"\n", value, buf); \
47 #define ole_expect(expr, expect) { \
49 ok(r == (expect), #expr " returned %x, expected %s (%x)\n", r, #expect, expect); \
52 #define ole_check(expr) ole_expect(expr, S_OK);
54 #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%08x\n", hr)
56 static const WCHAR wszStdOle2
[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
58 static void ref_count_test(LPCWSTR type_lib
)
61 ITypeInfo
*iti1
, *iti2
;
65 trace("Loading type library\n");
66 hRes
= LoadTypeLib(type_lib
, &iface
);
67 ok(hRes
== S_OK
, "Could not load type library\n");
71 hRes
= ITypeLib_GetTypeInfo(iface
, 1, &iti1
);
72 ok(hRes
== S_OK
, "ITypeLib_GetTypeInfo failed on index = 1\n");
73 ok(ref_count
=ITypeLib_Release(iface
) > 0, "ITypeLib destroyed while ITypeInfo has back pointer\n");
77 hRes
= ITypeLib_GetTypeInfo(iface
, 1, &iti2
);
78 ok(hRes
== S_OK
, "ITypeLib_GetTypeInfo failed on index = 1\n");
79 ok(iti1
== iti2
, "ITypeLib_GetTypeInfo returned different pointers for same indexes\n");
81 ITypeLib_AddRef(iface
);
82 ITypeInfo_Release(iti2
);
83 ITypeInfo_Release(iti1
);
84 ok(ITypeLib_Release(iface
) == 0, "ITypeLib should be destroyed here.\n");
87 static void test_TypeComp(void)
96 ITypeInfo
*pFontTypeInfo
;
97 static WCHAR wszStdFunctions
[] = {'S','t','d','F','u','n','c','t','i','o','n','s',0};
98 static WCHAR wszSavePicture
[] = {'S','a','v','e','P','i','c','t','u','r','e',0};
99 static WCHAR wszOLE_TRISTATE
[] = {'O','L','E','_','T','R','I','S','T','A','T','E',0};
100 static WCHAR wszUnchecked
[] = {'U','n','c','h','e','c','k','e','d',0};
101 static WCHAR wszIUnknown
[] = {'I','U','n','k','n','o','w','n',0};
102 static WCHAR wszFont
[] = {'F','o','n','t',0};
103 static WCHAR wszGUID
[] = {'G','U','I','D',0};
104 static WCHAR wszStdPicture
[] = {'S','t','d','P','i','c','t','u','r','e',0};
105 static WCHAR wszOLE_COLOR
[] = {'O','L','E','_','C','O','L','O','R',0};
106 static WCHAR wszClone
[] = {'C','l','o','n','e',0};
107 static WCHAR wszclone
[] = {'c','l','o','n','e',0};
109 hr
= LoadTypeLib(wszStdOle2
, &pTypeLib
);
110 ok_ole_success(hr
, LoadTypeLib
);
112 hr
= ITypeLib_GetTypeComp(pTypeLib
, &pTypeComp
);
113 ok_ole_success(hr
, ITypeLib_GetTypeComp
);
115 /* test getting a TKIND_MODULE */
116 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszStdFunctions
);
117 hr
= ITypeComp_Bind(pTypeComp
, wszStdFunctions
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
118 ok_ole_success(hr
, ITypeComp_Bind
);
120 ok(desckind
== DESCKIND_TYPECOMP
,
121 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
123 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
125 ITypeComp_Release(bindptr
.lptcomp
);
127 /* test getting a TKIND_MODULE with INVOKE_PROPERTYGET */
128 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszStdFunctions
);
129 hr
= ITypeComp_Bind(pTypeComp
, wszStdFunctions
, ulHash
, INVOKE_PROPERTYGET
, &pTypeInfo
, &desckind
, &bindptr
);
130 ok_ole_success(hr
, ITypeComp_Bind
);
132 ok(desckind
== DESCKIND_TYPECOMP
,
133 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
135 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
136 ITypeComp_Release(bindptr
.lptcomp
);
138 /* test getting a function within a TKIND_MODULE */
139 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszSavePicture
);
140 hr
= ITypeComp_Bind(pTypeComp
, wszSavePicture
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
141 ok_ole_success(hr
, ITypeComp_Bind
);
143 ok(desckind
== DESCKIND_FUNCDESC
,
144 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
146 ok(bindptr
.lpfuncdesc
!= NULL
, "bindptr.lpfuncdesc should not have been set to NULL\n");
147 ITypeInfo_ReleaseFuncDesc(pTypeInfo
, bindptr
.lpfuncdesc
);
148 ITypeInfo_Release(pTypeInfo
);
150 /* test getting a function within a TKIND_MODULE with INVOKE_PROPERTYGET */
151 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszSavePicture
);
152 hr
= ITypeComp_Bind(pTypeComp
, wszSavePicture
, ulHash
, INVOKE_PROPERTYGET
, &pTypeInfo
, &desckind
, &bindptr
);
153 todo_wine
ok(hr
== TYPE_E_TYPEMISMATCH
,
154 "ITypeComp_Bind should have failed with TYPE_E_TYPEMISMATCH instead of 0x%08x\n",
157 ok(desckind
== DESCKIND_NONE
,
158 "desckind should have been DESCKIND_NONE instead of %d\n",
160 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
161 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
163 /* test getting a TKIND_ENUM */
164 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszOLE_TRISTATE
);
165 hr
= ITypeComp_Bind(pTypeComp
, wszOLE_TRISTATE
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
166 ok_ole_success(hr
, ITypeComp_Bind
);
168 ok(desckind
== DESCKIND_TYPECOMP
,
169 "desckind should have been DESCKIND_TYPECOMP instead of %d\n",
171 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
173 ITypeComp_Release(bindptr
.lptcomp
);
175 /* test getting a value within a TKIND_ENUM */
176 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszUnchecked
);
177 hr
= ITypeComp_Bind(pTypeComp
, wszUnchecked
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
178 ok_ole_success(hr
, ITypeComp_Bind
);
180 ok(desckind
== DESCKIND_VARDESC
,
181 "desckind should have been DESCKIND_VARDESC instead of %d\n",
183 ITypeInfo_ReleaseVarDesc(pTypeInfo
, bindptr
.lpvardesc
);
184 ITypeInfo_Release(pTypeInfo
);
186 /* test getting a TKIND_INTERFACE */
187 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszIUnknown
);
188 hr
= ITypeComp_Bind(pTypeComp
, wszIUnknown
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
189 ok_ole_success(hr
, ITypeComp_Bind
);
191 ok(desckind
== DESCKIND_NONE
,
192 "desckind should have been DESCKIND_NONE instead of %d\n",
194 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
195 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
197 /* test getting a TKIND_DISPATCH */
198 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszFont
);
199 hr
= ITypeComp_Bind(pTypeComp
, wszFont
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
200 ok_ole_success(hr
, ITypeComp_Bind
);
202 ok(desckind
== DESCKIND_NONE
,
203 "desckind should have been DESCKIND_NONE instead of %d\n",
205 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
206 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
208 /* test getting a TKIND_RECORD/TKIND_ALIAS */
209 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszGUID
);
210 hr
= ITypeComp_Bind(pTypeComp
, wszGUID
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
211 ok_ole_success(hr
, ITypeComp_Bind
);
213 ok(desckind
== DESCKIND_NONE
,
214 "desckind should have been DESCKIND_NONE instead of %d\n",
216 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
217 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
219 /* test getting a TKIND_ALIAS */
220 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszOLE_COLOR
);
221 hr
= ITypeComp_Bind(pTypeComp
, wszOLE_COLOR
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
222 ok_ole_success(hr
, ITypeComp_Bind
);
224 ok(desckind
== DESCKIND_NONE
,
225 "desckind should have been DESCKIND_NONE instead of %d\n",
227 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
228 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
230 /* test getting a TKIND_COCLASS */
231 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszStdPicture
);
232 hr
= ITypeComp_Bind(pTypeComp
, wszStdPicture
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
233 ok_ole_success(hr
, ITypeComp_Bind
);
235 ok(desckind
== DESCKIND_NONE
,
236 "desckind should have been DESCKIND_NONE instead of %d\n",
238 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
239 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
241 ITypeComp_Release(pTypeComp
);
243 /* tests for ITypeComp on an interface */
244 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, &IID_IFont
, &pFontTypeInfo
);
245 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
247 hr
= ITypeInfo_GetTypeComp(pFontTypeInfo
, &pTypeComp
);
248 ok_ole_success(hr
, ITypeLib_GetTypeComp
);
250 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszClone
);
251 hr
= ITypeComp_Bind(pTypeComp
, wszClone
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
252 ok_ole_success(hr
, ITypeComp_Bind
);
254 ok(desckind
== DESCKIND_FUNCDESC
,
255 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
257 ok(bindptr
.lpfuncdesc
!= NULL
, "bindptr.lpfuncdesc should not have been set to NULL\n");
258 ITypeInfo_ReleaseFuncDesc(pTypeInfo
, bindptr
.lpfuncdesc
);
259 ITypeInfo_Release(pTypeInfo
);
261 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszClone
);
262 hr
= ITypeComp_Bind(pTypeComp
, wszClone
, ulHash
, INVOKE_PROPERTYGET
, &pTypeInfo
, &desckind
, &bindptr
);
263 ok(hr
== TYPE_E_TYPEMISMATCH
, "ITypeComp_Bind should have failed with TYPE_E_TYPEMISMATCH instead of 0x%08x\n", hr
);
265 ok(desckind
== DESCKIND_NONE
,
266 "desckind should have been DESCKIND_NONE instead of %d\n",
268 ok(!pTypeInfo
, "pTypeInfo should have been set to NULL\n");
269 ok(!bindptr
.lptcomp
, "bindptr should have been set to NULL\n");
271 /* tests that the compare is case-insensitive */
272 ulHash
= LHashValOfNameSys(SYS_WIN32
, LOCALE_NEUTRAL
, wszclone
);
273 hr
= ITypeComp_Bind(pTypeComp
, wszclone
, ulHash
, 0, &pTypeInfo
, &desckind
, &bindptr
);
274 ok_ole_success(hr
, ITypeComp_Bind
);
276 ok(desckind
== DESCKIND_FUNCDESC
,
277 "desckind should have been DESCKIND_FUNCDESC instead of %d\n",
279 ok(bindptr
.lpfuncdesc
!= NULL
, "bindptr.lpfuncdesc should not have been set to NULL\n");
280 ITypeInfo_ReleaseFuncDesc(pTypeInfo
, bindptr
.lpfuncdesc
);
281 ITypeInfo_Release(pTypeInfo
);
283 ITypeComp_Release(pTypeComp
);
284 ITypeInfo_Release(pFontTypeInfo
);
285 ITypeLib_Release(pTypeLib
);
288 static void test_CreateDispTypeInfo(void)
290 ITypeInfo
*pTypeInfo
, *pTI2
;
292 INTERFACEDATA ifdata
;
293 METHODDATA methdata
[4];
301 static WCHAR func1
[] = {'f','u','n','c','1',0};
302 static const WCHAR func2
[] = {'f','u','n','c','2',0};
303 static const WCHAR func3
[] = {'f','u','n','c','3',0};
304 static const WCHAR parm1
[] = {'p','a','r','m','1',0};
305 static const WCHAR parm2
[] = {'p','a','r','m','2',0};
306 OLECHAR
*name
= func1
;
308 ifdata
.pmethdata
= methdata
;
309 ifdata
.cMembers
= sizeof(methdata
) / sizeof(methdata
[0]);
311 methdata
[0].szName
= SysAllocString(func1
);
312 methdata
[0].ppdata
= parms1
;
313 methdata
[0].dispid
= 0x123;
314 methdata
[0].iMeth
= 0;
315 methdata
[0].cc
= CC_STDCALL
;
316 methdata
[0].cArgs
= 2;
317 methdata
[0].wFlags
= DISPATCH_METHOD
;
318 methdata
[0].vtReturn
= VT_HRESULT
;
319 parms1
[0].szName
= SysAllocString(parm1
);
320 parms1
[0].vt
= VT_I4
;
321 parms1
[1].szName
= SysAllocString(parm2
);
322 parms1
[1].vt
= VT_BSTR
;
324 methdata
[1].szName
= SysAllocString(func2
);
325 methdata
[1].ppdata
= NULL
;
326 methdata
[1].dispid
= 0x124;
327 methdata
[1].iMeth
= 1;
328 methdata
[1].cc
= CC_STDCALL
;
329 methdata
[1].cArgs
= 0;
330 methdata
[1].wFlags
= DISPATCH_PROPERTYGET
;
331 methdata
[1].vtReturn
= VT_I4
;
333 methdata
[2].szName
= SysAllocString(func3
);
334 methdata
[2].ppdata
= parms3
;
335 methdata
[2].dispid
= 0x125;
336 methdata
[2].iMeth
= 3;
337 methdata
[2].cc
= CC_STDCALL
;
338 methdata
[2].cArgs
= 1;
339 methdata
[2].wFlags
= DISPATCH_PROPERTYPUT
;
340 methdata
[2].vtReturn
= VT_HRESULT
;
341 parms3
[0].szName
= SysAllocString(parm1
);
342 parms3
[0].vt
= VT_I4
;
344 methdata
[3].szName
= SysAllocString(func3
);
345 methdata
[3].ppdata
= NULL
;
346 methdata
[3].dispid
= 0x125;
347 methdata
[3].iMeth
= 4;
348 methdata
[3].cc
= CC_STDCALL
;
349 methdata
[3].cArgs
= 0;
350 methdata
[3].wFlags
= DISPATCH_PROPERTYGET
;
351 methdata
[3].vtReturn
= VT_I4
;
353 hr
= CreateDispTypeInfo(&ifdata
, LOCALE_NEUTRAL
, &pTypeInfo
);
354 ok(hr
== S_OK
, "hr %08x\n", hr
);
356 hr
= ITypeInfo_GetTypeAttr(pTypeInfo
, &pTypeAttr
);
357 ok(hr
== S_OK
, "hr %08x\n", hr
);
359 ok(pTypeAttr
->typekind
== TKIND_COCLASS
, "typekind %0x\n", pTypeAttr
->typekind
);
360 ok(pTypeAttr
->cImplTypes
== 1, "cImplTypes %d\n", pTypeAttr
->cImplTypes
);
361 ok(pTypeAttr
->cFuncs
== 0, "cFuncs %d\n", pTypeAttr
->cFuncs
);
362 ok(pTypeAttr
->wTypeFlags
== 0, "wTypeFlags %04x\n", pTypeAttr
->cFuncs
);
363 ITypeInfo_ReleaseTypeAttr(pTypeInfo
, pTypeAttr
);
365 hr
= ITypeInfo_GetRefTypeOfImplType(pTypeInfo
, 0, &href
);
366 ok(hr
== S_OK
, "hr %08x\n", hr
);
367 ok(href
== 0, "href = 0x%x\n", href
);
368 hr
= ITypeInfo_GetRefTypeInfo(pTypeInfo
, href
, &pTI2
);
369 ok(hr
== S_OK
, "hr %08x\n", hr
);
370 hr
= ITypeInfo_GetTypeAttr(pTI2
, &pTypeAttr
);
371 ok(hr
== S_OK
, "hr %08x\n", hr
);
372 ok(pTypeAttr
->typekind
== TKIND_INTERFACE
, "typekind %0x\n", pTypeAttr
->typekind
);
373 ok(pTypeAttr
->cFuncs
== 4, "cFuncs %d\n", pTypeAttr
->cFuncs
);
374 ok(IsEqualGUID(&pTypeAttr
->guid
, &GUID_NULL
), "guid {%08x-...}\n", pTypeAttr
->guid
.Data1
);
375 ok(pTypeAttr
->wTypeFlags
== 0, "typeflags %08x\n", pTypeAttr
->wTypeFlags
);
377 ITypeInfo_ReleaseTypeAttr(pTI2
, pTypeAttr
);
379 hr
= ITypeInfo_GetFuncDesc(pTI2
, 0, &pFuncDesc
);
380 ok(hr
== S_OK
, "hr %08x\n", hr
);
381 ok(pFuncDesc
->memid
== 0x123, "memid %x\n", pFuncDesc
->memid
);
382 ok(pFuncDesc
->funckind
== FUNC_VIRTUAL
, "funckind %d\n", pFuncDesc
->funckind
);
383 ok(pFuncDesc
->invkind
== methdata
[0].wFlags
, "invkind %d\n", pFuncDesc
->invkind
);
384 ok(pFuncDesc
->callconv
== methdata
[0].cc
, "callconv %d\n", pFuncDesc
->callconv
);
385 ok(pFuncDesc
->cParams
== methdata
[0].cArgs
, "cParams %d\n", pFuncDesc
->cParams
);
386 ok(pFuncDesc
->oVft
== 0, "oVft %d\n", pFuncDesc
->oVft
);
387 ok(pFuncDesc
->wFuncFlags
== 0, "oVft %d\n", pFuncDesc
->wFuncFlags
);
388 ok(pFuncDesc
->elemdescFunc
.tdesc
.vt
== VT_HRESULT
, "ret vt %x\n", pFuncDesc
->elemdescFunc
.tdesc
.vt
);
389 ok(pFuncDesc
->lprgelemdescParam
[0].tdesc
.vt
== VT_I4
, "parm 0 vt %x\n", pFuncDesc
->lprgelemdescParam
[0].tdesc
.vt
);
390 ok(U(pFuncDesc
->lprgelemdescParam
[0]).paramdesc
.wParamFlags
== PARAMFLAG_NONE
, "parm 0 flags %x\n", U(pFuncDesc
->lprgelemdescParam
[0]).paramdesc
.wParamFlags
);
392 ok(pFuncDesc
->lprgelemdescParam
[1].tdesc
.vt
== VT_BSTR
, "parm 1 vt %x\n", pFuncDesc
->lprgelemdescParam
[1].tdesc
.vt
);
393 ok(U(pFuncDesc
->lprgelemdescParam
[1]).paramdesc
.wParamFlags
== PARAMFLAG_NONE
, "parm 1 flags %x\n", U(pFuncDesc
->lprgelemdescParam
[1]).paramdesc
.wParamFlags
);
394 ITypeInfo_ReleaseFuncDesc(pTI2
, pFuncDesc
);
396 hr
= ITypeInfo_GetFuncDesc(pTI2
, 1, &pFuncDesc
);
397 ok(hr
== S_OK
, "hr %08x\n", hr
);
398 ok(pFuncDesc
->funckind
== FUNC_VIRTUAL
, "funckind %d\n", pFuncDesc
->funckind
);
399 ok(pFuncDesc
->invkind
== methdata
[1].wFlags
, "invkind %d\n", pFuncDesc
->invkind
);
400 ok(pFuncDesc
->callconv
== methdata
[1].cc
, "callconv %d\n", pFuncDesc
->callconv
);
401 ok(pFuncDesc
->cParams
== methdata
[1].cArgs
, "cParams %d\n", pFuncDesc
->cParams
);
402 ok(pFuncDesc
->oVft
== sizeof(void *), "oVft %d\n", pFuncDesc
->oVft
);
403 ok(pFuncDesc
->wFuncFlags
== 0, "oVft %d\n", pFuncDesc
->wFuncFlags
);
404 ok(pFuncDesc
->elemdescFunc
.tdesc
.vt
== VT_I4
, "ret vt %x\n", pFuncDesc
->elemdescFunc
.tdesc
.vt
);
405 ITypeInfo_ReleaseFuncDesc(pTI2
, pFuncDesc
);
407 hr
= ITypeInfo_GetFuncDesc(pTI2
, 2, &pFuncDesc
);
408 ok(hr
== S_OK
, "hr %08x\n", hr
);
409 ok(pFuncDesc
->funckind
== FUNC_VIRTUAL
, "funckind %d\n", pFuncDesc
->funckind
);
410 ok(pFuncDesc
->invkind
== methdata
[2].wFlags
, "invkind %d\n", pFuncDesc
->invkind
);
411 ok(pFuncDesc
->callconv
== methdata
[2].cc
, "callconv %d\n", pFuncDesc
->callconv
);
412 ok(pFuncDesc
->cParams
== methdata
[2].cArgs
, "cParams %d\n", pFuncDesc
->cParams
);
413 ok(pFuncDesc
->oVft
== 3 * sizeof(void *), "oVft %d\n", pFuncDesc
->oVft
);
414 ok(pFuncDesc
->wFuncFlags
== 0, "oVft %d\n", pFuncDesc
->wFuncFlags
);
415 ok(pFuncDesc
->elemdescFunc
.tdesc
.vt
== VT_HRESULT
, "ret vt %x\n", pFuncDesc
->elemdescFunc
.tdesc
.vt
);
416 ok(pFuncDesc
->lprgelemdescParam
[0].tdesc
.vt
== VT_I4
, "parm 0 vt %x\n", pFuncDesc
->lprgelemdescParam
[0].tdesc
.vt
);
417 ok(U(pFuncDesc
->lprgelemdescParam
[0]).paramdesc
.wParamFlags
== PARAMFLAG_NONE
, "parm 0 flags %x\n", U(pFuncDesc
->lprgelemdescParam
[0]).paramdesc
.wParamFlags
);
418 ITypeInfo_ReleaseFuncDesc(pTI2
, pFuncDesc
);
420 hr
= ITypeInfo_GetFuncDesc(pTI2
, 3, &pFuncDesc
);
421 ok(hr
== S_OK
, "hr %08x\n", hr
);
422 ok(pFuncDesc
->funckind
== FUNC_VIRTUAL
, "funckind %d\n", pFuncDesc
->funckind
);
423 ok(pFuncDesc
->invkind
== methdata
[3].wFlags
, "invkind %d\n", pFuncDesc
->invkind
);
424 ok(pFuncDesc
->callconv
== methdata
[3].cc
, "callconv %d\n", pFuncDesc
->callconv
);
425 ok(pFuncDesc
->cParams
== methdata
[3].cArgs
, "cParams %d\n", pFuncDesc
->cParams
);
426 ok(pFuncDesc
->oVft
== 4 * sizeof(void *), "oVft %d\n", pFuncDesc
->oVft
);
427 ok(pFuncDesc
->wFuncFlags
== 0, "oVft %d\n", pFuncDesc
->wFuncFlags
);
428 ok(pFuncDesc
->elemdescFunc
.tdesc
.vt
== VT_I4
, "ret vt %x\n", pFuncDesc
->elemdescFunc
.tdesc
.vt
);
429 ITypeInfo_ReleaseFuncDesc(pTI2
, pFuncDesc
);
431 /* test GetIDsOfNames on a coclass to see if it searches its interfaces */
432 hr
= ITypeInfo_GetIDsOfNames(pTypeInfo
, &name
, 1, &memid
);
433 ok(hr
== S_OK
, "hr 0x%08x\n", hr
);
434 ok(memid
== 0x123, "memid 0x%08x\n", memid
);
436 ITypeInfo_Release(pTI2
);
437 ITypeInfo_Release(pTypeInfo
);
439 SysFreeString(parms1
[0].szName
);
440 SysFreeString(parms1
[1].szName
);
441 SysFreeString(parms3
[0].szName
);
442 SysFreeString(methdata
[0].szName
);
443 SysFreeString(methdata
[1].szName
);
444 SysFreeString(methdata
[2].szName
);
445 SysFreeString(methdata
[3].szName
);
448 static void test_TypeInfo(void)
451 ITypeInfo
*pTypeInfo
;
452 ITypeInfo2
*pTypeInfo2
;
454 static WCHAR wszBogus
[] = { 'b','o','g','u','s',0 };
455 static WCHAR wszGetTypeInfo
[] = { 'G','e','t','T','y','p','e','I','n','f','o',0 };
456 static WCHAR wszClone
[] = {'C','l','o','n','e',0};
457 OLECHAR
* bogus
= wszBogus
;
458 OLECHAR
* pwszGetTypeInfo
= wszGetTypeInfo
;
459 OLECHAR
* pwszClone
= wszClone
;
461 DISPPARAMS dispparams
;
462 GUID bogusguid
= {0x806afb4f,0x13f7,0x42d2,{0x89,0x2c,0x6c,0x97,0xc3,0x6a,0x36,0xc1}};
465 hr
= LoadTypeLib(wszStdOle2
, &pTypeLib
);
466 ok_ole_success(hr
, LoadTypeLib
);
468 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, &IID_IFont
, &pTypeInfo
);
469 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
471 /* test nonexistent method name */
472 hr
= ITypeInfo_GetIDsOfNames(pTypeInfo
, &bogus
, 1, &dispidMember
);
473 ok(hr
== DISP_E_UNKNOWNNAME
,
474 "ITypeInfo_GetIDsOfNames should have returned DISP_E_UNKNOWNNAME instead of 0x%08x\n",
477 /* test invalid memberid */
478 dispparams
.cNamedArgs
= 0;
479 dispparams
.cArgs
= 0;
480 dispparams
.rgdispidNamedArgs
= NULL
;
481 dispparams
.rgvarg
= NULL
;
482 hr
= ITypeInfo_Invoke(pTypeInfo
, (void *)0xdeadbeef, 0xdeadbeef, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
483 ok(hr
== DISP_E_MEMBERNOTFOUND
, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr
);
485 hr
= ITypeInfo_GetIDsOfNames(pTypeInfo
, &pwszClone
, 1, &dispidMember
);
486 ok_ole_success(hr
, ITypeInfo_GetIDsOfNames
);
488 /* test correct memberid, but wrong flags */
489 hr
= ITypeInfo_Invoke(pTypeInfo
, (void *)0xdeadbeef, dispidMember
, DISPATCH_PROPERTYGET
, &dispparams
, NULL
, NULL
, NULL
);
490 ok(hr
== DISP_E_MEMBERNOTFOUND
, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr
);
492 /* test NULL dispparams */
493 hr
= ITypeInfo_Invoke(pTypeInfo
, (void *)0xdeadbeef, dispidMember
, DISPATCH_METHOD
, NULL
, NULL
, NULL
, NULL
);
494 ok(hr
== E_INVALIDARG
, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
496 /* test dispparams->cNamedArgs being bigger than dispparams->cArgs */
497 dispparams
.cNamedArgs
= 1;
498 hr
= ITypeInfo_Invoke(pTypeInfo
, (void *)0xdeadbeef, dispidMember
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
499 ok(hr
== E_INVALIDARG
, "ITypeInfo_Invoke should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
501 ITypeInfo_Release(pTypeInfo
);
503 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, &IID_IDispatch
, &pTypeInfo
);
504 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
506 hr
= ITypeInfo_GetIDsOfNames(pTypeInfo
, &pwszGetTypeInfo
, 1, &dispidMember
);
507 ok_ole_success(hr
, ITypeInfo_GetIDsOfNames
);
509 hr
= ITypeInfo_QueryInterface(pTypeInfo
, &IID_ITypeInfo2
, (void**)&pTypeInfo2
);
510 ok_ole_success(hr
, ITypeInfo_QueryInterface
);
518 /* test unknown guid passed to GetCustData */
519 hr
= ITypeInfo2_GetCustData(pTypeInfo2
, &bogusguid
, &var
);
520 ok_ole_success(hr
, ITypeInfo_GetCustData
);
521 ok(V_VT(&var
) == VT_EMPTY
, "got %i, expected VT_EMPTY\n", V_VT(&var
));
523 ITypeInfo2_Release(pTypeInfo2
);
528 /* test invoking a method with a [restricted] keyword */
529 hr
= ITypeInfo_Invoke(pTypeInfo
, NULL
, dispidMember
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
531 ok(hr
== DISP_E_MEMBERNOTFOUND
, "ITypeInfo_Invoke should have returned DISP_E_MEMBERNOTFOUND instead of 0x%08x\n", hr
);
534 ITypeInfo_Release(pTypeInfo
);
535 ITypeLib_Release(pTypeLib
);
538 /* RegDeleteTreeW from dlls/advapi32/registry.c */
539 static LSTATUS
myRegDeleteTreeW(HKEY hKey
, LPCWSTR lpszSubKey
)
542 DWORD dwMaxSubkeyLen
, dwMaxValueLen
;
543 DWORD dwMaxLen
, dwSize
;
544 WCHAR szNameBuf
[MAX_PATH
], *lpszName
= szNameBuf
;
549 ret
= RegOpenKeyExW(hKey
, lpszSubKey
, 0, KEY_READ
, &hSubKey
);
553 ret
= RegQueryInfoKeyW(hSubKey
, NULL
, NULL
, NULL
, NULL
,
554 &dwMaxSubkeyLen
, NULL
, NULL
, &dwMaxValueLen
, NULL
, NULL
, NULL
);
555 if (ret
) goto cleanup
;
559 dwMaxLen
= max(dwMaxSubkeyLen
, dwMaxValueLen
);
560 if (dwMaxLen
> sizeof(szNameBuf
)/sizeof(WCHAR
))
562 /* Name too big: alloc a buffer for it */
563 if (!(lpszName
= HeapAlloc( GetProcessHeap(), 0, dwMaxLen
*sizeof(WCHAR
))))
565 ret
= ERROR_NOT_ENOUGH_MEMORY
;
570 /* Recursively delete all the subkeys */
574 if (RegEnumKeyExW(hSubKey
, 0, lpszName
, &dwSize
, NULL
,
575 NULL
, NULL
, NULL
)) break;
577 ret
= myRegDeleteTreeW(hSubKey
, lpszName
);
578 if (ret
) goto cleanup
;
582 ret
= RegDeleteKeyW(hKey
, lpszSubKey
);
587 if (RegEnumValueW(hKey
, 0, lpszName
, &dwSize
,
588 NULL
, NULL
, NULL
, NULL
)) break;
590 ret
= RegDeleteValueW(hKey
, lpszName
);
591 if (ret
) goto cleanup
;
595 if (lpszName
!= szNameBuf
)
596 HeapFree(GetProcessHeap(), 0, lpszName
);
598 RegCloseKey(hSubKey
);
602 static BOOL
do_typelib_reg_key(GUID
*uid
, WORD maj
, WORD min
, LPCWSTR base
, BOOL remove
)
604 static const WCHAR typelibW
[] = {'T','y','p','e','l','i','b','\\',0};
605 static const WCHAR formatW
[] = {'\\','%','u','.','%','u','\\','0','\\','w','i','n','3','2',0};
606 static const WCHAR format2W
[] = {'%','s','_','%','u','_','%','u','.','d','l','l',0};
612 memcpy(buf
, typelibW
, sizeof(typelibW
));
613 StringFromGUID2(uid
, buf
+ lstrlenW(buf
), 40);
617 ok(myRegDeleteTreeW(HKEY_CLASSES_ROOT
, buf
) == ERROR_SUCCESS
, "SHDeleteKey failed\n");
621 wsprintfW(buf
+ lstrlenW(buf
), formatW
, maj
, min
);
623 SetLastError(0xdeadbeef);
624 res
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, buf
, 0, NULL
, 0,
625 KEY_WRITE
, NULL
, &hkey
, NULL
);
626 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
628 win_skip("W-calls are not implemented\n");
632 if (res
!= ERROR_SUCCESS
)
634 trace("RegCreateKeyExW failed\n");
638 wsprintfW(buf
, format2W
, base
, maj
, min
);
639 if (RegSetValueExW(hkey
, NULL
, 0, REG_SZ
,
640 (BYTE
*)buf
, (lstrlenW(buf
) + 1) * sizeof(WCHAR
)) != ERROR_SUCCESS
)
642 trace("RegSetValueExW failed\n");
649 static void test_QueryPathOfRegTypeLib(void)
651 static const struct test_data
655 const WCHAR path
[16];
657 { 1, 0, TYPE_E_LIBNOTREGISTERED
, { 0 } },
658 { 3, 0, S_OK
, {'f','a','k','e','_','3','_','0','.','d','l','l',0 } },
659 { 3, 1, S_OK
, {'f','a','k','e','_','3','_','1','.','d','l','l',0 } },
660 { 3, 22, S_OK
, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
661 { 3, 37, S_OK
, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
662 { 3, 40, S_OK
, {'f','a','k','e','_','3','_','3','7','.','d','l','l',0 } },
663 { 0xffff, 0xffff, S_OK
, {'f','a','k','e','_','5','_','3','7','.','d','l','l',0 } },
664 { 0xffff, 0, TYPE_E_LIBNOTREGISTERED
, { 0 } },
665 { 3, 0xffff, TYPE_E_LIBNOTREGISTERED
, { 0 } },
666 { 5, 0xffff, TYPE_E_LIBNOTREGISTERED
, { 0 } },
667 { 4, 0, TYPE_E_LIBNOTREGISTERED
, { 0 } }
669 static const WCHAR base
[] = {'f','a','k','e',0};
677 status
= UuidCreate(&uid
);
678 ok(!status
|| status
== RPC_S_UUID_LOCAL_ONLY
, "UuidCreate error %08x\n", status
);
680 StringFromGUID2(&uid
, uid_str
, 40);
681 /*trace("GUID: %s\n", wine_dbgstr_w(uid_str));*/
683 if (!do_typelib_reg_key(&uid
, 3, 0, base
, 0)) return;
684 if (!do_typelib_reg_key(&uid
, 3, 1, base
, 0)) return;
685 if (!do_typelib_reg_key(&uid
, 3, 37, base
, 0)) return;
686 if (!do_typelib_reg_key(&uid
, 5, 37, base
, 0)) return;
688 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
690 ret
= QueryPathOfRegTypeLib(&uid
, td
[i
].maj
, td
[i
].min
, 0, &path
);
691 ok(ret
== td
[i
].ret
, "QueryPathOfRegTypeLib(%u.%u) returned %08x\n", td
[i
].maj
, td
[i
].min
, ret
);
694 ok(!lstrcmpW(td
[i
].path
, path
), "typelib %u.%u path doesn't match\n", td
[i
].maj
, td
[i
].min
);
699 do_typelib_reg_key(&uid
, 0, 0, NULL
, 1);
702 static void test_inheritance(void)
706 ITypeInfo
*pTI
, *pTI_p
;
710 WCHAR path
[MAX_PATH
];
711 CHAR pathA
[MAX_PATH
];
712 static const WCHAR tl_path
[] = {'.','\\','m','i','d','l','_','t','m','a','r','s','h','a','l','.','t','l','b',0};
714 BOOL use_midl_tlb
= 0;
716 GetModuleFileNameA(NULL
, pathA
, MAX_PATH
);
717 MultiByteToWideChar(CP_ACP
, 0, pathA
, -1, path
, MAX_PATH
);
720 memcpy(path
, tl_path
, sizeof(tl_path
));
722 hr
= LoadTypeLib(path
, &pTL
);
723 if(FAILED(hr
)) return;
726 /* ItestIF3 is a syntax 2 dispinterface */
727 hr
= ITypeLib_GetTypeInfoOfGuid(pTL
, &DIID_ItestIF3
, &pTI
);
728 ok(hr
== S_OK
, "hr %08x\n", hr
);
730 hr
= ITypeInfo_GetTypeAttr(pTI
, &pTA
);
731 ok(hr
== S_OK
, "hr %08x\n", hr
);
732 ok(pTA
->typekind
== TKIND_DISPATCH
, "kind %04x\n", pTA
->typekind
);
733 ok(pTA
->cbSizeVft
== 7 * sizeof(void *), "sizevft %d\n", pTA
->cbSizeVft
);
734 ok(pTA
->wTypeFlags
== TYPEFLAG_FDISPATCHABLE
, "typeflags %x\n", pTA
->wTypeFlags
);
736 ok(pTA
->cFuncs
== 6, "cfuncs %d\n", pTA
->cFuncs
);
737 ok(pTA
->cImplTypes
== 1, "cimpltypes %d\n", pTA
->cImplTypes
);
739 ITypeInfo_ReleaseTypeAttr(pTI
, pTA
);
742 hr
= ITypeInfo_GetRefTypeOfImplType(pTI
, 0, &href
);
743 ok(hr
== S_OK
, "hr %08x\n", hr
);
744 hr
= ITypeInfo_GetRefTypeInfo(pTI
, href
, &pTI_p
);
745 ok(hr
== S_OK
, "hr %08x\n", hr
);
746 hr
= ITypeInfo_GetTypeAttr(pTI_p
, &pTA
);
747 ok(IsEqualGUID(&pTA
->guid
, &IID_IDispatch
), "guid {%08x-....\n", pTA
->guid
.Data1
);
748 ITypeInfo_ReleaseTypeAttr(pTI_p
, pTA
);
749 ITypeInfo_Release(pTI_p
);
751 /* Should have six methods */
752 hr
= ITypeInfo_GetFuncDesc(pTI
, 6, &pFD
);
753 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "hr %08x\n", hr
);
754 hr
= ITypeInfo_GetFuncDesc(pTI
, 5, &pFD
);
755 ok(hr
== S_OK
, "hr %08x\n", hr
);
756 ok(pFD
->memid
== 0x60020000, "memid %08x\n", pFD
->memid
);
757 ok(pFD
->oVft
== 5 * sizeof(void *), "oVft %d\n", pFD
->oVft
);
758 ITypeInfo_ReleaseFuncDesc(pTI
, pFD
);
760 ITypeInfo_Release(pTI
);
763 /* ItestIF4 is a syntax 1 dispinterface */
764 hr
= ITypeLib_GetTypeInfoOfGuid(pTL
, &DIID_ItestIF4
, &pTI
);
765 ok(hr
== S_OK
, "hr %08x\n", hr
);
767 hr
= ITypeInfo_GetTypeAttr(pTI
, &pTA
);
768 ok(hr
== S_OK
, "hr %08x\n", hr
);
769 ok(pTA
->typekind
== TKIND_DISPATCH
, "kind %04x\n", pTA
->typekind
);
770 ok(pTA
->cbSizeVft
== 7 * sizeof(void *), "sizevft %d\n", pTA
->cbSizeVft
);
771 ok(pTA
->wTypeFlags
== TYPEFLAG_FDISPATCHABLE
, "typeflags %x\n", pTA
->wTypeFlags
);
772 ok(pTA
->cFuncs
== 1, "cfuncs %d\n", pTA
->cFuncs
);
773 ok(pTA
->cImplTypes
== 1, "cimpltypes %d\n", pTA
->cImplTypes
);
774 ITypeInfo_ReleaseTypeAttr(pTI
, pTA
);
776 hr
= ITypeInfo_GetRefTypeOfImplType(pTI
, 0, &href
);
777 ok(hr
== S_OK
, "hr %08x\n", hr
);
778 hr
= ITypeInfo_GetRefTypeInfo(pTI
, href
, &pTI_p
);
779 ok(hr
== S_OK
, "hr %08x\n", hr
);
780 hr
= ITypeInfo_GetTypeAttr(pTI_p
, &pTA
);
781 ok(IsEqualGUID(&pTA
->guid
, &IID_IDispatch
), "guid {%08x-....\n", pTA
->guid
.Data1
);
782 ITypeInfo_ReleaseTypeAttr(pTI_p
, pTA
);
783 ITypeInfo_Release(pTI_p
);
784 hr
= ITypeInfo_GetFuncDesc(pTI
, 1, &pFD
);
785 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "hr %08x\n", hr
);
786 hr
= ITypeInfo_GetFuncDesc(pTI
, 0, &pFD
);
787 ok(hr
== S_OK
, "hr %08x\n", hr
);
788 ok(pFD
->memid
== 0x1c, "memid %08x\n", pFD
->memid
);
789 ITypeInfo_ReleaseFuncDesc(pTI
, pFD
);
790 ITypeInfo_Release(pTI
);
793 /* ItestIF5 is dual with inherited ifaces which derive from IUnknown but not IDispatch */
794 hr
= ITypeLib_GetTypeInfoOfGuid(pTL
, &IID_ItestIF5
, &pTI
);
795 ok(hr
== S_OK
, "hr %08x\n", hr
);
797 hr
= ITypeInfo_GetTypeAttr(pTI
, &pTA
);
798 ok(hr
== S_OK
, "hr %08x\n", hr
);
801 ok(pTA
->typekind
== TKIND_DISPATCH
, "kind %04x\n", pTA
->typekind
);
802 ok(pTA
->cbSizeVft
== 7 * sizeof(void *), "sizevft %d\n", pTA
->cbSizeVft
);
804 ok(pTA
->wTypeFlags
== TYPEFLAG_FDUAL
, "typeflags %x\n", pTA
->wTypeFlags
);
806 ok(pTA
->cFuncs
== 8, "cfuncs %d\n", pTA
->cFuncs
);
807 ok(pTA
->cImplTypes
== 1, "cimpltypes %d\n", pTA
->cImplTypes
);
808 ITypeInfo_ReleaseTypeAttr(pTI
, pTA
);
810 hr
= ITypeInfo_GetRefTypeOfImplType(pTI
, 0, &href
);
811 ok(hr
== S_OK
, "hr %08x\n", hr
);
812 hr
= ITypeInfo_GetRefTypeInfo(pTI
, href
, &pTI_p
);
813 ok(hr
== S_OK
, "hr %08x\n", hr
);
814 hr
= ITypeInfo_GetTypeAttr(pTI_p
, &pTA
);
815 ok(IsEqualGUID(&pTA
->guid
, &IID_IDispatch
), "guid {%08x-....\n", pTA
->guid
.Data1
);
816 ITypeInfo_ReleaseTypeAttr(pTI_p
, pTA
);
817 ITypeInfo_Release(pTI_p
);
819 hr
= ITypeInfo_GetFuncDesc(pTI
, 6, &pFD
);
820 ok(hr
== S_OK
, "hr %08x\n", hr
);
821 ok(pFD
->memid
== 0x1234, "memid %08x\n", pFD
->memid
);
822 ITypeInfo_ReleaseFuncDesc(pTI
, pFD
);
824 ITypeInfo_Release(pTI
);
826 /* ItestIF7 is dual with inherited ifaces which derive from Dispatch */
827 hr
= ITypeLib_GetTypeInfoOfGuid(pTL
, &IID_ItestIF7
, &pTI
);
828 ok(hr
== S_OK
, "hr %08x\n", hr
);
830 hr
= ITypeInfo_GetTypeAttr(pTI
, &pTA
);
831 ok(hr
== S_OK
, "hr %08x\n", hr
);
832 ok(pTA
->typekind
== TKIND_DISPATCH
, "kind %04x\n", pTA
->typekind
);
833 ok(pTA
->cbSizeVft
== 7 * sizeof(void *), "sizevft %d\n", pTA
->cbSizeVft
);
834 ok(pTA
->wTypeFlags
== (TYPEFLAG_FDISPATCHABLE
|TYPEFLAG_FDUAL
), "typeflags %x\n", pTA
->wTypeFlags
);
835 ok(pTA
->cFuncs
== 10, "cfuncs %d\n", pTA
->cFuncs
);
836 ok(pTA
->cImplTypes
== 1, "cimpltypes %d\n", pTA
->cImplTypes
);
837 ITypeInfo_ReleaseTypeAttr(pTI
, pTA
);
839 hr
= ITypeInfo_GetRefTypeOfImplType(pTI
, 0, &href
);
840 ok(hr
== S_OK
, "hr %08x\n", hr
);
841 hr
= ITypeInfo_GetRefTypeInfo(pTI
, href
, &pTI_p
);
842 ok(hr
== S_OK
, "hr %08x\n", hr
);
843 hr
= ITypeInfo_GetTypeAttr(pTI_p
, &pTA
);
844 ok(IsEqualGUID(&pTA
->guid
, &IID_IDispatch
), "guid {%08x-....\n", pTA
->guid
.Data1
);
845 ITypeInfo_ReleaseTypeAttr(pTI_p
, pTA
);
846 ITypeInfo_Release(pTI_p
);
848 hr
= ITypeInfo_GetFuncDesc(pTI
, 9, &pFD
);
849 ok(hr
== S_OK
, "hr %08x\n", hr
);
850 ok(pFD
->memid
== 0x1236, "memid %08x\n", pFD
->memid
);
851 ITypeInfo_ReleaseFuncDesc(pTI
, pFD
);
852 ITypeInfo_Release(pTI
);
854 /* ItestIF10 is a syntax 2 dispinterface which doesn't derive from IUnknown */
855 hr
= ITypeLib_GetTypeInfoOfGuid(pTL
, &DIID_ItestIF10
, &pTI
);
856 ok(hr
== S_OK
, "hr %08x\n", hr
);
858 hr
= ITypeInfo_GetTypeAttr(pTI
, &pTA
);
859 ok(hr
== S_OK
, "hr %08x\n", hr
);
860 ok(pTA
->typekind
== TKIND_DISPATCH
, "kind %04x\n", pTA
->typekind
);
861 ok(pTA
->cbSizeVft
== 7 * sizeof(void *), "sizevft %d\n", pTA
->cbSizeVft
);
862 ok(pTA
->wTypeFlags
== TYPEFLAG_FDISPATCHABLE
, "typeflags %x\n", pTA
->wTypeFlags
);
864 ok(pTA
->cFuncs
== 3, "cfuncs %d\n", pTA
->cFuncs
);
865 ok(pTA
->cImplTypes
== 1, "cimpltypes %d\n", pTA
->cImplTypes
);
867 ITypeInfo_ReleaseTypeAttr(pTI
, pTA
);
870 hr
= ITypeInfo_GetRefTypeOfImplType(pTI
, -1, &href
);
871 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "hr %08x\n", hr
);
872 hr
= ITypeInfo_GetRefTypeOfImplType(pTI
, 0, &href
);
873 ok(hr
== S_OK
, "hr %08x\n", hr
);
874 hr
= ITypeInfo_GetRefTypeInfo(pTI
, href
, &pTI_p
);
875 ok(hr
== S_OK
, "hr %08x\n", hr
);
876 hr
= ITypeInfo_GetTypeAttr(pTI_p
, &pTA
);
877 ok(IsEqualGUID(&pTA
->guid
, &IID_IDispatch
), "guid {%08x-....\n", pTA
->guid
.Data1
);
878 ITypeInfo_ReleaseTypeAttr(pTI_p
, pTA
);
879 ITypeInfo_Release(pTI_p
);
881 /* Should have three methods */
882 hr
= ITypeInfo_GetFuncDesc(pTI
, 3, &pFD
);
883 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "hr %08x\n", hr
);
884 hr
= ITypeInfo_GetFuncDesc(pTI
, 2, &pFD
);
885 ok(hr
== S_OK
, "hr %08x\n", hr
);
886 ok(pFD
->memid
== 0x60010000, "memid %08x\n", pFD
->memid
);
887 ok(pFD
->oVft
== 2 * sizeof(void *), "oVft %d\n", pFD
->oVft
);
888 ITypeInfo_ReleaseFuncDesc(pTI
, pFD
);
890 ITypeInfo_Release(pTI
);
892 /* ItestIF11 is a syntax 2 dispinterface which derives from IDispatch */
893 hr
= ITypeLib_GetTypeInfoOfGuid(pTL
, &DIID_ItestIF11
, &pTI
);
894 ok(hr
== S_OK
, "hr %08x\n", hr
);
896 hr
= ITypeInfo_GetTypeAttr(pTI
, &pTA
);
897 ok(hr
== S_OK
, "hr %08x\n", hr
);
898 ok(pTA
->typekind
== TKIND_DISPATCH
, "kind %04x\n", pTA
->typekind
);
899 ok(pTA
->cbSizeVft
== 7 * sizeof(void *), "sizevft %d\n", pTA
->cbSizeVft
);
900 ok(pTA
->wTypeFlags
== TYPEFLAG_FDISPATCHABLE
, "typeflags %x\n", pTA
->wTypeFlags
);
902 ok(pTA
->cFuncs
== 10, "cfuncs %d\n", pTA
->cFuncs
);
903 ok(pTA
->cImplTypes
== 1, "cimpltypes %d\n", pTA
->cImplTypes
);
905 ITypeInfo_ReleaseTypeAttr(pTI
, pTA
);
908 hr
= ITypeInfo_GetRefTypeOfImplType(pTI
, 0, &href
);
909 ok(hr
== S_OK
, "hr %08x\n", hr
);
910 hr
= ITypeInfo_GetRefTypeInfo(pTI
, href
, &pTI_p
);
911 ok(hr
== S_OK
, "hr %08x\n", hr
);
912 hr
= ITypeInfo_GetTypeAttr(pTI_p
, &pTA
);
913 ok(IsEqualGUID(&pTA
->guid
, &IID_IDispatch
), "guid {%08x-....\n", pTA
->guid
.Data1
);
914 ITypeInfo_ReleaseTypeAttr(pTI_p
, pTA
);
915 ITypeInfo_Release(pTI_p
);
917 /* Should have ten methods */
918 hr
= ITypeInfo_GetFuncDesc(pTI
, 10, &pFD
);
919 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "hr %08x\n", hr
);
920 hr
= ITypeInfo_GetFuncDesc(pTI
, 9, &pFD
);
921 ok(hr
== S_OK
, "hr %08x\n", hr
);
922 ok(pFD
->memid
== 0x1236, "memid %08x\n", pFD
->memid
);
923 ok(pFD
->oVft
== 9 * sizeof(void *), "oVft %d\n", pFD
->oVft
);
925 /* first argument to 10th function is an HREFTYPE from the impl type */
926 ok(pFD
->cParams
== 1, "cParams %i\n", pFD
->cParams
);
927 ok(pFD
->lprgelemdescParam
[0].tdesc
.vt
== VT_USERDEFINED
,
928 "vt 0x%x\n", pFD
->lprgelemdescParam
[0].tdesc
.vt
);
929 href
= U(pFD
->lprgelemdescParam
[0].tdesc
).hreftype
;
930 ok((href
& 0xff000000) == 0x04000000, "href 0x%08x\n", href
);
931 hr
= ITypeInfo_GetRefTypeInfo(pTI
, href
, &pTI_p
);
932 ok(SUCCEEDED(hr
), "hr %08x\n", hr
);
933 if (SUCCEEDED(hr
)) ITypeInfo_Release(pTI_p
);
934 ITypeInfo_ReleaseFuncDesc(pTI
, pFD
);
936 ITypeInfo_Release(pTI
);
939 /* ItestIF2 is an interface which derives from IUnknown */
940 hr
= ITypeLib_GetTypeInfoOfGuid(pTL
, &IID_ItestIF2
, &pTI
);
941 ok(hr
== S_OK
, "hr %08x\n", hr
);
943 hr
= ITypeInfo_GetTypeAttr(pTI
, &pTA
);
944 ok(hr
== S_OK
, "hr %08x\n", hr
);
945 ok(pTA
->typekind
== TKIND_INTERFACE
, "kind %04x\n", pTA
->typekind
);
946 ok(pTA
->cbSizeVft
== 6 * sizeof(void *), "sizevft %d\n", pTA
->cbSizeVft
);
947 ok(pTA
->wTypeFlags
== 0, "typeflags %x\n", pTA
->wTypeFlags
);
949 ok(pTA
->cFuncs
== 1, "cfuncs %d\n", pTA
->cFuncs
);
950 ok(pTA
->cImplTypes
== 1, "cimpltypes %d\n", pTA
->cImplTypes
);
952 ITypeInfo_ReleaseTypeAttr(pTI
, pTA
);
955 /* Should have one method */
956 hr
= ITypeInfo_GetFuncDesc(pTI
, 1, &pFD
);
957 ok(hr
== TYPE_E_ELEMENTNOTFOUND
, "hr %08x\n", hr
);
958 hr
= ITypeInfo_GetFuncDesc(pTI
, 0, &pFD
);
959 ok(hr
== S_OK
, "hr %08x\n", hr
);
960 ok(pFD
->memid
== 0x60020000, "memid %08x\n", pFD
->memid
);
961 ok(pFD
->oVft
== 5 * sizeof(void *), "oVft %d\n", pFD
->oVft
);
962 ITypeInfo_ReleaseFuncDesc(pTI
, pFD
);
964 ITypeInfo_Release(pTI
);
966 ITypeLib_Release(pTL
);
971 static void test_CreateTypeLib(void) {
972 static const WCHAR stdoleW
[] = {'s','t','d','o','l','e','2','.','t','l','b',0};
973 static OLECHAR typelibW
[] = {'t','y','p','e','l','i','b',0};
974 static OLECHAR interface1W
[] = {'i','n','t','e','r','f','a','c','e','1',0};
975 static OLECHAR interface2W
[] = {'i','n','t','e','r','f','a','c','e','2',0};
976 static OLECHAR dualW
[] = {'d','u','a','l',0};
977 static OLECHAR coclassW
[] = {'c','o','c','l','a','s','s',0};
978 static WCHAR defaultW
[] = {'d','e','f','a','u','l','t',0x3213,0};
979 static OLECHAR func1W
[] = {'f','u','n','c','1',0};
980 static OLECHAR func2W
[] = {'f','u','n','c','2',0};
981 static OLECHAR param1W
[] = {'p','a','r','a','m','1',0};
982 static OLECHAR param2W
[] = {'p','a','r','a','m','2',0};
983 static OLECHAR
*names1
[] = {func1W
, param1W
, param2W
};
984 static OLECHAR
*names2
[] = {func2W
, param1W
, param2W
};
986 char filename
[MAX_PATH
];
987 WCHAR filenameW
[MAX_PATH
];
988 ICreateTypeLib2
*createtl
;
989 ICreateTypeInfo
*createti
;
990 ITypeLib
*tl
, *stdole
;
991 ITypeInfo
*interface1
, *interface2
, *unknown
, *dispatch
, *ti
;
993 ELEMDESC elemdesc
[5];
994 PARAMDESCEX paramdescex
;
995 TYPEDESC typedesc1
, typedesc2
;
999 BSTR name
, docstring
, helpfile
;
1004 trace("CreateTypeLib tests\n");
1006 hres
= LoadTypeLib(stdoleW
, &stdole
);
1007 ok(hres
== S_OK
, "got %08x\n", hres
);
1009 hres
= ITypeLib_GetTypeInfoOfGuid(stdole
, &IID_IUnknown
, &unknown
);
1010 ok(hres
== S_OK
, "got %08x\n", hres
);
1012 hres
= ITypeLib_GetTypeInfoOfGuid(stdole
, &IID_IDispatch
, &dispatch
);
1013 ok(hres
== S_OK
, "got %08x\n", hres
);
1015 GetTempFileNameA(".", "tlb", 0, filename
);
1016 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, filenameW
, MAX_PATH
);
1018 hres
= CreateTypeLib2(SYS_WIN32
, filenameW
, &createtl
);
1019 ok(hres
== S_OK
, "got %08x\n", hres
);
1021 hres
= ICreateTypeLib_QueryInterface(createtl
, &IID_ITypeLib
, (void**)&tl
);
1022 ok(hres
== S_OK
, "got %08x\n", hres
);
1024 hres
= ITypeLib_GetLibAttr(tl
, &libattr
);
1025 ok(hres
== S_OK
, "got %08x\n", hres
);
1027 ok(libattr
->syskind
== SYS_WIN32
, "syskind = %d\n", libattr
->syskind
);
1028 ok(libattr
->wMajorVerNum
== 0, "wMajorVer = %d\n", libattr
->wMajorVerNum
);
1029 ok(libattr
->wMinorVerNum
== 0, "wMinorVerNum = %d\n", libattr
->wMinorVerNum
);
1030 ok(libattr
->wLibFlags
== 0, "wLibFlags = %d\n", libattr
->wLibFlags
);
1032 ITypeLib_ReleaseTLibAttr(tl
, libattr
);
1034 name
= (BSTR
)0xdeadbeef;
1035 hres
= ITypeLib_GetDocumentation(tl
, -1, &name
, &docstring
, &helpcontext
, &helpfile
);
1036 ok(hres
== S_OK
, "got %08x\n", hres
);
1037 ok(name
== NULL
, "name != NULL\n");
1038 ok(docstring
== NULL
, "docstring != NULL\n");
1039 ok(helpcontext
== 0, "helpcontext != 0\n");
1040 ok(helpfile
== NULL
, "helpfile != NULL\n");
1042 hres
= ITypeLib_GetDocumentation(tl
, 0, &name
, NULL
, NULL
, NULL
);
1043 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1045 hres
= ICreateTypeLib_SetName(createtl
, typelibW
);
1046 ok(hres
== S_OK
, "got %08x\n", hres
);
1048 hres
= ITypeLib_GetDocumentation(tl
, -1, NULL
, NULL
, NULL
, NULL
);
1049 ok(hres
== S_OK
, "got %08x\n", hres
);
1051 hres
= ITypeLib_GetDocumentation(tl
, -1, &name
, NULL
, NULL
, NULL
);
1052 ok(hres
== S_OK
, "got %08x\n", hres
);
1053 ok(!memcmp(name
, typelibW
, sizeof(typelibW
)), "name = %s\n", wine_dbgstr_w(name
));
1055 SysFreeString(name
);
1057 ITypeLib_Release(tl
);
1059 hres
= ICreateTypeLib_CreateTypeInfo(createtl
, interface1W
, TKIND_INTERFACE
, &createti
);
1060 ok(hres
== S_OK
, "got %08x\n", hres
);
1062 hres
= ICreateTypeInfo_QueryInterface(createti
, &IID_ITypeInfo
, (void**)&interface1
);
1063 ok(hres
== S_OK
, "got %08x\n", hres
);
1065 hres
= ITypeInfo_GetRefTypeInfo(interface1
, 0, NULL
);
1066 ok(hres
== E_INVALIDARG
, "got %08x\n", hres
);
1068 hres
= ICreateTypeInfo_LayOut(createti
);
1069 ok(hres
== S_OK
, "got %08x\n", hres
);
1071 hres
= ICreateTypeInfo_AddRefTypeInfo(createti
, NULL
, &hreftype
);
1072 ok(hres
== E_INVALIDARG
, "got %08x\n", hres
);
1074 hres
= ICreateTypeInfo_AddRefTypeInfo(createti
, unknown
, NULL
);
1075 ok(hres
== E_INVALIDARG
, "got %08x\n", hres
);
1077 hres
= ICreateTypeInfo_AddRefTypeInfo(createti
, unknown
, &hreftype
);
1078 ok(hres
== S_OK
, "got %08x\n", hres
);
1080 hres
= ICreateTypeInfo_AddImplType(createti
, 1, hreftype
);
1081 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1083 hres
= ICreateTypeInfo_AddImplType(createti
, 0, hreftype
);
1084 ok(hres
== S_OK
, "got %08x\n", hres
);
1086 hres
= ITypeInfo_GetRefTypeOfImplType(interface1
, 0, &hreftype
);
1087 ok(hres
== S_OK
, "got %08x\n", hres
);
1088 ok(hreftype
== 3, "hreftype = %d\n", hreftype
);
1090 memset(&funcdesc
, 0, sizeof(FUNCDESC
));
1091 funcdesc
.funckind
= FUNC_PUREVIRTUAL
;
1092 funcdesc
.invkind
= INVOKE_PROPERTYGET
;
1093 funcdesc
.callconv
= CC_STDCALL
;
1094 funcdesc
.elemdescFunc
.tdesc
.vt
= VT_BSTR
;
1095 funcdesc
.elemdescFunc
.idldesc
.wIDLFlags
= IDLFLAG_NONE
;
1097 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 0, NULL
);
1098 ok(hres
== E_INVALIDARG
, "got %08x\n", hres
);
1100 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 1, &funcdesc
);
1101 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1103 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 0, &funcdesc
);
1104 ok(hres
== S_OK
, "got %08x\n", hres
);
1106 funcdesc
.invkind
= INVOKE_PROPERTYPUT
;
1107 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 1, &funcdesc
);
1108 ok(hres
== TYPE_E_INCONSISTENTPROPFUNCS
, "got %08x\n", hres
);
1110 funcdesc
.invkind
= INVOKE_PROPERTYPUTREF
;
1111 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 1, &funcdesc
);
1112 ok(hres
== TYPE_E_INCONSISTENTPROPFUNCS
, "got %08x\n", hres
);
1114 elemdesc
[0].tdesc
.vt
= VT_BSTR
;
1115 elemdesc
[0].idldesc
.dwReserved
= 0;
1116 elemdesc
[0].idldesc
.wIDLFlags
= IDLFLAG_FIN
;
1118 funcdesc
.lprgelemdescParam
= elemdesc
;
1119 funcdesc
.invkind
= INVOKE_PROPERTYPUT
;
1120 funcdesc
.cParams
= 1;
1121 funcdesc
.elemdescFunc
.tdesc
.vt
= VT_VOID
;
1123 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 1, &funcdesc
);
1124 ok(hres
== S_OK
, "got %08x\n", hres
);
1126 funcdesc
.invkind
= INVOKE_PROPERTYPUTREF
;
1127 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 0, &funcdesc
);
1128 ok(hres
== S_OK
, "got %08x\n", hres
);
1131 funcdesc
.lprgelemdescParam
= NULL
;
1132 funcdesc
.invkind
= INVOKE_FUNC
;
1133 funcdesc
.cParams
= 0;
1134 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 1, &funcdesc
);
1135 ok(hres
== S_OK
, "got %08x\n", hres
);
1137 funcdesc
.memid
= MEMBERID_NIL
;
1138 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 1, &funcdesc
);
1139 ok(hres
== S_OK
, "got %08x\n", hres
);
1141 elemdesc
[0].tdesc
.vt
= VT_PTR
;
1142 elemdesc
[0].tdesc
.lptdesc
= &typedesc1
;
1143 typedesc1
.vt
= VT_BSTR
;
1144 funcdesc
.cParams
= 1;
1145 funcdesc
.lprgelemdescParam
= elemdesc
;
1146 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 4, &funcdesc
);
1147 ok(hres
== S_OK
, "got %08x\n", hres
);
1149 elemdesc
[0].tdesc
.lptdesc
= &typedesc2
;
1150 typedesc2
.vt
= VT_PTR
;
1151 typedesc2
.lptdesc
= &typedesc1
;
1152 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 4, &funcdesc
);
1153 ok(hres
== S_OK
, "got %08x\n", hres
);
1155 elemdesc
[0].tdesc
.vt
= VT_INT
;
1156 elemdesc
[0].paramdesc
.wParamFlags
= PARAMFLAG_FHASDEFAULT
;
1157 elemdesc
[0].paramdesc
.pparamdescex
= ¶mdescex
;
1158 V_VT(¶mdescex
.varDefaultValue
) = VT_INT
;
1159 V_INT(¶mdescex
.varDefaultValue
) = 0x123;
1160 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 3, &funcdesc
);
1161 ok(hres
== S_OK
, "got %08x\n", hres
);
1163 elemdesc
[0].idldesc
.dwReserved
= 0;
1164 elemdesc
[0].idldesc
.wIDLFlags
= IDLFLAG_FIN
;
1165 elemdesc
[1].tdesc
.vt
= VT_UI2
;
1166 elemdesc
[1].paramdesc
.wParamFlags
= PARAMFLAG_FHASDEFAULT
;
1167 elemdesc
[1].paramdesc
.pparamdescex
= ¶mdescex
;
1168 V_VT(¶mdescex
.varDefaultValue
) = VT_UI2
;
1169 V_UI2(¶mdescex
.varDefaultValue
) = 0xffff;
1170 funcdesc
.cParams
= 2;
1171 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 3, &funcdesc
);
1172 ok(hres
== S_OK
, "got %08x\n", hres
);
1174 elemdesc
[0].paramdesc
.wParamFlags
= PARAMFLAG_FHASDEFAULT
;
1175 elemdesc
[0].paramdesc
.pparamdescex
= ¶mdescex
;
1176 elemdesc
[1].tdesc
.vt
= VT_INT
;
1177 V_VT(¶mdescex
.varDefaultValue
) = VT_INT
;
1178 V_INT(¶mdescex
.varDefaultValue
) = 0xffffffff;
1179 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 3, &funcdesc
);
1180 ok(hres
== S_OK
, "got %08x\n", hres
);
1182 elemdesc
[0].tdesc
.vt
= VT_BSTR
;
1183 elemdesc
[1].tdesc
.vt
= VT_BSTR
;
1184 V_VT(¶mdescex
.varDefaultValue
) = VT_BSTR
;
1185 V_BSTR(¶mdescex
.varDefaultValue
) = SysAllocString(defaultW
);
1186 hres
= ICreateTypeInfo_AddFuncDesc(createti
, 3, &funcdesc
);
1187 ok(hres
== S_OK
, "got %08x\n", hres
);
1189 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 1000, NULL
, 1);
1190 ok(hres
== E_INVALIDARG
, "got %08x\n", hres
);
1192 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 1000, names1
, 1);
1193 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1195 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 0, names1
, 2);
1196 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1198 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 0, names2
, 1);
1199 ok(hres
== S_OK
, "got %08x\n", hres
);
1201 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 0, names1
, 1);
1202 ok(hres
== S_OK
, "got %08x\n", hres
);
1204 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 3, names2
, 3);
1205 ok(hres
== S_OK
, "got %08x\n", hres
);
1207 hres
= ICreateTypeInfo_SetFuncAndParamNames(createti
, 3, names1
, 3);
1208 ok(hres
== TYPE_E_AMBIGUOUSNAME
, "got %08x\n", hres
);
1210 ICreateTypeInfo_Release(createti
);
1212 hres
= ICreateTypeLib_CreateTypeInfo(createtl
, interface1W
, TKIND_INTERFACE
, &createti
);
1213 ok(hres
== TYPE_E_NAMECONFLICT
, "got %08x\n", hres
);
1215 hres
= ICreateTypeLib_CreateTypeInfo(createtl
, interface2W
, TKIND_INTERFACE
, &createti
);
1216 ok(hres
== S_OK
, "got %08x\n", hres
);
1218 hres
= ICreateTypeInfo_QueryInterface(createti
, &IID_ITypeInfo
, (void**)&interface2
);
1219 ok(hres
== S_OK
, "got %08x\n", hres
);
1221 hres
= ITypeInfo_GetRefTypeOfImplType(interface2
, 0, &hreftype
);
1222 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1224 hres
= ICreateTypeInfo_AddRefTypeInfo(createti
, interface1
, &hreftype
);
1225 ok(hres
== S_OK
, "got %08x\n", hres
);
1227 hres
= ITypeInfo_GetRefTypeInfo(interface2
, 0, &ti
);
1228 ok(hres
== S_OK
, "got %08x\n", hres
);
1229 ok(ti
== interface1
, "Received and added interfaces are different\n");
1231 ITypeInfo_Release(ti
);
1233 hres
= ICreateTypeInfo_AddImplType(createti
, 0, hreftype
);
1234 ok(hres
== S_OK
, "got %08x\n", hres
);
1236 hres
= ITypeInfo_GetRefTypeOfImplType(interface2
, 0, &hreftype
);
1237 ok(hres
== S_OK
, "got %08x\n", hres
);
1238 ok(hreftype
== 2, "hreftype = %d\n", hreftype
);
1240 hres
= ICreateTypeInfo_SetImplTypeFlags(createti
, 0, IMPLTYPEFLAG_FDEFAULT
);
1241 ok(hres
== TYPE_E_BADMODULEKIND
, "got %08x\n", hres
);
1243 hres
= ITypeInfo_GetImplTypeFlags(interface2
, 0, &impltypeflags
);
1244 ok(hres
== S_OK
, "got %08x\n", hres
);
1245 ok(impltypeflags
== 0, "impltypeflags = %x\n", impltypeflags
);
1247 hres
= ITypeInfo_GetImplTypeFlags(interface2
, 1, &impltypeflags
);
1248 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1250 ICreateTypeInfo_Release(createti
);
1252 hres
= ICreateTypeLib_CreateTypeInfo(createtl
, coclassW
, TKIND_COCLASS
, &createti
);
1253 ok(hres
== S_OK
, "got %08x\n", hres
);
1255 hres
= ICreateTypeInfo_AddRefTypeInfo(createti
, interface1
, &hreftype
);
1256 ok(hres
== S_OK
, "got %08x\n", hres
);
1258 hres
= ICreateTypeInfo_AddImplType(createti
, 0, hreftype
);
1259 ok(hres
== S_OK
, "got %08x\n", hres
);
1261 hres
= ICreateTypeInfo_AddImplType(createti
, 0, hreftype
);
1262 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1264 hres
= ICreateTypeInfo_AddRefTypeInfo(createti
, unknown
, &hreftype
);
1265 ok(hres
== S_OK
, "got %08x\n", hres
);
1267 hres
= ICreateTypeInfo_AddImplType(createti
, 1, hreftype
);
1268 ok(hres
== S_OK
, "got %08x\n", hres
);
1270 hres
= ICreateTypeInfo_AddImplType(createti
, 1, hreftype
);
1271 ok(hres
== TYPE_E_ELEMENTNOTFOUND
, "got %08x\n", hres
);
1273 hres
= ICreateTypeInfo_AddImplType(createti
, 2, hreftype
);
1274 ok(hres
== S_OK
, "got %08x\n", hres
);
1276 hres
= ICreateTypeInfo_SetImplTypeFlags(createti
, 0, IMPLTYPEFLAG_FDEFAULT
);
1277 ok(hres
== S_OK
, "got %08x\n", hres
);
1279 hres
= ICreateTypeInfo_SetImplTypeFlags(createti
, 1, IMPLTYPEFLAG_FRESTRICTED
);
1280 ok(hres
== S_OK
, "got %08x\n", hres
);
1282 hres
= ICreateTypeInfo_QueryInterface(createti
, &IID_ITypeInfo
, (void**)&ti
);
1283 ok(hres
== S_OK
, "got %08x\n", hres
);
1285 hres
= ITypeInfo_GetImplTypeFlags(ti
, 0, NULL
);
1286 ok(hres
== E_INVALIDARG
, "got %08x\n", hres
);
1288 hres
= ITypeInfo_GetImplTypeFlags(ti
, 0, &impltypeflags
);
1289 ok(hres
== S_OK
, "got %08x\n", hres
);
1290 ok(impltypeflags
== IMPLTYPEFLAG_FDEFAULT
, "impltypeflags = %x\n", impltypeflags
);
1292 hres
= ITypeInfo_GetImplTypeFlags(ti
, 1, &impltypeflags
);
1293 ok(hres
== S_OK
, "got %08x\n", hres
);
1294 ok(impltypeflags
== IMPLTYPEFLAG_FRESTRICTED
, "impltypeflags = %x\n", impltypeflags
);
1296 hres
= ITypeInfo_GetImplTypeFlags(ti
, 2, &impltypeflags
);
1297 ok(hres
== S_OK
, "got %08x\n", hres
);
1298 ok(impltypeflags
== 0, "impltypeflags = %x\n", impltypeflags
);
1300 hres
= ITypeInfo_GetRefTypeOfImplType(ti
, 0, &hreftype
);
1301 ok(hres
== S_OK
, "got %08x\n", hres
);
1302 ok(hreftype
== 0, "hreftype = %d\n", hreftype
);
1304 hres
= ITypeInfo_GetRefTypeOfImplType(ti
, 1, &hreftype
);
1305 ok(hres
== S_OK
, "got %08x\n", hres
);
1306 ok(hreftype
== 1, "hreftype = %d\n", hreftype
);
1308 hres
= ITypeInfo_GetRefTypeOfImplType(ti
, 2, &hreftype
);
1309 ok(hres
== S_OK
, "got %08x\n", hres
);
1310 ok(hreftype
== 1, "hreftype = %d\n", hreftype
);
1312 ITypeInfo_Release(ti
);
1314 ICreateTypeInfo_Release(createti
);
1316 hres
= ICreateTypeLib_CreateTypeInfo(createtl
, dualW
, TKIND_INTERFACE
, &createti
);
1317 ok(hres
== S_OK
, "got %08x\n", hres
);
1319 hres
= ICreateTypeInfo_AddRefTypeInfo(createti
, dispatch
, &hreftype
);
1320 ok(hres
== S_OK
, "got %08x\n", hres
);
1322 hres
= ICreateTypeInfo_AddImplType(createti
, 0, hreftype
);
1323 ok(hres
== S_OK
, "got %08x\n", hres
);
1325 hres
= ICreateTypeInfo_QueryInterface(createti
, &IID_ITypeInfo
, (void**)&ti
);
1326 ok(hres
== S_OK
, "got %08x\n", hres
);
1328 hres
= ITypeInfo_GetTypeAttr(ti
, &typeattr
);
1329 ok(hres
== S_OK
, "got %08x\n", hres
);
1330 ok(typeattr
->cbSizeInstance
== 4, "cbSizeInstance = %d\n", typeattr
->cbSizeInstance
);
1331 ok(typeattr
->typekind
== 3, "typekind = %d\n", typeattr
->typekind
);
1332 ok(typeattr
->cFuncs
== 0, "cFuncs = %d\n", typeattr
->cFuncs
);
1333 ok(typeattr
->cVars
== 0, "cVars = %d\n", typeattr
->cVars
);
1334 ok(typeattr
->cImplTypes
== 1, "cImplTypes = %d\n", typeattr
->cImplTypes
);
1335 ok(typeattr
->cbSizeVft
== 28, "cbSizeVft = %d\n", typeattr
->cbSizeVft
);
1336 ok(typeattr
->cbAlignment
== 4, "cbAlignment = %d\n", typeattr
->cbAlignment
);
1337 ok(typeattr
->wTypeFlags
== TYPEFLAG_FDISPATCHABLE
, "wTypeFlags = %d\n", typeattr
->wTypeFlags
);
1338 ok(typeattr
->wMajorVerNum
== 0, "wMajorVerNum = %d\n", typeattr
->wMajorVerNum
);
1339 ok(typeattr
->wMinorVerNum
== 0, "wMinorVerNum = %d\n", typeattr
->wMinorVerNum
);
1341 ITypeInfo_ReleaseTypeAttr(ti
, typeattr
);
1343 ITypeInfo_Release(ti
);
1345 ICreateTypeInfo_Release(createti
);
1347 hres
= ITypeInfo_GetTypeAttr(interface1
, &typeattr
);
1348 ok(hres
== S_OK
, "got %08x\n", hres
);
1349 ok(typeattr
->cbSizeInstance
== 4, "cbSizeInstance = %d\n", typeattr
->cbSizeInstance
);
1350 ok(typeattr
->typekind
== 3, "typekind = %d\n", typeattr
->typekind
);
1351 ok(typeattr
->cFuncs
== 11, "cFuncs = %d\n", typeattr
->cFuncs
);
1352 ok(typeattr
->cVars
== 0, "cVars = %d\n", typeattr
->cVars
);
1353 ok(typeattr
->cImplTypes
== 1, "cImplTypes = %d\n", typeattr
->cImplTypes
);
1354 ok(typeattr
->cbSizeVft
== 56, "cbSizeVft = %d\n", typeattr
->cbSizeVft
);
1355 ok(typeattr
->cbAlignment
== 4, "cbAlignment = %d\n", typeattr
->cbAlignment
);
1356 ok(typeattr
->wTypeFlags
== 0, "wTypeFlags = %d\n", typeattr
->wTypeFlags
);
1357 ok(typeattr
->wMajorVerNum
== 0, "wMajorVerNum = %d\n", typeattr
->wMajorVerNum
);
1358 ok(typeattr
->wMinorVerNum
== 0, "wMinorVerNum = %d\n", typeattr
->wMinorVerNum
);
1360 ITypeInfo_ReleaseTypeAttr(interface1
, typeattr
);
1362 hres
= ITypeInfo_GetTypeAttr(interface2
, &typeattr
);
1363 ok(hres
== S_OK
, "got %08x\n", hres
);
1364 ok(typeattr
->cbSizeInstance
== 4, "cbSizeInstance = %d\n", typeattr
->cbSizeInstance
);
1365 ok(typeattr
->typekind
== 3, "typekind = %d\n", typeattr
->typekind
);
1366 ok(typeattr
->cFuncs
== 0, "cFuncs = %d\n", typeattr
->cFuncs
);
1367 ok(typeattr
->cVars
== 0, "cVars = %d\n", typeattr
->cVars
);
1368 ok(typeattr
->cImplTypes
== 1, "cImplTypes = %d\n", typeattr
->cImplTypes
);
1369 ok(typeattr
->cbSizeVft
== 56, "cbSizeVft = %d\n", typeattr
->cbSizeVft
);
1370 ok(typeattr
->cbAlignment
== 4, "cbAlignment = %d\n", typeattr
->cbAlignment
);
1371 ok(typeattr
->wTypeFlags
== 0, "wTypeFlags = %d\n", typeattr
->wTypeFlags
);
1372 ok(typeattr
->wMajorVerNum
== 0, "wMajorVerNum = %d\n", typeattr
->wMajorVerNum
);
1373 ok(typeattr
->wMinorVerNum
== 0, "wMinorVerNum = %d\n", typeattr
->wMinorVerNum
);
1375 ITypeInfo_ReleaseTypeAttr(interface2
, typeattr
);
1377 hres
= ICreateTypeLib2_SaveAllChanges(createtl
);
1378 ok(hres
== S_OK
, "got %08x\n", hres
);
1379 ICreateTypeLib2_Release(createtl
);
1381 hres
= LoadTypeLibEx(filenameW
, REGKIND_NONE
, &tl
);
1382 ok(hres
== S_OK
, "got %08x\n", hres
);
1384 ITypeInfo_Release(interface2
);
1385 ITypeInfo_Release(interface1
);
1386 ITypeInfo_Release(dispatch
);
1387 ITypeInfo_Release(unknown
);
1389 ITypeLib_Release(tl
);
1390 ITypeLib_Release(stdole
);
1392 DeleteFileA(filename
);
1395 #if 0 /* use this to generate more tests */
1397 #define OLE_CHECK(x) { HRESULT hr = x; if (FAILED(hr)) { printf(#x "failed - %x\n", hr); return; } }
1399 static char *dump_string(LPWSTR wstr
)
1401 int size
= lstrlenW(wstr
)+3;
1402 char *out
= CoTaskMemAlloc(size
);
1403 WideCharToMultiByte(20127, 0, wstr
, -1, out
+1, size
, NULL
, NULL
);
1415 #define MAP_ENTRY(x) { x, #x }
1416 static const struct map_entry tkind_map
[] = {
1417 MAP_ENTRY(TKIND_ENUM
),
1418 MAP_ENTRY(TKIND_RECORD
),
1419 MAP_ENTRY(TKIND_MODULE
),
1420 MAP_ENTRY(TKIND_INTERFACE
),
1421 MAP_ENTRY(TKIND_DISPATCH
),
1422 MAP_ENTRY(TKIND_COCLASS
),
1423 MAP_ENTRY(TKIND_ALIAS
),
1424 MAP_ENTRY(TKIND_UNION
),
1425 MAP_ENTRY(TKIND_MAX
),
1429 static const struct map_entry funckind_map
[] = {
1430 MAP_ENTRY(FUNC_VIRTUAL
),
1431 MAP_ENTRY(FUNC_PUREVIRTUAL
),
1432 MAP_ENTRY(FUNC_NONVIRTUAL
),
1433 MAP_ENTRY(FUNC_STATIC
),
1434 MAP_ENTRY(FUNC_DISPATCH
),
1438 static const struct map_entry invkind_map
[] = {
1439 MAP_ENTRY(INVOKE_FUNC
),
1440 MAP_ENTRY(INVOKE_PROPERTYGET
),
1441 MAP_ENTRY(INVOKE_PROPERTYPUT
),
1442 MAP_ENTRY(INVOKE_PROPERTYPUTREF
),
1448 static const char *map_value(DWORD val
, const struct map_entry
*map
)
1451 static char bufs
[16][256];
1456 if (map
->value
== val
)
1461 buf
= bufs
[(map_id
++)%16];
1462 sprintf(buf
, "0x%x", val
);
1466 static void test_dump_typelib(const char *name
)
1468 WCHAR wszString
[260];
1474 MultiByteToWideChar(CP_ACP
, 0, name
, -1, wszString
, 260);
1475 OLE_CHECK(LoadTypeLib(wszString
, &lib
));
1476 count
= ITypeLib_GetTypeInfoCount(lib
);
1477 printf("/* interfaces count: %d */\n", count
);
1478 for (i
= 0; i
< count
; i
++)
1484 OLE_CHECK(ITypeLib_GetDocumentation(lib
, i
, &name
, NULL
, NULL
, NULL
));
1486 " %s,\n", dump_string(name
));
1487 SysFreeString(name
);
1489 OLE_CHECK(ITypeLib_GetTypeInfo(lib
, i
, &info
));
1490 ITypeInfo_GetTypeAttr(info
, &attr
);
1491 printf(" /*kind*/ %s, /*flags*/ 0x%x, /*align*/ %d, /*size*/ %d,\n"
1492 " /*#vtbl*/ %d, /*#func*/ %d,\n"
1494 map_value(attr
->typekind
, tkind_map
), attr
->wTypeFlags
, attr
->cbAlignment
, attr
->cbSizeInstance
, attr
->cbSizeVft
,
1496 ITypeInfo_ReleaseTypeAttr(info
, attr
);
1504 if (FAILED(ITypeInfo_GetFuncDesc(info
, f
, &desc
)))
1507 " 0x%x, /*func*/ %s, /*inv*/ %s, /*call*/ 0x%x,\n",
1508 desc
->memid
, map_value(desc
->funckind
, funckind_map
), map_value(desc
->invkind
, invkind_map
),
1510 printf(" /*#param*/ %d, /*#opt*/ %d, /*vtbl*/ %d, /*#scodes*/ %d, /*flags*/ 0x%x,\n",
1511 desc
->cParams
, desc
->cParamsOpt
, desc
->oVft
, desc
->cScodes
, desc
->wFuncFlags
);
1512 printf(" {%d, %x}, /* ret */\n", desc
->elemdescFunc
.tdesc
.vt
, desc
->elemdescFunc
.paramdesc
.wParamFlags
);
1513 printf(" { /* params */\n");
1514 for (p
= 0; p
< desc
->cParams
; p
++)
1516 ELEMDESC e
= desc
->lprgelemdescParam
[p
];
1517 printf(" {%d, %x},\n", e
.tdesc
.vt
, e
.paramdesc
.wParamFlags
);
1519 printf(" {-1, -1}\n");
1521 printf(" { /* names */\n");
1522 OLE_CHECK(ITypeInfo_GetNames(info
, desc
->memid
, tab
, 256, &cNames
));
1523 for (p
= 0; p
< cNames
; p
++)
1525 printf(" %s,\n", dump_string(tab
[p
]));
1526 SysFreeString(tab
[p
]);
1531 ITypeInfo_ReleaseFuncDesc(info
, desc
);
1536 ITypeInfo_Release(info
);
1538 ITypeLib_Release(lib
);
1543 typedef struct _element_info
1549 typedef struct _function_info
1560 element_info ret_type
;
1561 element_info params
[15];
1565 typedef struct _interface_info
1571 USHORT cbSizeInstance
;
1574 function_info funcs
[20];
1577 static const interface_info info
[] = {
1578 /* interfaces count: 2 */
1581 /*kind*/ TKIND_DISPATCH
, /*flags*/ 0x1040, /*align*/ 4, /*size*/ 4,
1582 /*#vtbl*/ 7, /*#func*/ 8,
1585 0x60000000, /*func*/ FUNC_DISPATCH
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1586 /*#param*/ 2, /*#opt*/ 0, /*vtbl*/ 0, /*#scodes*/ 0, /*flags*/ 0x1,
1601 0x60000001, /*func*/ FUNC_DISPATCH
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1602 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 1, /*#scodes*/ 0, /*flags*/ 0x1,
1613 0x60000002, /*func*/ FUNC_DISPATCH
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1614 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 2, /*#scodes*/ 0, /*flags*/ 0x1,
1625 0x60010000, /*func*/ FUNC_DISPATCH
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1626 /*#param*/ 1, /*#opt*/ 0, /*vtbl*/ 3, /*#scodes*/ 0, /*flags*/ 0x1,
1639 0x60010001, /*func*/ FUNC_DISPATCH
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1640 /*#param*/ 3, /*#opt*/ 0, /*vtbl*/ 4, /*#scodes*/ 0, /*flags*/ 0x1,
1657 0x60010002, /*func*/ FUNC_DISPATCH
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1658 /*#param*/ 5, /*#opt*/ 0, /*vtbl*/ 5, /*#scodes*/ 0, /*flags*/ 0x1,
1679 0x60010003, /*func*/ FUNC_DISPATCH
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1680 /*#param*/ 8, /*#opt*/ 0, /*vtbl*/ 6, /*#scodes*/ 0, /*flags*/ 0x1,
1707 0x60020000, /*func*/ FUNC_DISPATCH
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1708 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 7, /*#scodes*/ 0, /*flags*/ 0x0,
1722 /*kind*/ TKIND_INTERFACE
, /*flags*/ 0x1000, /*align*/ 4, /*size*/ 4,
1723 /*#vtbl*/ 8, /*#func*/ 1,
1726 0x60020000, /*func*/ FUNC_PUREVIRTUAL
, /*inv*/ INVOKE_FUNC
, /*call*/ 0x4,
1727 /*#param*/ 0, /*#opt*/ 0, /*vtbl*/ 7, /*#scodes*/ 0, /*flags*/ 0x0,
1741 #define check_type(elem, info) { \
1742 expect_int((elem)->tdesc.vt, (info)->vt); \
1743 expect_hex(U(*(elem)).paramdesc.wParamFlags, (info)->wParamFlags); \
1746 static void test_dump_typelib(const char *name
)
1748 WCHAR wszName
[MAX_PATH
];
1750 int ifcount
= sizeof(info
)/sizeof(info
[0]);
1753 MultiByteToWideChar(CP_ACP
, 0, name
, -1, wszName
, MAX_PATH
);
1754 ole_check(LoadTypeLibEx(wszName
, REGKIND_NONE
, &typelib
));
1755 expect_eq(ITypeLib_GetTypeInfoCount(typelib
), ifcount
, UINT
, "%d");
1756 for (iface
= 0; iface
< ifcount
; iface
++)
1758 const interface_info
*if_info
= &info
[iface
];
1759 ITypeInfo
*typeinfo
;
1763 trace("Interface %s\n", if_info
->name
);
1764 ole_check(ITypeLib_GetTypeInfo(typelib
, iface
, &typeinfo
));
1765 ole_check(ITypeLib_GetDocumentation(typelib
, iface
, &bstrIfName
, NULL
, NULL
, NULL
));
1766 expect_wstr_acpval(bstrIfName
, if_info
->name
);
1767 SysFreeString(bstrIfName
);
1769 ole_check(ITypeInfo_GetTypeAttr(typeinfo
, &typeattr
));
1770 expect_int(typeattr
->typekind
, if_info
->type
);
1771 expect_hex(typeattr
->wTypeFlags
, if_info
->wTypeFlags
);
1772 expect_int(typeattr
->cbAlignment
, if_info
->cbAlignment
);
1773 expect_int(typeattr
->cbSizeInstance
, if_info
->cbSizeInstance
);
1774 expect_int(typeattr
->cbSizeVft
, if_info
->cbSizeVft
* sizeof(void*));
1775 expect_int(typeattr
->cFuncs
, if_info
->cFuncs
);
1777 for (func
= 0; func
< typeattr
->cFuncs
; func
++)
1779 function_info
*fn_info
= (function_info
*)&if_info
->funcs
[func
];
1785 trace("Function %s\n", fn_info
->names
[0]);
1786 ole_check(ITypeInfo_GetFuncDesc(typeinfo
, func
, &desc
));
1787 expect_int(desc
->memid
, fn_info
->memid
);
1788 expect_int(desc
->funckind
, fn_info
->funckind
);
1789 expect_int(desc
->invkind
, fn_info
->invkind
);
1790 expect_int(desc
->callconv
, fn_info
->callconv
);
1791 expect_int(desc
->cParams
, fn_info
->cParams
);
1792 expect_int(desc
->cParamsOpt
, fn_info
->cParamsOpt
);
1793 ok( desc
->oVft
== fn_info
->vtbl_index
* sizeof(void*) ||
1794 broken(desc
->oVft
== fn_info
->vtbl_index
* 4), /* xp64 */
1795 "desc->oVft got %u\n", desc
->oVft
);
1796 expect_int(desc
->cScodes
, fn_info
->cScodes
);
1797 expect_int(desc
->wFuncFlags
, fn_info
->wFuncFlags
);
1798 ole_check(ITypeInfo_GetNames(typeinfo
, desc
->memid
, namesTab
, 256, &cNames
));
1799 for (i
= 0; i
< cNames
; i
++)
1801 expect_wstr_acpval(namesTab
[i
], fn_info
->names
[i
]);
1802 SysFreeString(namesTab
[i
]);
1804 expect_null(fn_info
->names
[cNames
]);
1806 check_type(&desc
->elemdescFunc
, &fn_info
->ret_type
);
1807 for (i
= 0 ; i
< desc
->cParams
; i
++)
1809 check_type(&desc
->lprgelemdescParam
[i
], &fn_info
->params
[i
]);
1811 expect_int(fn_info
->params
[desc
->cParams
].vt
, (VARTYPE
)-1);
1813 ITypeInfo_ReleaseFuncDesc(typeinfo
, desc
);
1816 ITypeInfo_ReleaseTypeAttr(typeinfo
, typeattr
);
1817 ITypeInfo_Release(typeinfo
);
1819 ITypeLib_Release(typelib
);
1824 static const char *create_test_typelib(void)
1826 static char filename
[MAX_PATH
];
1832 GetTempFileNameA( ".", "tlb", 0, filename
);
1833 file
= CreateFile( filename
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0 );
1834 ok( file
!= INVALID_HANDLE_VALUE
, "file creation failed\n" );
1835 if (file
== INVALID_HANDLE_VALUE
) return NULL
;
1836 res
= FindResource( GetModuleHandle(0), MAKEINTRESOURCE(2), "TYPELIB" );
1837 ok( res
!= 0, "couldn't find resource\n" );
1838 ptr
= LockResource( LoadResource( GetModuleHandle(0), res
));
1839 WriteFile( file
, ptr
, SizeofResource( GetModuleHandle(0), res
), &written
, NULL
);
1840 ok( written
== SizeofResource( GetModuleHandle(0), res
), "couldn't write resource\n" );
1841 CloseHandle( file
);
1845 static void test_create_typelib_lcid(LCID lcid
)
1847 char filename
[MAX_PATH
];
1848 WCHAR name
[MAX_PATH
];
1850 ICreateTypeLib2
*tl
;
1852 DWORD msft_header
[5]; /* five is enough for now */
1855 GetTempFileNameA( ".", "tlb", 0, filename
);
1856 MultiByteToWideChar(CP_ACP
, 0, filename
, -1, name
, MAX_PATH
);
1858 hr
= CreateTypeLib2(SYS_WIN32
, name
, &tl
);
1859 ok(hr
== S_OK
, "got %08x\n", hr
);
1861 hr
= ICreateTypeLib2_SetLcid(tl
, lcid
);
1862 ok(hr
== S_OK
, "got %08x\n", hr
);
1864 hr
= ICreateTypeLib2_SaveAllChanges(tl
);
1865 ICreateTypeLib2_Release(tl
);
1867 file
= CreateFileA( filename
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, 0 );
1868 ok( file
!= INVALID_HANDLE_VALUE
, "file creation failed\n" );
1870 ReadFile( file
, msft_header
, sizeof(msft_header
), &read
, NULL
);
1871 ok(read
== sizeof(msft_header
), "read %d\n", read
);
1872 CloseHandle( file
);
1874 ok(msft_header
[0] == 0x5446534d, "got %08x\n", msft_header
[0]);
1875 ok(msft_header
[1] == 0x00010002, "got %08x\n", msft_header
[1]);
1876 ok(msft_header
[2] == 0xffffffff, "got %08x\n", msft_header
[2]);
1877 ok(msft_header
[3] == (lcid
? lcid
: 0x409), "got %08x (lcid %08x)\n", msft_header
[3], lcid
);
1878 ok(msft_header
[4] == lcid
, "got %08x (lcid %08x)\n", msft_header
[4], lcid
);
1880 DeleteFileA(filename
);
1883 static void test_create_typelibs(void)
1885 test_create_typelib_lcid(LOCALE_SYSTEM_DEFAULT
);
1886 test_create_typelib_lcid(LOCALE_USER_DEFAULT
);
1887 test_create_typelib_lcid(LOCALE_NEUTRAL
);
1889 test_create_typelib_lcid(0x009);
1890 test_create_typelib_lcid(0x409);
1891 test_create_typelib_lcid(0x809);
1893 test_create_typelib_lcid(0x007);
1894 test_create_typelib_lcid(0x407);
1899 const char *filename
;
1901 ref_count_test(wszStdOle2
);
1903 test_CreateDispTypeInfo();
1905 test_QueryPathOfRegTypeLib();
1907 test_CreateTypeLib();
1909 if ((filename
= create_test_typelib()))
1911 test_dump_typelib( filename
);
1912 DeleteFile( filename
);
1915 test_create_typelibs();