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 HRESULT WINAPI
NonOleAutomation_Error(INonOleAutomation
*iface
)
903 static INonOleAutomationVtbl NonOleAutomation_VTable
=
905 NonOleAutomation_QueryInterface
,
906 NonOleAutomation_AddRef
,
907 NonOleAutomation_Release
,
908 NonOleAutomation_BstrRet
,
909 NonOleAutomation_Error
912 static INonOleAutomation NonOleAutomation
= { &NonOleAutomation_VTable
};
914 static ITypeInfo
*NonOleAutomation_GetTypeInfo(void)
917 HRESULT hr
= LoadRegTypeLib(&LIBID_TestTypelib
, 1, 0, LOCALE_NEUTRAL
, &pTypeLib
);
918 ok_ole_success(hr
, LoadRegTypeLib
);
921 ITypeInfo
*pTypeInfo
;
922 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, &IID_INonOleAutomation
, &pTypeInfo
);
923 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
924 ITypeLib_Release(pTypeLib
);
930 static void test_typelibmarshal(void)
932 static const WCHAR szCat
[] = { 'C','a','t',0 };
933 static const WCHAR szTestTest
[] = { 'T','e','s','t','T','e','s','t',0 };
934 static WCHAR szSuperman
[] = { 'S','u','p','e','r','m','a','n',0 };
936 IKindaEnumWidget
*pKEW
= KindaEnumWidget_Create();
939 IDispatch
*pDispatch
;
940 static const LARGE_INTEGER ullZero
;
943 DISPID dispidNamed
= DISPID_PROPERTYPUT
;
944 DISPPARAMS dispparams
;
945 VARIANTARG vararg
[4];
950 ITypeInfo
*pTypeInfo
;
952 MYSTRUCT mystructArray
[5];
955 ok(pKEW
!= NULL
, "Widget creation failed\n");
957 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
958 ok_ole_success(hr
, CreateStreamOnHGlobal
);
959 tid
= start_host_object(pStream
, &IID_IKindaEnumWidget
, (IUnknown
*)pKEW
, MSHLFLAGS_NORMAL
, &thread
);
960 IKindaEnumWidget_Release(pKEW
);
962 IStream_Seek(pStream
, ullZero
, STREAM_SEEK_SET
, NULL
);
963 hr
= CoUnmarshalInterface(pStream
, &IID_IKindaEnumWidget
, (void **)&pKEW
);
964 ok_ole_success(hr
, CoUnmarshalInterface
);
965 IStream_Release(pStream
);
967 hr
= IKindaEnumWidget_Next(pKEW
, &pWidget
);
968 ok_ole_success(hr
, IKindaEnumWidget_Next
);
970 IKindaEnumWidget_Release(pKEW
);
972 hr
= IWidget_QueryInterface(pWidget
, &IID_IDispatch
, (void **)&pDispatch
);
975 VariantInit(&vararg
[0]);
976 dispparams
.cNamedArgs
= 1;
977 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
978 dispparams
.cArgs
= 1;
979 dispparams
.rgvarg
= vararg
;
980 VariantInit(&varresult
);
981 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
982 ok_ole_success(hr
, IDispatch_Invoke
);
983 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
984 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
985 excepinfo
.wCode
, excepinfo
.scode
);
986 VariantClear(&varresult
);
988 /* call put_Name (direct) */
989 bstr
= SysAllocString(szSuperman
);
990 hr
= IWidget_put_Name(pWidget
, bstr
);
991 ok_ole_success(hr
, IWidget_put_Name
);
995 dispparams
.cNamedArgs
= 0;
996 dispparams
.rgdispidNamedArgs
= NULL
;
997 dispparams
.cArgs
= 0;
998 dispparams
.rgvarg
= NULL
;
999 VariantInit(&varresult
);
1000 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1001 ok_ole_success(hr
, IDispatch_Invoke
);
1002 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1003 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1004 excepinfo
.wCode
, excepinfo
.scode
);
1005 trace("Name = %s\n", wine_dbgstr_w(V_BSTR(&varresult
)));
1006 VariantClear(&varresult
);
1008 /* call get_Name (direct) */
1010 hr
= IWidget_get_Name(pWidget
, &bstr
);
1011 ok_ole_success(hr
, IWidget_get_Name
);
1012 ok(!lstrcmpW(bstr
, szCat
), "IWidget_get_Name should have returned string \"Cat\" instead of %s\n", wine_dbgstr_w(bstr
));
1013 SysFreeString(bstr
);
1015 /* call DoSomething */
1016 VariantInit(&vararg
[0]);
1017 VariantInit(&vararg
[1]);
1018 V_VT(&vararg
[1]) = VT_R8
;
1019 V_R8(&vararg
[1]) = 3.141;
1020 dispparams
.cNamedArgs
= 0;
1021 dispparams
.cArgs
= 2;
1022 dispparams
.rgdispidNamedArgs
= NULL
;
1023 dispparams
.rgvarg
= vararg
;
1024 VariantInit(&varresult
);
1025 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_DOSOMETHING
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1026 ok_ole_success(hr
, IDispatch_Invoke
);
1027 ok(V_VT(&varresult
) == VT_EMPTY
, "varresult should be VT_EMPTY\n");
1028 VariantClear(&varresult
);
1030 /* call get_State */
1031 dispparams
.cNamedArgs
= 0;
1032 dispparams
.cArgs
= 0;
1033 dispparams
.rgdispidNamedArgs
= NULL
;
1034 dispparams
.rgvarg
= NULL
;
1035 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_STATE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1036 ok_ole_success(hr
, IDispatch_Invoke
);
1037 ok((V_VT(&varresult
) == VT_I4
) && (V_I4(&varresult
) == STATE_WIDGETIFIED
), "Return val mismatch\n");
1039 /* call get_State (direct) */
1040 hr
= IWidget_get_State(pWidget
, &the_state
);
1041 ok_ole_success(hr
, IWidget_get_state
);
1042 ok(the_state
== STATE_WIDGETIFIED
, "should have returned WIDGET_WIDGETIFIED instead of %d\n", the_state
);
1044 /* call put_State */
1045 the_state
= STATE_WIDGETIFIED
;
1046 VariantInit(&vararg
[0]);
1047 V_VT(&vararg
[0]) = VT_BYREF
|VT_I4
;
1048 V_I4REF(&vararg
[0]) = (int *)&the_state
;
1049 dispparams
.cNamedArgs
= 1;
1050 dispparams
.cArgs
= 1;
1051 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1052 dispparams
.rgvarg
= vararg
;
1053 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_STATE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1054 ok_ole_success(hr
, IDispatch_Invoke
);
1057 bstr
= SysAllocString(szTestTest
);
1058 VariantInit(&vararg
[0]);
1059 V_VT(&vararg
[0]) = VT_BYREF
|VT_BSTR
;
1060 V_BSTRREF(&vararg
[0]) = &bstr
;
1061 dispparams
.cNamedArgs
= 0;
1062 dispparams
.cArgs
= 1;
1063 dispparams
.rgdispidNamedArgs
= NULL
;
1064 dispparams
.rgvarg
= vararg
;
1065 VariantInit(&varresult
);
1066 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_MAP
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1067 ok_ole_success(hr
, IDispatch_Invoke
);
1068 ok(V_VT(&varresult
) == VT_BSTR
, "Return value should be of type BSTR instead of %d\n", V_VT(&varresult
));
1069 ok(!lstrcmpW(V_BSTR(&varresult
), szTestTest
), "Return value should have been \"TestTest\" instead of %s\n", wine_dbgstr_w(V_BSTR(&varresult
)));
1070 VariantClear(&varresult
);
1072 /* call SetOleColor with large negative VT_I4 param */
1073 VariantInit(&vararg
[0]);
1074 V_VT(&vararg
[0]) = VT_I4
;
1075 V_I4(&vararg
[0]) = 0x80000005;
1076 dispparams
.cNamedArgs
= 0;
1077 dispparams
.cArgs
= 1;
1078 dispparams
.rgdispidNamedArgs
= NULL
;
1079 dispparams
.rgvarg
= vararg
;
1080 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_SETOLECOLOR
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, &excepinfo
, NULL
);
1081 ok_ole_success(hr
, IDispatch_Invoke
);
1083 /* call GetOleColor */
1084 dispparams
.cNamedArgs
= 0;
1085 dispparams
.cArgs
= 0;
1086 dispparams
.rgdispidNamedArgs
= NULL
;
1087 dispparams
.rgvarg
= NULL
;
1088 VariantInit(&varresult
);
1089 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_GETOLECOLOR
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1090 ok_ole_success(hr
, IDispatch_Invoke
);
1091 VariantClear(&varresult
);
1093 /* call StructArgs (direct) */
1094 mystruct
= MYSTRUCT_BYPTR
;
1095 memcpy(mystructArray
, MYSTRUCT_ARRAY
, sizeof(mystructArray
));
1096 hr
= IWidget_StructArgs(pWidget
, MYSTRUCT_BYVAL
, &mystruct
, mystructArray
);
1097 ok_ole_success(hr
, IWidget_StructArgs
);
1100 dispparams
.cNamedArgs
= 0;
1101 dispparams
.cArgs
= 0;
1102 dispparams
.rgdispidNamedArgs
= NULL
;
1103 dispparams
.rgvarg
= NULL
;
1104 VariantInit(&varresult
);
1105 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1106 ok_ole_success(hr
, IDispatch_Invoke
);
1107 ok(V_VT(&varresult
) == VT_DISPATCH
, "vt %x\n", V_VT(&varresult
));
1108 VariantClear(&varresult
);
1110 /* call CloneInterface */
1111 dispparams
.cNamedArgs
= 0;
1112 dispparams
.cArgs
= 0;
1113 dispparams
.rgdispidNamedArgs
= NULL
;
1114 dispparams
.rgvarg
= NULL
;
1115 VariantInit(&varresult
);
1116 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONEINTERFACE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1117 ok_ole_success(hr
, IDispatch_Invoke
);
1118 ok(V_VT(&varresult
) == VT_DISPATCH
, "vt %x\n", V_VT(&varresult
));
1119 VariantClear(&varresult
);
1121 /* call CloneDispatch with automatic value getting */
1122 V_VT(&vararg
[0]) = VT_I2
;
1123 V_I2(&vararg
[0]) = 1;
1124 dispparams
.cNamedArgs
= 0;
1125 dispparams
.rgdispidNamedArgs
= NULL
;
1126 dispparams
.cArgs
= 1;
1127 dispparams
.rgvarg
= vararg
;
1128 VariantInit(&varresult
);
1129 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONEDISPATCH
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1130 ok_ole_success(hr
, IDispatch_Invoke
);
1132 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1133 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1134 excepinfo
.wCode
, excepinfo
.scode
);
1136 ok(V_VT(&varresult
) == VT_I2
, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult
));
1137 ok(V_I2(&varresult
) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult
));
1138 VariantClear(&varresult
);
1140 /* call CloneCoclass */
1141 dispparams
.cNamedArgs
= 0;
1142 dispparams
.cArgs
= 0;
1143 dispparams
.rgdispidNamedArgs
= NULL
;
1144 dispparams
.rgvarg
= NULL
;
1145 VariantInit(&varresult
);
1146 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONECOCLASS
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1147 ok_ole_success(hr
, IDispatch_Invoke
);
1149 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1150 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1151 excepinfo
.wCode
, excepinfo
.scode
);
1153 ok(V_VT(&varresult
) == VT_DISPATCH
, "V_VT(&varresult) was %d instead of VT_DISPATCH\n", V_VT(&varresult
));
1154 ok(!V_DISPATCH(&varresult
), "V_DISPATCH(&varresult) should be NULL instead of %p\n", V_DISPATCH(&varresult
));
1155 VariantClear(&varresult
);
1157 /* call Value with a VT_VARIANT|VT_BYREF type */
1158 V_VT(&vararg
[0]) = VT_VARIANT
|VT_BYREF
;
1159 V_VARIANTREF(&vararg
[0]) = &vararg
[1];
1160 V_VT(&vararg
[1]) = VT_I2
;
1161 V_I2(&vararg
[1]) = 1;
1162 dispparams
.cNamedArgs
= 0;
1163 dispparams
.rgdispidNamedArgs
= NULL
;
1164 dispparams
.cArgs
= 1;
1165 dispparams
.rgvarg
= vararg
;
1166 VariantInit(&varresult
);
1167 hr
= IDispatch_Invoke(pDispatch
, DISPID_VALUE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1168 ok_ole_success(hr
, IDispatch_Invoke
);
1170 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1171 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1172 excepinfo
.wCode
, excepinfo
.scode
);
1174 ok(V_VT(&varresult
) == VT_I2
, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult
));
1175 ok(V_I2(&varresult
) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult
));
1176 VariantClear(&varresult
);
1178 /* call Variant - exercises variant copying in ITypeInfo::Invoke and
1179 * handling of void return types */
1180 /* use a big type to ensure that the variant was properly copied into the
1181 * destination function's args */
1182 V_VT(&vararg
[0]) = VT_CY
;
1183 S(V_CY(&vararg
[0])).Hi
= 0xdababe;
1184 S(V_CY(&vararg
[0])).Lo
= 0xdeadbeef;
1185 dispparams
.cNamedArgs
= 0;
1186 dispparams
.cArgs
= 1;
1187 dispparams
.rgdispidNamedArgs
= NULL
;
1188 dispparams
.rgvarg
= vararg
;
1189 VariantInit(&varresult
);
1190 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARIANT
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1191 ok_ole_success(hr
, IDispatch_Invoke
);
1192 VariantClear(&varresult
);
1195 VariantInit(&vararg
[3]);
1196 V_VT(&vararg
[3]) = VT_I4
;
1197 V_I4(&vararg
[3]) = 3;
1198 VariantInit(&vararg
[2]);
1199 V_VT(&vararg
[2]) = VT_I4
;
1200 V_I4(&vararg
[2]) = 0;
1201 VariantInit(&vararg
[1]);
1202 V_VT(&vararg
[1]) = VT_I4
;
1203 V_I4(&vararg
[1]) = 1;
1204 VariantInit(&vararg
[0]);
1205 V_VT(&vararg
[0]) = VT_I4
;
1206 V_I4(&vararg
[0]) = 2;
1207 dispparams
.cNamedArgs
= 0;
1208 dispparams
.cArgs
= 4;
1209 dispparams
.rgdispidNamedArgs
= NULL
;
1210 dispparams
.rgvarg
= vararg
;
1211 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARARG
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1212 ok_ole_success(hr
, ITypeInfo_Invoke
);
1214 /* call VarArg, even one (non-optional, non-safearray) named argument is not allowed */
1216 dispparams
.cNamedArgs
= 1;
1217 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1218 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARARG
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1219 ok(hr
== DISP_E_NONAMEDARGS
, "IDispatch_Invoke should have returned DISP_E_NONAMEDARGS instead of 0x%08x\n", hr
);
1220 dispidNamed
= DISPID_PROPERTYPUT
;
1223 dispparams
.cNamedArgs
= 0;
1224 dispparams
.cArgs
= 0;
1225 dispparams
.rgdispidNamedArgs
= NULL
;
1226 dispparams
.rgvarg
= NULL
;
1227 VariantInit(&varresult
);
1228 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_ERROR
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, &excepinfo
, NULL
);
1229 ok(hr
== DISP_E_EXCEPTION
, "IDispatch_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr
);
1230 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== E_NOTIMPL
,
1231 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1232 excepinfo
.wCode
, excepinfo
.scode
);
1233 VariantClear(&varresult
);
1236 pTypeInfo
= NonOleAutomation_GetTypeInfo();
1237 dispparams
.cNamedArgs
= 0;
1238 dispparams
.cArgs
= 0;
1239 dispparams
.rgdispidNamedArgs
= NULL
;
1240 dispparams
.rgvarg
= NULL
;
1241 VariantInit(&varresult
);
1242 hr
= ITypeInfo_Invoke(pTypeInfo
, &NonOleAutomation
, DISPID_NOA_BSTRRET
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1243 ok_ole_success(hr
, ITypeInfo_Invoke
);
1244 ok(V_VT(&varresult
) == VT_BSTR
, "V_VT(&varresult) should be VT_BSTR instead of %d\n", V_VT(&varresult
));
1245 ok(V_BSTR(&varresult
) != NULL
, "V_BSTR(&varresult) should not be NULL\n");
1247 VariantClear(&varresult
);
1249 dispparams
.cNamedArgs
= 0;
1250 dispparams
.cArgs
= 0;
1251 dispparams
.rgdispidNamedArgs
= NULL
;
1252 dispparams
.rgvarg
= NULL
;
1253 hr
= ITypeInfo_Invoke(pTypeInfo
, &NonOleAutomation
, DISPID_NOA_ERROR
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1254 ok(hr
== DISP_E_EXCEPTION
, "ITypeInfo_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr
);
1255 ok(V_VT(&varresult
) == VT_EMPTY
, "V_VT(&varresult) should be VT_EMPTY instead of %d\n", V_VT(&varresult
));
1256 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== E_NOTIMPL
,
1257 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1258 excepinfo
.wCode
, excepinfo
.scode
);
1259 VariantClear(&varresult
);
1261 ITypeInfo_Release(pTypeInfo
);
1263 /* tests call put_Name without named arg */
1264 VariantInit(&vararg
[0]);
1265 dispparams
.cNamedArgs
= 0;
1266 dispparams
.rgdispidNamedArgs
= NULL
;
1267 dispparams
.cArgs
= 1;
1268 dispparams
.rgvarg
= vararg
;
1269 VariantInit(&varresult
);
1270 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1271 ok(hr
== DISP_E_PARAMNOTFOUND
, "IDispatch_Invoke should have returned DISP_E_PARAMNOTFOUND instead of 0x%08x\n", hr
);
1272 VariantClear(&varresult
);
1274 /* tests param type that cannot be coerced */
1275 VariantInit(&vararg
[0]);
1276 V_VT(&vararg
[0]) = VT_UNKNOWN
;
1277 V_UNKNOWN(&vararg
[0]) = NULL
;
1278 dispparams
.cNamedArgs
= 1;
1279 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1280 dispparams
.cArgs
= 1;
1281 dispparams
.rgvarg
= vararg
;
1282 VariantInit(&varresult
);
1283 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1284 ok(hr
== DISP_E_TYPEMISMATCH
, "IDispatch_Invoke should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hr
);
1285 VariantClear(&varresult
);
1287 /* tests bad param type */
1288 VariantInit(&vararg
[0]);
1289 V_VT(&vararg
[0]) = VT_CLSID
;
1290 V_BYREF(&vararg
[0]) = NULL
;
1291 dispparams
.cNamedArgs
= 1;
1292 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1293 dispparams
.cArgs
= 1;
1294 dispparams
.rgvarg
= vararg
;
1295 VariantInit(&varresult
);
1296 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1297 ok(hr
== DISP_E_BADVARTYPE
, "IDispatch_Invoke should have returned DISP_E_BADVARTYPE instead of 0x%08x\n", hr
);
1298 VariantClear(&varresult
);
1300 /* tests too small param count */
1301 dispparams
.cNamedArgs
= 0;
1302 dispparams
.rgdispidNamedArgs
= NULL
;
1303 dispparams
.cArgs
= 0;
1304 dispparams
.rgvarg
= NULL
;
1305 VariantInit(&varresult
);
1306 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_DOSOMETHING
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1307 ok(hr
== DISP_E_BADPARAMCOUNT
, "IDispatch_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr
);
1308 VariantClear(&varresult
);
1310 /* tests propget function with large param count */
1311 VariantInit(&vararg
[0]);
1312 V_VT(&vararg
[0]) = VT_BSTR
;
1313 V_BSTR(&vararg
[0]) = NULL
;
1314 V_VT(&vararg
[1]) = VT_I4
;
1315 V_I4(&vararg
[1]) = 1;
1316 dispparams
.cNamedArgs
= 0;
1317 dispparams
.cArgs
= 2;
1318 dispparams
.rgdispidNamedArgs
= NULL
;
1319 dispparams
.rgvarg
= vararg
;
1320 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_STATE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1321 ok(hr
== DISP_E_NOTACOLLECTION
, "IDispatch_Invoke should have returned DISP_E_NOTACOLLECTION instead of 0x%08x\n", hr
);
1323 /* test propput with lcid */
1325 /* the lcid passed to the function is the first lcid in the typelib header.
1326 Since we don't explicitly set an lcid in the idl, it'll default to US English. */
1327 VariantInit(&vararg
[0]);
1328 V_VT(&vararg
[0]) = VT_I4
;
1329 V_I4(&vararg
[0]) = 0xcafe;
1330 dispparams
.cNamedArgs
= 1;
1331 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1332 dispparams
.cArgs
= 1;
1333 dispparams
.rgvarg
= vararg
;
1334 VariantInit(&varresult
);
1335 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_WITH_LCID
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1336 ok_ole_success(hr
, ITypeInfo_Invoke
);
1337 VariantClear(&varresult
);
1339 /* test propget with lcid */
1340 dispparams
.cNamedArgs
= 0;
1341 dispparams
.cArgs
= 0;
1342 dispparams
.rgvarg
= NULL
;
1343 dispparams
.rgdispidNamedArgs
= NULL
;
1344 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_WITH_LCID
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1345 ok_ole_success(hr
, ITypeInfo_Invoke
);
1346 ok(V_VT(&varresult
) == VT_I4
, "got %x\n", V_VT(&varresult
));
1347 ok(V_I4(&varresult
) == 0x409, "got %x\n", V_I4(&varresult
));
1348 VariantClear(&varresult
);
1350 /* test propget of INT value */
1351 dispparams
.cNamedArgs
= 0;
1352 dispparams
.cArgs
= 0;
1353 dispparams
.rgvarg
= NULL
;
1354 dispparams
.rgdispidNamedArgs
= NULL
;
1355 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_INT
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1356 ok_ole_success(hr
, ITypeInfo_Invoke
);
1357 ok(V_VT(&varresult
) == VT_I4
, "got %x\n", V_VT(&varresult
));
1358 ok(V_I4(&varresult
) == -13, "got %x\n", V_I4(&varresult
));
1359 VariantClear(&varresult
);
1361 /* test propget of INT value */
1362 dispparams
.cNamedArgs
= 0;
1363 dispparams
.cArgs
= 0;
1364 dispparams
.rgvarg
= NULL
;
1365 dispparams
.rgdispidNamedArgs
= NULL
;
1366 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_UINT
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1367 ok_ole_success(hr
, ITypeInfo_Invoke
);
1368 ok(V_VT(&varresult
) == VT_UI4
, "got %x\n", V_VT(&varresult
));
1369 ok(V_UI4(&varresult
) == 42, "got %x\n", V_UI4(&varresult
));
1370 VariantClear(&varresult
);
1372 /* test byref marshalling */
1374 VariantInit(&vararg
[0]);
1375 V_VT(&vararg
[0]) = VT_UI4
|VT_BYREF
;
1376 V_UI4REF(&vararg
[0]) = &uval
;
1377 dispparams
.cNamedArgs
= 0;
1378 dispparams
.cArgs
= 1;
1379 dispparams
.rgvarg
= vararg
;
1380 dispparams
.rgdispidNamedArgs
= NULL
;
1381 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_BYREF_UINT
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1382 ok_ole_success(hr
, ITypeInfo_Invoke
);
1383 ok(V_VT(&varresult
) == VT_EMPTY
, "varresult should be VT_EMPTY\n");
1384 ok(V_VT(&vararg
[0]) == (VT_UI4
|VT_BYREF
), "arg VT not unmarshalled correctly: %x\n", V_VT(&vararg
[0]));
1385 ok(V_UI4REF(&vararg
[0]) == &uval
, "Byref pointer not preserved: %p/%p\n", &uval
, V_UI4REF(&vararg
[0]));
1386 ok(*V_UI4REF(&vararg
[0]) == 42, "Expected 42 to be returned instead of %u\n", *V_UI4REF(&vararg
[0]));
1387 VariantClear(&varresult
);
1388 VariantClear(&vararg
[0]);
1390 IDispatch_Release(pDispatch
);
1391 IWidget_Release(pWidget
);
1393 trace("calling end_host_object\n");
1394 end_host_object(tid
, thread
);
1397 static void test_DispCallFunc(void)
1399 static const WCHAR szEmpty
[] = { 0 };
1400 VARTYPE rgvt
[] = { VT_R8
, VT_BSTR
, VT_BSTR
, VT_VARIANT
|VT_BYREF
};
1401 VARIANTARG vararg
[4];
1403 VARIANTARG
*rgpvarg
[4] = { &vararg
[0], &vararg
[1], &vararg
[2], &vararg
[3] };
1404 VARIANTARG varresult
;
1406 IWidget
*pWidget
= Widget_Create();
1407 V_VT(&vararg
[0]) = VT_R8
;
1408 V_R8(&vararg
[0]) = 3.141;
1409 V_VT(&vararg
[1]) = VT_BSTR
;
1410 V_BSTRREF(&vararg
[1]) = CoTaskMemAlloc(sizeof(BSTR
));
1411 V_VT(&vararg
[2]) = VT_BSTR
;
1412 V_BSTR(&vararg
[2]) = SysAllocString(szEmpty
);
1413 V_VT(&vararg
[3]) = VT_VARIANT
|VT_BYREF
;
1414 V_VARIANTREF(&vararg
[3]) = &varref
;
1415 V_VT(&varref
) = VT_ERROR
;
1416 V_ERROR(&varref
) = DISP_E_PARAMNOTFOUND
;
1417 VariantInit(&varresult
);
1418 hr
= DispCallFunc(pWidget
, 9*sizeof(void*), CC_STDCALL
, VT_UI4
, 4, rgvt
, rgpvarg
, &varresult
);
1419 ok_ole_success(hr
, DispCallFunc
);
1420 VariantClear(&varresult
);
1421 SysFreeString(*V_BSTRREF(&vararg
[1]));
1422 CoTaskMemFree(V_BSTRREF(&vararg
[1]));
1423 VariantClear(&vararg
[2]);
1424 IWidget_Release(pWidget
);
1427 static void test_StaticWidget(void)
1429 ITypeInfo
*type_info
;
1430 DISPPARAMS dispparams
;
1431 VARIANTARG vararg
[4];
1432 EXCEPINFO excepinfo
;
1436 type_info
= get_type_info(&IID_IStaticWidget
);
1439 dispparams
.cNamedArgs
= 0;
1440 dispparams
.cArgs
= 1;
1441 dispparams
.rgdispidNamedArgs
= NULL
;
1442 dispparams
.rgvarg
= vararg
;
1443 V_VT(vararg
) = VT_DISPATCH
;
1444 V_DISPATCH(vararg
) = (IDispatch
*)&TestDualDisp
;
1445 VariantInit(&varresult
);
1446 hr
= ITypeInfo_Invoke(type_info
, &StaticWidget
, DISPID_TM_TESTDUAL
, DISPATCH_METHOD
,
1447 &dispparams
, &varresult
, &excepinfo
, NULL
);
1448 ok_ole_success(hr
, IDispatch_Invoke
);
1449 ok(V_VT(&varresult
) == VT_EMPTY
, "vt %x\n", V_VT(&varresult
));
1450 VariantClear(&varresult
);
1452 ITypeInfo_Release(type_info
);
1455 static void test_libattr(void)
1461 hr
= LoadRegTypeLib(&LIBID_TestTypelib
, 1, 0, LOCALE_NEUTRAL
, &pTypeLib
);
1462 ok_ole_success(hr
, LoadRegTypeLib
);
1466 hr
= ITypeLib_GetLibAttr(pTypeLib
, &pattr
);
1467 ok_ole_success(hr
, GetLibAttr
);
1470 ok(pattr
->lcid
== MAKELANGID(LANG_NEUTRAL
, SUBLANG_NEUTRAL
), "lcid %x\n", pattr
->lcid
);
1472 ITypeLib_ReleaseTLibAttr(pTypeLib
, pattr
);
1475 ITypeLib_Release(pTypeLib
);
1478 START_TEST(tmarshal
)
1482 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1484 hr
= register_current_module_typelib();
1485 ok_ole_success(hr
, register_current_module_typelib
);
1487 test_typelibmarshal();
1488 test_DispCallFunc();
1489 test_StaticWidget();
1492 hr
= UnRegisterTypeLib(&LIBID_TestTypelib
, 1, 0, LOCALE_NEUTRAL
,
1493 sizeof(void*) == 8 ? SYS_WIN64
: SYS_WIN32
);
1494 ok_ole_success(hr
, UnRegisterTypeLib
);