2 * Copyright (C) 2005-2006 Robert Shearman for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/test.h"
30 #include "tmarshal_dispids.h"
32 #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%08lx\n", (unsigned long int)hr)
34 /* ULL suffix is not portable */
35 #define ULL_CONST(dw1, dw2) ((((ULONGLONG)dw1) << 32) | (ULONGLONG)dw2)
37 const MYSTRUCT MYSTRUCT_BYVAL
= {0x12345678, ULL_CONST(0xdeadbeef, 0x98765432)};
38 const MYSTRUCT MYSTRUCT_BYPTR
= {0x91827364, ULL_CONST(0x88776655, 0x44332211)};
39 const MYSTRUCT MYSTRUCT_ARRAY
[5] = {
40 {0x1a1b1c1d, ULL_CONST(0x1e1f1011, 0x12131415)},
41 {0x2a2b2c2d, ULL_CONST(0x2e2f2021, 0x22232425)},
42 {0x3a3b3c3d, ULL_CONST(0x3e3f3031, 0x32333435)},
43 {0x4a4b4c4d, ULL_CONST(0x4e4f4041, 0x42434445)},
44 {0x5a5b5c5d, ULL_CONST(0x5e5f5051, 0x52535455)},
48 #define RELEASEMARSHALDATA WM_USER
50 struct host_object_data
55 MSHLFLAGS marshal_flags
;
57 IMessageFilter
*filter
;
60 static DWORD CALLBACK
host_object_proc(LPVOID p
)
62 struct host_object_data
*data
= p
;
66 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
70 IMessageFilter
* prev_filter
= NULL
;
71 hr
= CoRegisterMessageFilter(data
->filter
, &prev_filter
);
72 if (prev_filter
) IMessageFilter_Release(prev_filter
);
73 ok_ole_success(hr
, CoRegisterMessageFilter
);
76 hr
= CoMarshalInterface(data
->stream
, &data
->iid
, data
->object
, MSHCTX_INPROC
, NULL
, data
->marshal_flags
);
77 ok_ole_success(hr
, CoMarshalInterface
);
79 /* force the message queue to be created before signaling parent thread */
80 PeekMessage(&msg
, NULL
, WM_USER
, WM_USER
, PM_NOREMOVE
);
82 SetEvent(data
->marshal_event
);
84 while (GetMessage(&msg
, NULL
, 0, 0))
86 if (msg
.hwnd
== NULL
&& msg
.message
== RELEASEMARSHALDATA
)
88 trace("releasing marshal data\n");
89 CoReleaseMarshalData(data
->stream
);
90 SetEvent((HANDLE
)msg
.lParam
);
93 DispatchMessage(&msg
);
96 HeapFree(GetProcessHeap(), 0, data
);
103 static DWORD
start_host_object2(IStream
*stream
, REFIID riid
, IUnknown
*object
, MSHLFLAGS marshal_flags
, IMessageFilter
*filter
, HANDLE
*thread
)
106 HANDLE marshal_event
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
107 struct host_object_data
*data
= HeapAlloc(GetProcessHeap(), 0, sizeof(*data
));
109 data
->stream
= stream
;
111 data
->object
= object
;
112 data
->marshal_flags
= marshal_flags
;
113 data
->marshal_event
= marshal_event
;
114 data
->filter
= filter
;
116 *thread
= CreateThread(NULL
, 0, host_object_proc
, data
, 0, &tid
);
118 /* wait for marshaling to complete before returning */
119 WaitForSingleObject(marshal_event
, INFINITE
);
120 CloseHandle(marshal_event
);
125 static DWORD
start_host_object(IStream
*stream
, REFIID riid
, IUnknown
*object
, MSHLFLAGS marshal_flags
, HANDLE
*thread
)
127 return start_host_object2(stream
, riid
, object
, marshal_flags
, NULL
, thread
);
131 /* asks thread to release the marshal data because it has to be done by the
132 * same thread that marshaled the interface in the first place. */
133 static void release_host_object(DWORD tid
)
135 HANDLE event
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
136 PostThreadMessage(tid
, RELEASEMARSHALDATA
, 0, (LPARAM
)event
);
137 WaitForSingleObject(event
, INFINITE
);
142 static void end_host_object(DWORD tid
, HANDLE thread
)
144 BOOL ret
= PostThreadMessage(tid
, WM_QUIT
, 0, 0);
145 ok(ret
, "PostThreadMessage failed with error %d\n", GetLastError());
146 /* be careful of races - don't return until hosting thread has terminated */
147 WaitForSingleObject(thread
, INFINITE
);
151 static ItestDual TestDual
, TestDualDisp
;
153 static HRESULT WINAPI
TestDual_QueryInterface(ItestDual
*iface
, REFIID riid
, void **ppvObject
)
155 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDispatch
)) {
156 *ppvObject
= &TestDualDisp
;
158 }else if(IsEqualGUID(riid
, &IID_ItestDual
)) {
159 *ppvObject
= &TestDual
;
164 return E_NOINTERFACE
;
167 static ULONG WINAPI
TestDual_AddRef(ItestDual
*iface
)
172 static ULONG WINAPI
TestDual_Release(ItestDual
*iface
)
177 static HRESULT WINAPI
TestDual_GetTypeInfoCount(ItestDual
*iface
, UINT
*pctinfo
)
179 ok(0, "unexpected call\n");
183 static HRESULT WINAPI
TestDual_GetTypeInfo(ItestDual
*iface
, UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
185 ok(0, "unexpected call\n");
189 static HRESULT WINAPI
TestDual_GetIDsOfNames(ItestDual
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
190 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
192 ok(0, "unexpected call\n");
196 static HRESULT WINAPI
TestDual_Invoke(ItestDual
*iface
, DISPID dispIdMember
, REFIID riid
, LCID lcid
,
197 WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
,
200 ok(0, "unexpected call\n");
204 static ItestDualVtbl TestDualVtbl
= {
205 TestDual_QueryInterface
,
208 TestDual_GetTypeInfoCount
,
209 TestDual_GetTypeInfo
,
210 TestDual_GetIDsOfNames
,
214 static ItestDual TestDual
= { &TestDualVtbl
};
215 static ItestDual TestDualDisp
= { &TestDualVtbl
};
217 typedef struct Widget
219 const IWidgetVtbl
*lpVtbl
;
221 IUnknown
*pDispatchUnknown
;
224 static HRESULT WINAPI
Widget_QueryInterface(
226 /* [in] */ REFIID riid
,
227 /* [iid_is][out] */ void __RPC_FAR
*__RPC_FAR
*ppvObject
)
229 if (IsEqualIID(riid
, &IID_IWidget
) || IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDispatch
))
231 IWidget_AddRef(iface
);
238 return E_NOINTERFACE
;
242 static ULONG WINAPI
Widget_AddRef(
245 Widget
*This
= (Widget
*)iface
;
247 return InterlockedIncrement(&This
->refs
);
250 static ULONG WINAPI
Widget_Release(
253 Widget
*This
= (Widget
*)iface
;
254 ULONG refs
= InterlockedDecrement(&This
->refs
);
257 IUnknown_Release(This
->pDispatchUnknown
);
258 memset(This
, 0xcc, sizeof(*This
));
259 HeapFree(GetProcessHeap(), 0, This
);
260 trace("Widget destroyed!\n");
266 static HRESULT WINAPI
Widget_GetTypeInfoCount(
268 /* [out] */ UINT __RPC_FAR
*pctinfo
)
270 Widget
*This
= (Widget
*)iface
;
271 IDispatch
*pDispatch
;
272 HRESULT hr
= IUnknown_QueryInterface(This
->pDispatchUnknown
, &IID_IDispatch
, (void **)&pDispatch
);
275 hr
= IDispatch_GetTypeInfoCount(pDispatch
, pctinfo
);
276 IDispatch_Release(pDispatch
);
281 static HRESULT WINAPI
Widget_GetTypeInfo(
282 IWidget __RPC_FAR
* iface
,
283 /* [in] */ UINT iTInfo
,
284 /* [in] */ LCID lcid
,
285 /* [out] */ ITypeInfo __RPC_FAR
*__RPC_FAR
*ppTInfo
)
287 Widget
*This
= (Widget
*)iface
;
288 IDispatch
*pDispatch
;
289 HRESULT hr
= IUnknown_QueryInterface(This
->pDispatchUnknown
, &IID_IDispatch
, (void **)&pDispatch
);
292 hr
= IDispatch_GetTypeInfo(pDispatch
, iTInfo
, lcid
, ppTInfo
);
293 IDispatch_Release(pDispatch
);
298 static HRESULT WINAPI
Widget_GetIDsOfNames(
299 IWidget __RPC_FAR
* iface
,
300 /* [in] */ REFIID riid
,
301 /* [size_is][in] */ LPOLESTR __RPC_FAR
*rgszNames
,
302 /* [in] */ UINT cNames
,
303 /* [in] */ LCID lcid
,
304 /* [size_is][out] */ DISPID __RPC_FAR
*rgDispId
)
306 Widget
*This
= (Widget
*)iface
;
307 IDispatch
*pDispatch
;
308 HRESULT hr
= IUnknown_QueryInterface(This
->pDispatchUnknown
, &IID_IDispatch
, (void **)&pDispatch
);
311 hr
= IDispatch_GetIDsOfNames(pDispatch
, riid
, rgszNames
, cNames
, lcid
, rgDispId
);
312 IDispatch_Release(pDispatch
);
317 static HRESULT WINAPI
Widget_Invoke(
318 IWidget __RPC_FAR
* iface
,
319 /* [in] */ DISPID dispIdMember
,
320 /* [in] */ REFIID riid
,
321 /* [in] */ LCID lcid
,
322 /* [in] */ WORD wFlags
,
323 /* [out][in] */ DISPPARAMS __RPC_FAR
*pDispParams
,
324 /* [out] */ VARIANT __RPC_FAR
*pVarResult
,
325 /* [out] */ EXCEPINFO __RPC_FAR
*pExcepInfo
,
326 /* [out] */ UINT __RPC_FAR
*puArgErr
)
328 Widget
*This
= (Widget
*)iface
;
329 IDispatch
*pDispatch
;
330 HRESULT hr
= IUnknown_QueryInterface(This
->pDispatchUnknown
, &IID_IDispatch
, (void **)&pDispatch
);
333 hr
= IDispatch_Invoke(pDispatch
, dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
334 IDispatch_Release(pDispatch
);
339 static HRESULT WINAPI
Widget_put_Name(
340 IWidget __RPC_FAR
* iface
,
341 /* [in] */ BSTR name
)
343 trace("put_Name(%s)\n", wine_dbgstr_w(name
));
347 static HRESULT WINAPI
Widget_get_Name(
348 IWidget __RPC_FAR
* iface
,
349 /* [out] */ BSTR __RPC_FAR
*name
)
351 static const WCHAR szCat
[] = { 'C','a','t',0 };
352 trace("get_Name()\n");
353 *name
= SysAllocString(szCat
);
357 static HRESULT WINAPI
Widget_DoSomething(
358 IWidget __RPC_FAR
* iface
,
359 /* [in] */ double number
,
360 /* [out] */ BSTR
*str1
,
361 /* [defaultvalue][in] */ BSTR str2
,
362 /* [optional][in] */ VARIANT __RPC_FAR
*opt
)
364 static const WCHAR szString
[] = { 'S','t','r','i','n','g',0 };
365 trace("DoSomething()\n");
367 ok(number
== 3.141, "number(%f) != 3.141\n", number
);
368 ok(*str2
== '\0', "str2(%s) != \"\"\n", wine_dbgstr_w(str2
));
369 ok(V_VT(opt
) == VT_ERROR
, "V_VT(opt) should be VT_ERROR instead of 0x%x\n", V_VT(opt
));
370 ok(V_ERROR(opt
) == DISP_E_PARAMNOTFOUND
, "V_ERROR(opt) should be DISP_E_PARAMNOTFOUND instead of 0x%08x\n", V_ERROR(opt
));
371 *str1
= SysAllocString(szString
);
376 static HRESULT WINAPI
Widget_get_State(
377 IWidget __RPC_FAR
* iface
,
378 /* [retval][out] */ STATE __RPC_FAR
*state
)
380 trace("get_State() = STATE_WIDGETIFIED\n");
381 *state
= STATE_WIDGETIFIED
;
385 static HRESULT WINAPI
Widget_put_State(
386 IWidget __RPC_FAR
* iface
,
387 /* [in] */ STATE state
)
389 trace("put_State(%d)\n", state
);
393 static HRESULT WINAPI
Widget_Map(
398 trace("Map(%s, %p)\n", wine_dbgstr_w(bstrId
), sValue
);
399 *sValue
= SysAllocString(bstrId
);
403 static HRESULT WINAPI
Widget_SetOleColor(
407 trace("SetOleColor(0x%x)\n", val
);
411 static HRESULT WINAPI
Widget_GetOleColor(
415 trace("GetOleColor() = 0x8000000f\n");
420 static HRESULT WINAPI
Widget_Clone(
425 return Widget_QueryInterface(iface
, &IID_IWidget
, (void **)ppVal
);
428 static HRESULT WINAPI
Widget_CloneDispatch(
432 trace("CloneDispatch()\n");
433 return Widget_QueryInterface(iface
, &IID_IWidget
, (void **)ppVal
);
436 static HRESULT WINAPI
Widget_CloneCoclass(
438 ApplicationObject2
**ppVal
)
440 trace("CloneCoclass()\n");
444 static HRESULT WINAPI
Widget_Value(
445 IWidget __RPC_FAR
* iface
,
449 trace("Value(%p, %p)\n", value
, retval
);
450 ok(V_VT(value
) == VT_I2
, "V_VT(value) was %d instead of VT_I2\n", V_VT(value
));
451 ok(V_I2(value
) == 1, "V_I2(value) was %d instead of 1\n", V_I2(value
));
452 V_VT(retval
) = VT_I2
;
457 static HRESULT WINAPI
Widget_Array(
461 trace("Array(%p)\n", values
);
465 static HRESULT WINAPI
Widget_VariantArrayPtr(
469 trace("VariantArrayPtr(%p)\n", values
);
473 static HRESULT WINAPI
Widget_Variant(
474 IWidget __RPC_FAR
* iface
,
477 trace("Variant()\n");
478 ok(V_VT(&var
) == VT_CY
, "V_VT(&var) was %d\n", V_VT(&var
));
479 ok(S(V_CY(&var
)).Hi
== 0xdababe, "V_CY(&var).Hi was 0x%x\n", S(V_CY(&var
)).Hi
);
480 ok(S(V_CY(&var
)).Lo
== 0xdeadbeef, "V_CY(&var).Lo was 0x%x\n", S(V_CY(&var
)).Lo
);
484 static HRESULT WINAPI
Widget_VarArg(
489 LONG lbound
, ubound
, i
;
493 trace("VarArg(%p)\n", values
);
495 hr
= SafeArrayGetLBound(values
, 1, &lbound
);
496 ok(hr
== S_OK
, "SafeArrayGetLBound failed with %x\n", hr
);
497 ok(lbound
== 0, "SafeArrayGetLBound returned %d\n", lbound
);
499 hr
= SafeArrayGetUBound(values
, 1, &ubound
);
500 ok(hr
== S_OK
, "SafeArrayGetUBound failed with %x\n", hr
);
501 ok(ubound
== numexpect
-1, "SafeArrayGetUBound returned %d, but expected %d\n", ubound
, numexpect
-1);
503 hr
= SafeArrayAccessData(values
, (LPVOID
)&data
);
504 ok(hr
== S_OK
, "SafeArrayAccessData failed with %x\n", hr
);
506 for (i
=0; i
<=ubound
-lbound
; i
++)
508 ok(V_VT(&data
[i
]) == VT_I4
, "V_VT(&data[%d]) was %d\n", i
, V_VT(&data
[i
]));
509 ok(V_I4(&data
[i
]) == i
, "V_I4(&data[%d]) was %d\n", i
, V_I4(&data
[i
]));
512 hr
= SafeArrayUnaccessData(values
);
513 ok(hr
== S_OK
, "SafeArrayUnaccessData failed with %x\n", hr
);
518 static HRESULT WINAPI
Widget_StructArgs(
525 ok(byval
.field1
== MYSTRUCT_BYVAL
.field1
&&
526 byval
.field2
== MYSTRUCT_BYVAL
.field2
,
527 "Struct parameter passed by value corrupted\n");
528 ok(byptr
->field1
== MYSTRUCT_BYPTR
.field1
&&
529 byptr
->field2
== MYSTRUCT_BYPTR
.field2
,
530 "Struct parameter passed by pointer corrupted\n");
531 for (i
= 0; i
< 5; i
++)
532 if (arr
[i
].field1
!= MYSTRUCT_ARRAY
[i
].field1
||
533 arr
[i
].field2
!= MYSTRUCT_ARRAY
[i
].field2
)
535 ok(diff
== 0, "Array of structs corrupted\n");
540 static HRESULT WINAPI
Widget_Error(
541 IWidget __RPC_FAR
* iface
)
547 static HRESULT WINAPI
Widget_CloneInterface(
548 IWidget __RPC_FAR
* iface
,
549 ISomethingFromDispatch
**ppVal
)
551 trace("CloneInterface()\n");
556 static HRESULT WINAPI
Widget_put_prop_with_lcid(
557 IWidget
* iface
, LONG lcid
, INT i
)
559 trace("put_prop_with_lcid(%08x, %x)\n", lcid
, i
);
560 ok(lcid
== MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), "got lcid %08x\n", lcid
);
561 ok(i
== 0xcafe, "got %08x\n", i
);
565 static HRESULT WINAPI
Widget_get_prop_with_lcid(
566 IWidget
* iface
, LONG lcid
, INT
*i
)
568 trace("get_prop_with_lcid(%08x, %p)\n", lcid
, i
);
569 ok(lcid
== MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), "got lcid %08x\n", lcid
);
574 static HRESULT WINAPI
Widget_get_prop_int(
575 IWidget
* iface
, INT
*i
)
577 trace("get_prop_int(%p)\n", i
);
582 static HRESULT WINAPI
Widget_get_prop_uint(
583 IWidget
* iface
, UINT
*i
)
585 trace("get_prop_uint(%p)\n", i
);
590 static HRESULT WINAPI
Widget_ByRefUInt(
591 IWidget
* iface
, UINT
*i
)
597 static const struct IWidgetVtbl Widget_VTable
=
599 Widget_QueryInterface
,
602 Widget_GetTypeInfoCount
,
604 Widget_GetIDsOfNames
,
615 Widget_CloneDispatch
,
619 Widget_VariantArrayPtr
,
624 Widget_CloneInterface
,
625 Widget_put_prop_with_lcid
,
626 Widget_get_prop_with_lcid
,
628 Widget_get_prop_uint
,
632 static HRESULT WINAPI
StaticWidget_QueryInterface(IStaticWidget
*iface
, REFIID riid
, void **ppvObject
)
634 if (IsEqualIID(riid
, &IID_IStaticWidget
) || IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDispatch
))
636 IStaticWidget_AddRef(iface
);
642 return E_NOINTERFACE
;
645 static ULONG WINAPI
StaticWidget_AddRef(IStaticWidget
*iface
)
650 static ULONG WINAPI
StaticWidget_Release(IStaticWidget
*iface
)
655 static HRESULT WINAPI
StaticWidget_GetTypeInfoCount(IStaticWidget
*iface
, UINT
*pctinfo
)
657 ok(0, "unexpected call\n");
661 static HRESULT WINAPI
StaticWidget_GetTypeInfo(IStaticWidget
*iface
, UINT iTInfo
, LCID lcid
,
664 ok(0, "unexpected call\n");
668 static HRESULT WINAPI
StaticWidget_GetIDsOfNames(IStaticWidget
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
669 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
671 ok(0, "unexpected call\n");
675 static HRESULT WINAPI
StaticWidget_Invoke(IStaticWidget
*iface
, DISPID dispIdMember
, REFIID riid
,
676 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
,
679 ok(0, "unexpected call\n");
683 static HRESULT WINAPI
StaticWidget_TestDual(IStaticWidget
*iface
, ItestDual
*p
)
685 trace("TestDual()\n");
687 ok(p
== &TestDual
, "wrong ItestDual\n");
691 static const IStaticWidgetVtbl StaticWidgetVtbl
= {
692 StaticWidget_QueryInterface
,
694 StaticWidget_Release
,
695 StaticWidget_GetTypeInfoCount
,
696 StaticWidget_GetTypeInfo
,
697 StaticWidget_GetIDsOfNames
,
699 StaticWidget_TestDual
702 static IStaticWidget StaticWidget
= { &StaticWidgetVtbl
};
704 typedef struct KindaEnum
706 const IKindaEnumWidgetVtbl
*lpVtbl
;
710 static HRESULT
register_current_module_typelib(void)
712 WCHAR path
[MAX_PATH
];
713 CHAR pathA
[MAX_PATH
];
717 GetModuleFileNameA(NULL
, pathA
, MAX_PATH
);
718 MultiByteToWideChar(CP_ACP
, 0, pathA
, -1, path
, MAX_PATH
);
720 hr
= LoadTypeLib(path
, &typelib
);
723 hr
= RegisterTypeLib(typelib
, path
, NULL
);
724 ITypeLib_Release(typelib
);
729 static ITypeInfo
*get_type_info(REFIID riid
)
731 ITypeInfo
*pTypeInfo
;
735 hr
= LoadRegTypeLib(&LIBID_TestTypelib
, 1, 0, LOCALE_NEUTRAL
, &pTypeLib
);
736 ok_ole_success(hr
, LoadRegTypeLib
);
740 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, riid
, &pTypeInfo
);
741 ITypeLib_Release(pTypeLib
);
742 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
749 static IWidget
*Widget_Create(void)
752 ITypeInfo
*pTypeInfo
;
755 pTypeInfo
= get_type_info(&IID_IWidget
);
759 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
760 This
->lpVtbl
= &Widget_VTable
;
762 This
->pDispatchUnknown
= NULL
;
764 hr
= CreateStdDispatch((IUnknown
*)&This
->lpVtbl
, This
, pTypeInfo
, &This
->pDispatchUnknown
);
765 ok_ole_success(hr
, CreateStdDispatch
);
766 ITypeInfo_Release(pTypeInfo
);
769 return (IWidget
*)&This
->lpVtbl
;
772 HeapFree(GetProcessHeap(), 0, This
);
777 static HRESULT WINAPI
KindaEnum_QueryInterface(
778 IKindaEnumWidget
*iface
,
779 /* [in] */ REFIID riid
,
780 /* [iid_is][out] */ void __RPC_FAR
*__RPC_FAR
*ppvObject
)
782 if (IsEqualIID(riid
, &IID_IKindaEnumWidget
) || IsEqualIID(riid
, &IID_IUnknown
))
784 IKindaEnumWidget_AddRef(iface
);
791 return E_NOINTERFACE
;
795 static ULONG WINAPI
KindaEnum_AddRef(
796 IKindaEnumWidget
*iface
)
798 KindaEnum
*This
= (KindaEnum
*)iface
;
800 return InterlockedIncrement(&This
->refs
);
803 static ULONG WINAPI
KindaEnum_Release(
804 IKindaEnumWidget
*iface
)
806 KindaEnum
*This
= (KindaEnum
*)iface
;
807 ULONG refs
= InterlockedDecrement(&This
->refs
);
810 memset(This
, 0xcc, sizeof(*This
));
811 HeapFree(GetProcessHeap(), 0, This
);
812 trace("KindaEnumWidget destroyed!\n");
818 static HRESULT WINAPI
KindaEnum_Next(
819 IKindaEnumWidget
*iface
,
820 /* [out] */ IWidget __RPC_FAR
*__RPC_FAR
*widget
)
822 *widget
= Widget_Create();
826 return E_OUTOFMEMORY
;
829 static HRESULT WINAPI
KindaEnum_Count(
830 IKindaEnumWidget
*iface
,
831 /* [out] */ ULONG __RPC_FAR
*count
)
836 static HRESULT WINAPI
KindaEnum_Reset(
837 IKindaEnumWidget
*iface
)
842 static HRESULT WINAPI
KindaEnum_Clone(
843 IKindaEnumWidget
*iface
,
844 /* [out] */ IKindaEnumWidget __RPC_FAR
*__RPC_FAR
*ppenum
)
849 static const IKindaEnumWidgetVtbl KindaEnumWidget_VTable
=
851 KindaEnum_QueryInterface
,
860 static IKindaEnumWidget
*KindaEnumWidget_Create(void)
864 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
865 if (!This
) return NULL
;
866 This
->lpVtbl
= &KindaEnumWidget_VTable
;
868 return (IKindaEnumWidget
*)This
;
871 static HRESULT WINAPI
NonOleAutomation_QueryInterface(INonOleAutomation
*iface
, REFIID riid
, void **ppv
)
873 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_INonOleAutomation
))
875 *(INonOleAutomation
**)ppv
= iface
;
879 return E_NOINTERFACE
;
882 static ULONG WINAPI
NonOleAutomation_AddRef(INonOleAutomation
*iface
)
887 static ULONG WINAPI
NonOleAutomation_Release(INonOleAutomation
*iface
)
892 static BSTR WINAPI
NonOleAutomation_BstrRet(INonOleAutomation
*iface
)
894 static const WCHAR wszTestString
[] = {'T','h','i','s',' ','i','s',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0};
895 return SysAllocString(wszTestString
);
898 static INonOleAutomationVtbl NonOleAutomation_VTable
=
900 NonOleAutomation_QueryInterface
,
901 NonOleAutomation_AddRef
,
902 NonOleAutomation_Release
,
903 NonOleAutomation_BstrRet
,
906 static INonOleAutomation NonOleAutomation
= { &NonOleAutomation_VTable
};
908 static ITypeInfo
*NonOleAutomation_GetTypeInfo(void)
911 HRESULT hr
= LoadRegTypeLib(&LIBID_TestTypelib
, 1, 0, LOCALE_NEUTRAL
, &pTypeLib
);
912 ok_ole_success(hr
, LoadRegTypeLib
);
915 ITypeInfo
*pTypeInfo
;
916 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, &IID_INonOleAutomation
, &pTypeInfo
);
917 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
918 ITypeLib_Release(pTypeLib
);
924 static void test_typelibmarshal(void)
926 static const WCHAR szCat
[] = { 'C','a','t',0 };
927 static const WCHAR szTestTest
[] = { 'T','e','s','t','T','e','s','t',0 };
928 static WCHAR szSuperman
[] = { 'S','u','p','e','r','m','a','n',0 };
930 IKindaEnumWidget
*pKEW
= KindaEnumWidget_Create();
933 IDispatch
*pDispatch
;
934 static const LARGE_INTEGER ullZero
;
937 DISPID dispidNamed
= DISPID_PROPERTYPUT
;
938 DISPPARAMS dispparams
;
939 VARIANTARG vararg
[4];
944 ITypeInfo
*pTypeInfo
;
946 MYSTRUCT mystructArray
[5];
949 ok(pKEW
!= NULL
, "Widget creation failed\n");
951 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
952 ok_ole_success(hr
, CreateStreamOnHGlobal
);
953 tid
= start_host_object(pStream
, &IID_IKindaEnumWidget
, (IUnknown
*)pKEW
, MSHLFLAGS_NORMAL
, &thread
);
954 IKindaEnumWidget_Release(pKEW
);
956 IStream_Seek(pStream
, ullZero
, STREAM_SEEK_SET
, NULL
);
957 hr
= CoUnmarshalInterface(pStream
, &IID_IKindaEnumWidget
, (void **)&pKEW
);
958 ok_ole_success(hr
, CoUnmarshalInterface
);
959 IStream_Release(pStream
);
961 hr
= IKindaEnumWidget_Next(pKEW
, &pWidget
);
962 ok_ole_success(hr
, IKindaEnumWidget_Next
);
964 IKindaEnumWidget_Release(pKEW
);
966 hr
= IWidget_QueryInterface(pWidget
, &IID_IDispatch
, (void **)&pDispatch
);
969 VariantInit(&vararg
[0]);
970 dispparams
.cNamedArgs
= 1;
971 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
972 dispparams
.cArgs
= 1;
973 dispparams
.rgvarg
= vararg
;
974 VariantInit(&varresult
);
975 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
976 ok_ole_success(hr
, IDispatch_Invoke
);
977 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
978 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
979 excepinfo
.wCode
, excepinfo
.scode
);
980 VariantClear(&varresult
);
982 /* call put_Name (direct) */
983 bstr
= SysAllocString(szSuperman
);
984 hr
= IWidget_put_Name(pWidget
, bstr
);
985 ok_ole_success(hr
, IWidget_put_Name
);
989 dispparams
.cNamedArgs
= 0;
990 dispparams
.rgdispidNamedArgs
= NULL
;
991 dispparams
.cArgs
= 0;
992 dispparams
.rgvarg
= NULL
;
993 VariantInit(&varresult
);
994 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
995 ok_ole_success(hr
, IDispatch_Invoke
);
996 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
997 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
998 excepinfo
.wCode
, excepinfo
.scode
);
999 trace("Name = %s\n", wine_dbgstr_w(V_BSTR(&varresult
)));
1000 VariantClear(&varresult
);
1002 /* call get_Name (direct) */
1004 hr
= IWidget_get_Name(pWidget
, &bstr
);
1005 ok_ole_success(hr
, IWidget_get_Name
);
1006 ok(!lstrcmpW(bstr
, szCat
), "IWidget_get_Name should have returned string \"Cat\" instead of %s\n", wine_dbgstr_w(bstr
));
1007 SysFreeString(bstr
);
1009 /* call DoSomething */
1010 VariantInit(&vararg
[0]);
1011 VariantInit(&vararg
[1]);
1012 V_VT(&vararg
[1]) = VT_R8
;
1013 V_R8(&vararg
[1]) = 3.141;
1014 dispparams
.cNamedArgs
= 0;
1015 dispparams
.cArgs
= 2;
1016 dispparams
.rgdispidNamedArgs
= NULL
;
1017 dispparams
.rgvarg
= vararg
;
1018 VariantInit(&varresult
);
1019 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_DOSOMETHING
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1020 ok_ole_success(hr
, IDispatch_Invoke
);
1021 ok(V_VT(&varresult
) == VT_EMPTY
, "varresult should be VT_EMPTY\n");
1022 VariantClear(&varresult
);
1024 /* call get_State */
1025 dispparams
.cNamedArgs
= 0;
1026 dispparams
.cArgs
= 0;
1027 dispparams
.rgdispidNamedArgs
= NULL
;
1028 dispparams
.rgvarg
= NULL
;
1029 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_STATE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1030 ok_ole_success(hr
, IDispatch_Invoke
);
1031 ok((V_VT(&varresult
) == VT_I4
) && (V_I4(&varresult
) == STATE_WIDGETIFIED
), "Return val mismatch\n");
1033 /* call get_State (direct) */
1034 hr
= IWidget_get_State(pWidget
, &the_state
);
1035 ok_ole_success(hr
, IWidget_get_state
);
1036 ok(the_state
== STATE_WIDGETIFIED
, "should have returned WIDGET_WIDGETIFIED instead of %d\n", the_state
);
1038 /* call put_State */
1039 the_state
= STATE_WIDGETIFIED
;
1040 VariantInit(&vararg
[0]);
1041 V_VT(&vararg
[0]) = VT_BYREF
|VT_I4
;
1042 V_I4REF(&vararg
[0]) = (int *)&the_state
;
1043 dispparams
.cNamedArgs
= 1;
1044 dispparams
.cArgs
= 1;
1045 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1046 dispparams
.rgvarg
= vararg
;
1047 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_STATE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1048 ok_ole_success(hr
, IDispatch_Invoke
);
1051 bstr
= SysAllocString(szTestTest
);
1052 VariantInit(&vararg
[0]);
1053 V_VT(&vararg
[0]) = VT_BYREF
|VT_BSTR
;
1054 V_BSTRREF(&vararg
[0]) = &bstr
;
1055 dispparams
.cNamedArgs
= 0;
1056 dispparams
.cArgs
= 1;
1057 dispparams
.rgdispidNamedArgs
= NULL
;
1058 dispparams
.rgvarg
= vararg
;
1059 VariantInit(&varresult
);
1060 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_MAP
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1061 ok_ole_success(hr
, IDispatch_Invoke
);
1062 ok(V_VT(&varresult
) == VT_BSTR
, "Return value should be of type BSTR instead of %d\n", V_VT(&varresult
));
1063 ok(!lstrcmpW(V_BSTR(&varresult
), szTestTest
), "Return value should have been \"TestTest\" instead of %s\n", wine_dbgstr_w(V_BSTR(&varresult
)));
1064 VariantClear(&varresult
);
1066 /* call SetOleColor with large negative VT_I4 param */
1067 VariantInit(&vararg
[0]);
1068 V_VT(&vararg
[0]) = VT_I4
;
1069 V_I4(&vararg
[0]) = 0x80000005;
1070 dispparams
.cNamedArgs
= 0;
1071 dispparams
.cArgs
= 1;
1072 dispparams
.rgdispidNamedArgs
= NULL
;
1073 dispparams
.rgvarg
= vararg
;
1074 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_SETOLECOLOR
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, &excepinfo
, NULL
);
1075 ok_ole_success(hr
, IDispatch_Invoke
);
1077 /* call GetOleColor */
1078 dispparams
.cNamedArgs
= 0;
1079 dispparams
.cArgs
= 0;
1080 dispparams
.rgdispidNamedArgs
= NULL
;
1081 dispparams
.rgvarg
= NULL
;
1082 VariantInit(&varresult
);
1083 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_GETOLECOLOR
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1084 ok_ole_success(hr
, IDispatch_Invoke
);
1085 VariantClear(&varresult
);
1087 /* call StructArgs (direct) */
1088 mystruct
= MYSTRUCT_BYPTR
;
1089 memcpy(mystructArray
, MYSTRUCT_ARRAY
, sizeof(mystructArray
));
1090 hr
= IWidget_StructArgs(pWidget
, MYSTRUCT_BYVAL
, &mystruct
, mystructArray
);
1091 ok_ole_success(hr
, IWidget_StructArgs
);
1094 dispparams
.cNamedArgs
= 0;
1095 dispparams
.cArgs
= 0;
1096 dispparams
.rgdispidNamedArgs
= NULL
;
1097 dispparams
.rgvarg
= NULL
;
1098 VariantInit(&varresult
);
1099 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1100 ok_ole_success(hr
, IDispatch_Invoke
);
1101 ok(V_VT(&varresult
) == VT_DISPATCH
, "vt %x\n", V_VT(&varresult
));
1102 VariantClear(&varresult
);
1104 /* call CloneInterface */
1105 dispparams
.cNamedArgs
= 0;
1106 dispparams
.cArgs
= 0;
1107 dispparams
.rgdispidNamedArgs
= NULL
;
1108 dispparams
.rgvarg
= NULL
;
1109 VariantInit(&varresult
);
1110 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONEINTERFACE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1111 ok_ole_success(hr
, IDispatch_Invoke
);
1112 ok(V_VT(&varresult
) == VT_DISPATCH
, "vt %x\n", V_VT(&varresult
));
1113 VariantClear(&varresult
);
1115 /* call CloneDispatch with automatic value getting */
1116 V_VT(&vararg
[0]) = VT_I2
;
1117 V_I2(&vararg
[0]) = 1;
1118 dispparams
.cNamedArgs
= 0;
1119 dispparams
.rgdispidNamedArgs
= NULL
;
1120 dispparams
.cArgs
= 1;
1121 dispparams
.rgvarg
= vararg
;
1122 VariantInit(&varresult
);
1123 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONEDISPATCH
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1124 ok_ole_success(hr
, IDispatch_Invoke
);
1126 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1127 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1128 excepinfo
.wCode
, excepinfo
.scode
);
1130 ok(V_VT(&varresult
) == VT_I2
, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult
));
1131 ok(V_I2(&varresult
) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult
));
1132 VariantClear(&varresult
);
1134 /* call CloneCoclass */
1135 dispparams
.cNamedArgs
= 0;
1136 dispparams
.cArgs
= 0;
1137 dispparams
.rgdispidNamedArgs
= NULL
;
1138 dispparams
.rgvarg
= NULL
;
1139 VariantInit(&varresult
);
1140 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONECOCLASS
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1141 ok_ole_success(hr
, IDispatch_Invoke
);
1143 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1144 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1145 excepinfo
.wCode
, excepinfo
.scode
);
1147 ok(V_VT(&varresult
) == VT_DISPATCH
, "V_VT(&varresult) was %d instead of VT_DISPATCH\n", V_VT(&varresult
));
1148 ok(!V_DISPATCH(&varresult
), "V_DISPATCH(&varresult) should be NULL instead of %p\n", V_DISPATCH(&varresult
));
1149 VariantClear(&varresult
);
1151 /* call Value with a VT_VARIANT|VT_BYREF type */
1152 V_VT(&vararg
[0]) = VT_VARIANT
|VT_BYREF
;
1153 V_VARIANTREF(&vararg
[0]) = &vararg
[1];
1154 V_VT(&vararg
[1]) = VT_I2
;
1155 V_I2(&vararg
[1]) = 1;
1156 dispparams
.cNamedArgs
= 0;
1157 dispparams
.rgdispidNamedArgs
= NULL
;
1158 dispparams
.cArgs
= 1;
1159 dispparams
.rgvarg
= vararg
;
1160 VariantInit(&varresult
);
1161 hr
= IDispatch_Invoke(pDispatch
, DISPID_VALUE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1162 ok_ole_success(hr
, IDispatch_Invoke
);
1164 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1165 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1166 excepinfo
.wCode
, excepinfo
.scode
);
1168 ok(V_VT(&varresult
) == VT_I2
, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult
));
1169 ok(V_I2(&varresult
) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult
));
1170 VariantClear(&varresult
);
1172 /* call Variant - exercises variant copying in ITypeInfo::Invoke and
1173 * handling of void return types */
1174 /* use a big type to ensure that the variant was properly copied into the
1175 * destination function's args */
1176 V_VT(&vararg
[0]) = VT_CY
;
1177 S(V_CY(&vararg
[0])).Hi
= 0xdababe;
1178 S(V_CY(&vararg
[0])).Lo
= 0xdeadbeef;
1179 dispparams
.cNamedArgs
= 0;
1180 dispparams
.cArgs
= 1;
1181 dispparams
.rgdispidNamedArgs
= NULL
;
1182 dispparams
.rgvarg
= vararg
;
1183 VariantInit(&varresult
);
1184 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARIANT
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1185 ok_ole_success(hr
, IDispatch_Invoke
);
1186 VariantClear(&varresult
);
1189 VariantInit(&vararg
[3]);
1190 V_VT(&vararg
[3]) = VT_I4
;
1191 V_I4(&vararg
[3]) = 3;
1192 VariantInit(&vararg
[2]);
1193 V_VT(&vararg
[2]) = VT_I4
;
1194 V_I4(&vararg
[2]) = 0;
1195 VariantInit(&vararg
[1]);
1196 V_VT(&vararg
[1]) = VT_I4
;
1197 V_I4(&vararg
[1]) = 1;
1198 VariantInit(&vararg
[0]);
1199 V_VT(&vararg
[0]) = VT_I4
;
1200 V_I4(&vararg
[0]) = 2;
1201 dispparams
.cNamedArgs
= 0;
1202 dispparams
.cArgs
= 4;
1203 dispparams
.rgdispidNamedArgs
= NULL
;
1204 dispparams
.rgvarg
= vararg
;
1205 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARARG
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1206 ok_ole_success(hr
, ITypeInfo_Invoke
);
1208 /* call VarArg, even one (non-optional, non-safearray) named argument is not allowed */
1210 dispparams
.cNamedArgs
= 1;
1211 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1212 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARARG
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1213 ok(hr
== DISP_E_NONAMEDARGS
, "IDispatch_Invoke should have returned DISP_E_NONAMEDARGS instead of 0x%08x\n", hr
);
1214 dispidNamed
= DISPID_PROPERTYPUT
;
1217 dispparams
.cNamedArgs
= 0;
1218 dispparams
.cArgs
= 0;
1219 dispparams
.rgdispidNamedArgs
= NULL
;
1220 dispparams
.rgvarg
= NULL
;
1221 VariantInit(&varresult
);
1222 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_ERROR
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, &excepinfo
, NULL
);
1223 ok(hr
== DISP_E_EXCEPTION
, "IDispatch_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr
);
1224 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== E_NOTIMPL
,
1225 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1226 excepinfo
.wCode
, excepinfo
.scode
);
1227 VariantClear(&varresult
);
1230 pTypeInfo
= NonOleAutomation_GetTypeInfo();
1231 dispparams
.cNamedArgs
= 0;
1232 dispparams
.cArgs
= 0;
1233 dispparams
.rgdispidNamedArgs
= NULL
;
1234 dispparams
.rgvarg
= NULL
;
1235 VariantInit(&varresult
);
1236 hr
= ITypeInfo_Invoke(pTypeInfo
, &NonOleAutomation
, DISPID_NOA_BSTRRET
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1237 ok_ole_success(hr
, ITypeInfo_Invoke
);
1238 ok(V_VT(&varresult
) == VT_BSTR
, "V_VT(&varresult) should be VT_BSTR instead of %d\n", V_VT(&varresult
));
1239 ok(V_BSTR(&varresult
) != NULL
, "V_BSTR(&varresult) should not be NULL\n");
1241 VariantClear(&varresult
);
1242 ITypeInfo_Release(pTypeInfo
);
1244 /* tests call put_Name without named arg */
1245 VariantInit(&vararg
[0]);
1246 dispparams
.cNamedArgs
= 0;
1247 dispparams
.rgdispidNamedArgs
= NULL
;
1248 dispparams
.cArgs
= 1;
1249 dispparams
.rgvarg
= vararg
;
1250 VariantInit(&varresult
);
1251 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1252 ok(hr
== DISP_E_PARAMNOTFOUND
, "IDispatch_Invoke should have returned DISP_E_PARAMNOTFOUND instead of 0x%08x\n", hr
);
1253 VariantClear(&varresult
);
1255 /* tests param type that cannot be coerced */
1256 VariantInit(&vararg
[0]);
1257 V_VT(&vararg
[0]) = VT_UNKNOWN
;
1258 V_UNKNOWN(&vararg
[0]) = NULL
;
1259 dispparams
.cNamedArgs
= 1;
1260 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1261 dispparams
.cArgs
= 1;
1262 dispparams
.rgvarg
= vararg
;
1263 VariantInit(&varresult
);
1264 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1265 ok(hr
== DISP_E_TYPEMISMATCH
, "IDispatch_Invoke should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hr
);
1266 VariantClear(&varresult
);
1268 /* tests bad param type */
1269 VariantInit(&vararg
[0]);
1270 V_VT(&vararg
[0]) = VT_CLSID
;
1271 V_BYREF(&vararg
[0]) = NULL
;
1272 dispparams
.cNamedArgs
= 1;
1273 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1274 dispparams
.cArgs
= 1;
1275 dispparams
.rgvarg
= vararg
;
1276 VariantInit(&varresult
);
1277 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1278 ok(hr
== DISP_E_BADVARTYPE
, "IDispatch_Invoke should have returned DISP_E_BADVARTYPE instead of 0x%08x\n", hr
);
1279 VariantClear(&varresult
);
1281 /* tests too small param count */
1282 dispparams
.cNamedArgs
= 0;
1283 dispparams
.rgdispidNamedArgs
= NULL
;
1284 dispparams
.cArgs
= 0;
1285 dispparams
.rgvarg
= NULL
;
1286 VariantInit(&varresult
);
1287 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_DOSOMETHING
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1288 ok(hr
== DISP_E_BADPARAMCOUNT
, "IDispatch_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr
);
1289 VariantClear(&varresult
);
1291 /* tests propget function with large param count */
1292 VariantInit(&vararg
[0]);
1293 V_VT(&vararg
[0]) = VT_BSTR
;
1294 V_BSTR(&vararg
[0]) = NULL
;
1295 V_VT(&vararg
[1]) = VT_I4
;
1296 V_I4(&vararg
[1]) = 1;
1297 dispparams
.cNamedArgs
= 0;
1298 dispparams
.cArgs
= 2;
1299 dispparams
.rgdispidNamedArgs
= NULL
;
1300 dispparams
.rgvarg
= vararg
;
1301 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_STATE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1302 ok(hr
== DISP_E_NOTACOLLECTION
, "IDispatch_Invoke should have returned DISP_E_NOTACOLLECTION instead of 0x%08x\n", hr
);
1304 /* test propput with lcid */
1306 /* the lcid passed to the function is the first lcid in the typelib header.
1307 Since we don't explicitly set an lcid in the idl, it'll default to US English. */
1308 VariantInit(&vararg
[0]);
1309 V_VT(&vararg
[0]) = VT_I4
;
1310 V_I4(&vararg
[0]) = 0xcafe;
1311 dispparams
.cNamedArgs
= 1;
1312 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1313 dispparams
.cArgs
= 1;
1314 dispparams
.rgvarg
= vararg
;
1315 VariantInit(&varresult
);
1316 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_WITH_LCID
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1317 ok_ole_success(hr
, ITypeInfo_Invoke
);
1318 VariantClear(&varresult
);
1320 /* test propget with lcid */
1321 dispparams
.cNamedArgs
= 0;
1322 dispparams
.cArgs
= 0;
1323 dispparams
.rgvarg
= NULL
;
1324 dispparams
.rgdispidNamedArgs
= NULL
;
1325 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_WITH_LCID
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1326 ok_ole_success(hr
, ITypeInfo_Invoke
);
1327 ok(V_VT(&varresult
) == VT_I4
, "got %x\n", V_VT(&varresult
));
1328 ok(V_I4(&varresult
) == 0x409, "got %x\n", V_I4(&varresult
));
1329 VariantClear(&varresult
);
1331 /* test propget of INT value */
1332 dispparams
.cNamedArgs
= 0;
1333 dispparams
.cArgs
= 0;
1334 dispparams
.rgvarg
= NULL
;
1335 dispparams
.rgdispidNamedArgs
= NULL
;
1336 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_INT
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1337 ok_ole_success(hr
, ITypeInfo_Invoke
);
1338 ok(V_VT(&varresult
) == VT_I4
, "got %x\n", V_VT(&varresult
));
1339 ok(V_I4(&varresult
) == -13, "got %x\n", V_I4(&varresult
));
1340 VariantClear(&varresult
);
1342 /* test propget of INT value */
1343 dispparams
.cNamedArgs
= 0;
1344 dispparams
.cArgs
= 0;
1345 dispparams
.rgvarg
= NULL
;
1346 dispparams
.rgdispidNamedArgs
= NULL
;
1347 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_UINT
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1348 ok_ole_success(hr
, ITypeInfo_Invoke
);
1349 ok(V_VT(&varresult
) == VT_UI4
, "got %x\n", V_VT(&varresult
));
1350 ok(V_UI4(&varresult
) == 42, "got %x\n", V_UI4(&varresult
));
1351 VariantClear(&varresult
);
1353 /* test byref marshalling */
1355 VariantInit(&vararg
[0]);
1356 V_VT(&vararg
[0]) = VT_UI4
|VT_BYREF
;
1357 V_UI4REF(&vararg
[0]) = &uval
;
1358 dispparams
.cNamedArgs
= 0;
1359 dispparams
.cArgs
= 1;
1360 dispparams
.rgvarg
= vararg
;
1361 dispparams
.rgdispidNamedArgs
= NULL
;
1362 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_BYREF_UINT
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1363 ok_ole_success(hr
, ITypeInfo_Invoke
);
1364 ok(V_VT(&varresult
) == VT_EMPTY
, "varresult should be VT_EMPTY\n");
1365 ok(V_VT(&vararg
[0]) == (VT_UI4
|VT_BYREF
), "arg VT not unmarshalled correctly: %x\n", V_VT(&vararg
[0]));
1366 ok(V_UI4REF(&vararg
[0]) == &uval
, "Byref pointer not preserved: %p/%p\n", &uval
, V_UI4REF(&vararg
[0]));
1367 ok(*V_UI4REF(&vararg
[0]) == 42, "Expected 42 to be returned instead of %u\n", *V_UI4REF(&vararg
[0]));
1368 VariantClear(&varresult
);
1369 VariantClear(&vararg
[0]);
1371 IDispatch_Release(pDispatch
);
1372 IWidget_Release(pWidget
);
1374 trace("calling end_host_object\n");
1375 end_host_object(tid
, thread
);
1378 static void test_DispCallFunc(void)
1380 static const WCHAR szEmpty
[] = { 0 };
1381 VARTYPE rgvt
[] = { VT_R8
, VT_BSTR
, VT_BSTR
, VT_VARIANT
|VT_BYREF
};
1382 VARIANTARG vararg
[4];
1384 VARIANTARG
*rgpvarg
[4] = { &vararg
[0], &vararg
[1], &vararg
[2], &vararg
[3] };
1385 VARIANTARG varresult
;
1387 IWidget
*pWidget
= Widget_Create();
1388 V_VT(&vararg
[0]) = VT_R8
;
1389 V_R8(&vararg
[0]) = 3.141;
1390 V_VT(&vararg
[1]) = VT_BSTR
;
1391 V_BSTRREF(&vararg
[1]) = CoTaskMemAlloc(sizeof(BSTR
));
1392 V_VT(&vararg
[2]) = VT_BSTR
;
1393 V_BSTR(&vararg
[2]) = SysAllocString(szEmpty
);
1394 V_VT(&vararg
[3]) = VT_VARIANT
|VT_BYREF
;
1395 V_VARIANTREF(&vararg
[3]) = &varref
;
1396 V_VT(&varref
) = VT_ERROR
;
1397 V_ERROR(&varref
) = DISP_E_PARAMNOTFOUND
;
1398 VariantInit(&varresult
);
1399 hr
= DispCallFunc(pWidget
, 9*sizeof(void*), CC_STDCALL
, VT_UI4
, 4, rgvt
, rgpvarg
, &varresult
);
1400 ok_ole_success(hr
, DispCallFunc
);
1401 VariantClear(&varresult
);
1402 SysFreeString(*V_BSTRREF(&vararg
[1]));
1403 CoTaskMemFree(V_BSTRREF(&vararg
[1]));
1404 VariantClear(&vararg
[2]);
1405 IWidget_Release(pWidget
);
1408 static void test_StaticWidget(void)
1410 ITypeInfo
*type_info
;
1411 DISPPARAMS dispparams
;
1412 VARIANTARG vararg
[4];
1413 EXCEPINFO excepinfo
;
1417 type_info
= get_type_info(&IID_IStaticWidget
);
1420 dispparams
.cNamedArgs
= 0;
1421 dispparams
.cArgs
= 1;
1422 dispparams
.rgdispidNamedArgs
= NULL
;
1423 dispparams
.rgvarg
= vararg
;
1424 V_VT(vararg
) = VT_DISPATCH
;
1425 V_DISPATCH(vararg
) = (IDispatch
*)&TestDualDisp
;
1426 VariantInit(&varresult
);
1427 hr
= ITypeInfo_Invoke(type_info
, &StaticWidget
, DISPID_TM_TESTDUAL
, DISPATCH_METHOD
,
1428 &dispparams
, &varresult
, &excepinfo
, NULL
);
1429 ok_ole_success(hr
, IDispatch_Invoke
);
1430 ok(V_VT(&varresult
) == VT_EMPTY
, "vt %x\n", V_VT(&varresult
));
1431 VariantClear(&varresult
);
1433 ITypeInfo_Release(type_info
);
1436 static void test_libattr(void)
1442 hr
= LoadRegTypeLib(&LIBID_TestTypelib
, 1, 0, LOCALE_NEUTRAL
, &pTypeLib
);
1443 ok_ole_success(hr
, LoadRegTypeLib
);
1447 hr
= ITypeLib_GetLibAttr(pTypeLib
, &pattr
);
1448 ok_ole_success(hr
, GetLibAttr
);
1451 ok(pattr
->lcid
== MAKELANGID(LANG_NEUTRAL
, SUBLANG_NEUTRAL
), "lcid %x\n", pattr
->lcid
);
1453 ITypeLib_ReleaseTLibAttr(pTypeLib
, pattr
);
1456 ITypeLib_Release(pTypeLib
);
1459 START_TEST(tmarshal
)
1463 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1465 hr
= register_current_module_typelib();
1466 ok_ole_success(hr
, register_current_module_typelib
);
1468 test_typelibmarshal();
1469 test_DispCallFunc();
1470 test_StaticWidget();
1473 hr
= UnRegisterTypeLib(&LIBID_TestTypelib
, 1, 0, LOCALE_NEUTRAL
,
1474 sizeof(void*) == 8 ? SYS_WIN64
: SYS_WIN32
);
1475 ok_ole_success(hr
, UnRegisterTypeLib
);