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 HRESULT WINAPI
Widget_put_prop_opt_arg(
598 IWidget
* iface
, INT opt
, INT i
)
600 trace("put_prop_opt_arg(%08x, %08x)\n", opt
, i
);
601 todo_wine
ok(opt
== 0, "got opt=%08x\n", opt
);
602 ok(i
== 0xcafe, "got i=%08x\n", i
);
606 static HRESULT WINAPI
Widget_put_prop_req_arg(
607 IWidget
* iface
, INT req
, INT i
)
609 trace("put_prop_req_arg(%08x, %08x)\n", req
, i
);
610 ok(req
== 0x5678, "got req=%08x\n", req
);
611 ok(i
== 0x1234, "got i=%08x\n", i
);
615 static const struct IWidgetVtbl Widget_VTable
=
617 Widget_QueryInterface
,
620 Widget_GetTypeInfoCount
,
622 Widget_GetIDsOfNames
,
633 Widget_CloneDispatch
,
637 Widget_VariantArrayPtr
,
642 Widget_CloneInterface
,
643 Widget_put_prop_with_lcid
,
644 Widget_get_prop_with_lcid
,
646 Widget_get_prop_uint
,
648 Widget_put_prop_opt_arg
,
649 Widget_put_prop_req_arg
,
652 static HRESULT WINAPI
StaticWidget_QueryInterface(IStaticWidget
*iface
, REFIID riid
, void **ppvObject
)
654 if (IsEqualIID(riid
, &IID_IStaticWidget
) || IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDispatch
))
656 IStaticWidget_AddRef(iface
);
662 return E_NOINTERFACE
;
665 static ULONG WINAPI
StaticWidget_AddRef(IStaticWidget
*iface
)
670 static ULONG WINAPI
StaticWidget_Release(IStaticWidget
*iface
)
675 static HRESULT WINAPI
StaticWidget_GetTypeInfoCount(IStaticWidget
*iface
, UINT
*pctinfo
)
677 ok(0, "unexpected call\n");
681 static HRESULT WINAPI
StaticWidget_GetTypeInfo(IStaticWidget
*iface
, UINT iTInfo
, LCID lcid
,
684 ok(0, "unexpected call\n");
688 static HRESULT WINAPI
StaticWidget_GetIDsOfNames(IStaticWidget
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
689 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
691 ok(0, "unexpected call\n");
695 static HRESULT WINAPI
StaticWidget_Invoke(IStaticWidget
*iface
, DISPID dispIdMember
, REFIID riid
,
696 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
,
699 ok(0, "unexpected call\n");
703 static HRESULT WINAPI
StaticWidget_TestDual(IStaticWidget
*iface
, ItestDual
*p
)
705 trace("TestDual()\n");
707 ok(p
== &TestDual
, "wrong ItestDual\n");
711 static const IStaticWidgetVtbl StaticWidgetVtbl
= {
712 StaticWidget_QueryInterface
,
714 StaticWidget_Release
,
715 StaticWidget_GetTypeInfoCount
,
716 StaticWidget_GetTypeInfo
,
717 StaticWidget_GetIDsOfNames
,
719 StaticWidget_TestDual
722 static IStaticWidget StaticWidget
= { &StaticWidgetVtbl
};
724 typedef struct KindaEnum
726 const IKindaEnumWidgetVtbl
*lpVtbl
;
730 static HRESULT
register_current_module_typelib(void)
732 WCHAR path
[MAX_PATH
];
733 CHAR pathA
[MAX_PATH
];
737 GetModuleFileNameA(NULL
, pathA
, MAX_PATH
);
738 MultiByteToWideChar(CP_ACP
, 0, pathA
, -1, path
, MAX_PATH
);
740 hr
= LoadTypeLib(path
, &typelib
);
743 hr
= RegisterTypeLib(typelib
, path
, NULL
);
744 ITypeLib_Release(typelib
);
749 static ITypeInfo
*get_type_info(REFIID riid
)
751 ITypeInfo
*pTypeInfo
;
755 hr
= LoadRegTypeLib(&LIBID_TestTypelib
, 1, 0, LOCALE_NEUTRAL
, &pTypeLib
);
756 ok_ole_success(hr
, LoadRegTypeLib
);
760 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, riid
, &pTypeInfo
);
761 ITypeLib_Release(pTypeLib
);
762 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
769 static IWidget
*Widget_Create(void)
772 ITypeInfo
*pTypeInfo
;
775 pTypeInfo
= get_type_info(&IID_IWidget
);
779 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
780 This
->lpVtbl
= &Widget_VTable
;
782 This
->pDispatchUnknown
= NULL
;
784 hr
= CreateStdDispatch((IUnknown
*)&This
->lpVtbl
, This
, pTypeInfo
, &This
->pDispatchUnknown
);
785 ok_ole_success(hr
, CreateStdDispatch
);
786 ITypeInfo_Release(pTypeInfo
);
789 return (IWidget
*)&This
->lpVtbl
;
792 HeapFree(GetProcessHeap(), 0, This
);
797 static HRESULT WINAPI
KindaEnum_QueryInterface(
798 IKindaEnumWidget
*iface
,
799 /* [in] */ REFIID riid
,
800 /* [iid_is][out] */ void __RPC_FAR
*__RPC_FAR
*ppvObject
)
802 if (IsEqualIID(riid
, &IID_IKindaEnumWidget
) || IsEqualIID(riid
, &IID_IUnknown
))
804 IKindaEnumWidget_AddRef(iface
);
811 return E_NOINTERFACE
;
815 static ULONG WINAPI
KindaEnum_AddRef(
816 IKindaEnumWidget
*iface
)
818 KindaEnum
*This
= (KindaEnum
*)iface
;
820 return InterlockedIncrement(&This
->refs
);
823 static ULONG WINAPI
KindaEnum_Release(
824 IKindaEnumWidget
*iface
)
826 KindaEnum
*This
= (KindaEnum
*)iface
;
827 ULONG refs
= InterlockedDecrement(&This
->refs
);
830 memset(This
, 0xcc, sizeof(*This
));
831 HeapFree(GetProcessHeap(), 0, This
);
832 trace("KindaEnumWidget destroyed!\n");
838 static HRESULT WINAPI
KindaEnum_Next(
839 IKindaEnumWidget
*iface
,
840 /* [out] */ IWidget __RPC_FAR
*__RPC_FAR
*widget
)
842 *widget
= Widget_Create();
846 return E_OUTOFMEMORY
;
849 static HRESULT WINAPI
KindaEnum_Count(
850 IKindaEnumWidget
*iface
,
851 /* [out] */ ULONG __RPC_FAR
*count
)
856 static HRESULT WINAPI
KindaEnum_Reset(
857 IKindaEnumWidget
*iface
)
862 static HRESULT WINAPI
KindaEnum_Clone(
863 IKindaEnumWidget
*iface
,
864 /* [out] */ IKindaEnumWidget __RPC_FAR
*__RPC_FAR
*ppenum
)
869 static const IKindaEnumWidgetVtbl KindaEnumWidget_VTable
=
871 KindaEnum_QueryInterface
,
880 static IKindaEnumWidget
*KindaEnumWidget_Create(void)
884 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
885 if (!This
) return NULL
;
886 This
->lpVtbl
= &KindaEnumWidget_VTable
;
888 return (IKindaEnumWidget
*)This
;
891 static HRESULT WINAPI
NonOleAutomation_QueryInterface(INonOleAutomation
*iface
, REFIID riid
, void **ppv
)
893 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_INonOleAutomation
))
895 *(INonOleAutomation
**)ppv
= iface
;
899 return E_NOINTERFACE
;
902 static ULONG WINAPI
NonOleAutomation_AddRef(INonOleAutomation
*iface
)
907 static ULONG WINAPI
NonOleAutomation_Release(INonOleAutomation
*iface
)
912 static BSTR WINAPI
NonOleAutomation_BstrRet(INonOleAutomation
*iface
)
914 static const WCHAR wszTestString
[] = {'T','h','i','s',' ','i','s',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0};
915 return SysAllocString(wszTestString
);
918 static HRESULT WINAPI
NonOleAutomation_Error(INonOleAutomation
*iface
)
923 static INonOleAutomationVtbl NonOleAutomation_VTable
=
925 NonOleAutomation_QueryInterface
,
926 NonOleAutomation_AddRef
,
927 NonOleAutomation_Release
,
928 NonOleAutomation_BstrRet
,
929 NonOleAutomation_Error
932 static INonOleAutomation NonOleAutomation
= { &NonOleAutomation_VTable
};
934 static ITypeInfo
*NonOleAutomation_GetTypeInfo(void)
937 HRESULT hr
= LoadRegTypeLib(&LIBID_TestTypelib
, 1, 0, LOCALE_NEUTRAL
, &pTypeLib
);
938 ok_ole_success(hr
, LoadRegTypeLib
);
941 ITypeInfo
*pTypeInfo
;
942 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, &IID_INonOleAutomation
, &pTypeInfo
);
943 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
944 ITypeLib_Release(pTypeLib
);
950 static void test_typelibmarshal(void)
952 static const WCHAR szCat
[] = { 'C','a','t',0 };
953 static const WCHAR szTestTest
[] = { 'T','e','s','t','T','e','s','t',0 };
954 static WCHAR szSuperman
[] = { 'S','u','p','e','r','m','a','n',0 };
956 IKindaEnumWidget
*pKEW
= KindaEnumWidget_Create();
959 IDispatch
*pDispatch
;
960 static const LARGE_INTEGER ullZero
;
963 DISPID dispidNamed
= DISPID_PROPERTYPUT
;
964 DISPPARAMS dispparams
;
965 VARIANTARG vararg
[4];
970 ITypeInfo
*pTypeInfo
;
972 MYSTRUCT mystructArray
[5];
975 ok(pKEW
!= NULL
, "Widget creation failed\n");
977 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
978 ok_ole_success(hr
, CreateStreamOnHGlobal
);
979 tid
= start_host_object(pStream
, &IID_IKindaEnumWidget
, (IUnknown
*)pKEW
, MSHLFLAGS_NORMAL
, &thread
);
980 IKindaEnumWidget_Release(pKEW
);
982 IStream_Seek(pStream
, ullZero
, STREAM_SEEK_SET
, NULL
);
983 hr
= CoUnmarshalInterface(pStream
, &IID_IKindaEnumWidget
, (void **)&pKEW
);
984 ok_ole_success(hr
, CoUnmarshalInterface
);
985 IStream_Release(pStream
);
987 hr
= IKindaEnumWidget_Next(pKEW
, &pWidget
);
988 ok_ole_success(hr
, IKindaEnumWidget_Next
);
990 IKindaEnumWidget_Release(pKEW
);
992 hr
= IWidget_QueryInterface(pWidget
, &IID_IDispatch
, (void **)&pDispatch
);
995 VariantInit(&vararg
[0]);
996 dispparams
.cNamedArgs
= 1;
997 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
998 dispparams
.cArgs
= 1;
999 dispparams
.rgvarg
= vararg
;
1000 VariantInit(&varresult
);
1001 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1002 ok_ole_success(hr
, IDispatch_Invoke
);
1003 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1004 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1005 excepinfo
.wCode
, excepinfo
.scode
);
1006 VariantClear(&varresult
);
1008 /* call put_Name (direct) */
1009 bstr
= SysAllocString(szSuperman
);
1010 hr
= IWidget_put_Name(pWidget
, bstr
);
1011 ok_ole_success(hr
, IWidget_put_Name
);
1012 SysFreeString(bstr
);
1015 dispparams
.cNamedArgs
= 0;
1016 dispparams
.rgdispidNamedArgs
= NULL
;
1017 dispparams
.cArgs
= 0;
1018 dispparams
.rgvarg
= NULL
;
1019 VariantInit(&varresult
);
1020 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1021 ok_ole_success(hr
, IDispatch_Invoke
);
1022 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1023 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1024 excepinfo
.wCode
, excepinfo
.scode
);
1025 trace("Name = %s\n", wine_dbgstr_w(V_BSTR(&varresult
)));
1026 VariantClear(&varresult
);
1028 /* call get_Name (direct) */
1030 hr
= IWidget_get_Name(pWidget
, &bstr
);
1031 ok_ole_success(hr
, IWidget_get_Name
);
1032 ok(!lstrcmpW(bstr
, szCat
), "IWidget_get_Name should have returned string \"Cat\" instead of %s\n", wine_dbgstr_w(bstr
));
1033 SysFreeString(bstr
);
1035 /* call DoSomething */
1036 VariantInit(&vararg
[0]);
1037 VariantInit(&vararg
[1]);
1038 V_VT(&vararg
[1]) = VT_R8
;
1039 V_R8(&vararg
[1]) = 3.141;
1040 dispparams
.cNamedArgs
= 0;
1041 dispparams
.cArgs
= 2;
1042 dispparams
.rgdispidNamedArgs
= NULL
;
1043 dispparams
.rgvarg
= vararg
;
1044 VariantInit(&varresult
);
1045 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_DOSOMETHING
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1046 ok_ole_success(hr
, IDispatch_Invoke
);
1047 ok(V_VT(&varresult
) == VT_EMPTY
, "varresult should be VT_EMPTY\n");
1048 VariantClear(&varresult
);
1050 /* call get_State */
1051 dispparams
.cNamedArgs
= 0;
1052 dispparams
.cArgs
= 0;
1053 dispparams
.rgdispidNamedArgs
= NULL
;
1054 dispparams
.rgvarg
= NULL
;
1055 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_STATE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1056 ok_ole_success(hr
, IDispatch_Invoke
);
1057 ok((V_VT(&varresult
) == VT_I4
) && (V_I4(&varresult
) == STATE_WIDGETIFIED
), "Return val mismatch\n");
1059 /* call get_State (direct) */
1060 hr
= IWidget_get_State(pWidget
, &the_state
);
1061 ok_ole_success(hr
, IWidget_get_state
);
1062 ok(the_state
== STATE_WIDGETIFIED
, "should have returned WIDGET_WIDGETIFIED instead of %d\n", the_state
);
1064 /* call put_State */
1065 the_state
= STATE_WIDGETIFIED
;
1066 VariantInit(&vararg
[0]);
1067 V_VT(&vararg
[0]) = VT_BYREF
|VT_I4
;
1068 V_I4REF(&vararg
[0]) = (int *)&the_state
;
1069 dispparams
.cNamedArgs
= 1;
1070 dispparams
.cArgs
= 1;
1071 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1072 dispparams
.rgvarg
= vararg
;
1073 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_STATE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1074 ok_ole_success(hr
, IDispatch_Invoke
);
1077 bstr
= SysAllocString(szTestTest
);
1078 VariantInit(&vararg
[0]);
1079 V_VT(&vararg
[0]) = VT_BYREF
|VT_BSTR
;
1080 V_BSTRREF(&vararg
[0]) = &bstr
;
1081 dispparams
.cNamedArgs
= 0;
1082 dispparams
.cArgs
= 1;
1083 dispparams
.rgdispidNamedArgs
= NULL
;
1084 dispparams
.rgvarg
= vararg
;
1085 VariantInit(&varresult
);
1086 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_MAP
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1087 ok_ole_success(hr
, IDispatch_Invoke
);
1088 ok(V_VT(&varresult
) == VT_BSTR
, "Return value should be of type BSTR instead of %d\n", V_VT(&varresult
));
1089 ok(!lstrcmpW(V_BSTR(&varresult
), szTestTest
), "Return value should have been \"TestTest\" instead of %s\n", wine_dbgstr_w(V_BSTR(&varresult
)));
1090 VariantClear(&varresult
);
1092 /* call SetOleColor with large negative VT_I4 param */
1093 VariantInit(&vararg
[0]);
1094 V_VT(&vararg
[0]) = VT_I4
;
1095 V_I4(&vararg
[0]) = 0x80000005;
1096 dispparams
.cNamedArgs
= 0;
1097 dispparams
.cArgs
= 1;
1098 dispparams
.rgdispidNamedArgs
= NULL
;
1099 dispparams
.rgvarg
= vararg
;
1100 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_SETOLECOLOR
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, &excepinfo
, NULL
);
1101 ok_ole_success(hr
, IDispatch_Invoke
);
1103 /* call GetOleColor */
1104 dispparams
.cNamedArgs
= 0;
1105 dispparams
.cArgs
= 0;
1106 dispparams
.rgdispidNamedArgs
= NULL
;
1107 dispparams
.rgvarg
= NULL
;
1108 VariantInit(&varresult
);
1109 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_GETOLECOLOR
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1110 ok_ole_success(hr
, IDispatch_Invoke
);
1111 VariantClear(&varresult
);
1113 /* call StructArgs (direct) */
1114 mystruct
= MYSTRUCT_BYPTR
;
1115 memcpy(mystructArray
, MYSTRUCT_ARRAY
, sizeof(mystructArray
));
1116 hr
= IWidget_StructArgs(pWidget
, MYSTRUCT_BYVAL
, &mystruct
, mystructArray
);
1117 ok_ole_success(hr
, IWidget_StructArgs
);
1120 dispparams
.cNamedArgs
= 0;
1121 dispparams
.cArgs
= 0;
1122 dispparams
.rgdispidNamedArgs
= NULL
;
1123 dispparams
.rgvarg
= NULL
;
1124 VariantInit(&varresult
);
1125 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1126 ok_ole_success(hr
, IDispatch_Invoke
);
1127 ok(V_VT(&varresult
) == VT_DISPATCH
, "vt %x\n", V_VT(&varresult
));
1128 VariantClear(&varresult
);
1130 /* call CloneInterface */
1131 dispparams
.cNamedArgs
= 0;
1132 dispparams
.cArgs
= 0;
1133 dispparams
.rgdispidNamedArgs
= NULL
;
1134 dispparams
.rgvarg
= NULL
;
1135 VariantInit(&varresult
);
1136 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONEINTERFACE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1137 ok_ole_success(hr
, IDispatch_Invoke
);
1138 ok(V_VT(&varresult
) == VT_DISPATCH
, "vt %x\n", V_VT(&varresult
));
1139 VariantClear(&varresult
);
1141 /* call CloneDispatch with automatic value getting */
1142 V_VT(&vararg
[0]) = VT_I2
;
1143 V_I2(&vararg
[0]) = 1;
1144 dispparams
.cNamedArgs
= 0;
1145 dispparams
.rgdispidNamedArgs
= NULL
;
1146 dispparams
.cArgs
= 1;
1147 dispparams
.rgvarg
= vararg
;
1148 VariantInit(&varresult
);
1149 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONEDISPATCH
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1150 ok_ole_success(hr
, IDispatch_Invoke
);
1152 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1153 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1154 excepinfo
.wCode
, excepinfo
.scode
);
1156 ok(V_VT(&varresult
) == VT_I2
, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult
));
1157 ok(V_I2(&varresult
) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult
));
1158 VariantClear(&varresult
);
1160 /* call CloneCoclass */
1161 dispparams
.cNamedArgs
= 0;
1162 dispparams
.cArgs
= 0;
1163 dispparams
.rgdispidNamedArgs
= NULL
;
1164 dispparams
.rgvarg
= NULL
;
1165 VariantInit(&varresult
);
1166 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONECOCLASS
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1167 ok_ole_success(hr
, IDispatch_Invoke
);
1169 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1170 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1171 excepinfo
.wCode
, excepinfo
.scode
);
1173 ok(V_VT(&varresult
) == VT_DISPATCH
, "V_VT(&varresult) was %d instead of VT_DISPATCH\n", V_VT(&varresult
));
1174 ok(!V_DISPATCH(&varresult
), "V_DISPATCH(&varresult) should be NULL instead of %p\n", V_DISPATCH(&varresult
));
1175 VariantClear(&varresult
);
1177 /* call Value with a VT_VARIANT|VT_BYREF type */
1178 V_VT(&vararg
[0]) = VT_VARIANT
|VT_BYREF
;
1179 V_VARIANTREF(&vararg
[0]) = &vararg
[1];
1180 V_VT(&vararg
[1]) = VT_I2
;
1181 V_I2(&vararg
[1]) = 1;
1182 dispparams
.cNamedArgs
= 0;
1183 dispparams
.rgdispidNamedArgs
= NULL
;
1184 dispparams
.cArgs
= 1;
1185 dispparams
.rgvarg
= vararg
;
1186 VariantInit(&varresult
);
1187 hr
= IDispatch_Invoke(pDispatch
, DISPID_VALUE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1188 ok_ole_success(hr
, IDispatch_Invoke
);
1190 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1191 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1192 excepinfo
.wCode
, excepinfo
.scode
);
1194 ok(V_VT(&varresult
) == VT_I2
, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult
));
1195 ok(V_I2(&varresult
) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult
));
1196 VariantClear(&varresult
);
1198 /* call Variant - exercises variant copying in ITypeInfo::Invoke and
1199 * handling of void return types */
1200 /* use a big type to ensure that the variant was properly copied into the
1201 * destination function's args */
1202 V_VT(&vararg
[0]) = VT_CY
;
1203 S(V_CY(&vararg
[0])).Hi
= 0xdababe;
1204 S(V_CY(&vararg
[0])).Lo
= 0xdeadbeef;
1205 dispparams
.cNamedArgs
= 0;
1206 dispparams
.cArgs
= 1;
1207 dispparams
.rgdispidNamedArgs
= NULL
;
1208 dispparams
.rgvarg
= vararg
;
1209 VariantInit(&varresult
);
1210 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARIANT
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1211 ok_ole_success(hr
, IDispatch_Invoke
);
1212 VariantClear(&varresult
);
1215 VariantInit(&vararg
[3]);
1216 V_VT(&vararg
[3]) = VT_I4
;
1217 V_I4(&vararg
[3]) = 3;
1218 VariantInit(&vararg
[2]);
1219 V_VT(&vararg
[2]) = VT_I4
;
1220 V_I4(&vararg
[2]) = 0;
1221 VariantInit(&vararg
[1]);
1222 V_VT(&vararg
[1]) = VT_I4
;
1223 V_I4(&vararg
[1]) = 1;
1224 VariantInit(&vararg
[0]);
1225 V_VT(&vararg
[0]) = VT_I4
;
1226 V_I4(&vararg
[0]) = 2;
1227 dispparams
.cNamedArgs
= 0;
1228 dispparams
.cArgs
= 4;
1229 dispparams
.rgdispidNamedArgs
= NULL
;
1230 dispparams
.rgvarg
= vararg
;
1231 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARARG
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1232 ok_ole_success(hr
, ITypeInfo_Invoke
);
1234 /* call VarArg, even one (non-optional, non-safearray) named argument is not allowed */
1236 dispparams
.cNamedArgs
= 1;
1237 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1238 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARARG
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1239 ok(hr
== DISP_E_NONAMEDARGS
, "IDispatch_Invoke should have returned DISP_E_NONAMEDARGS instead of 0x%08x\n", hr
);
1240 dispidNamed
= DISPID_PROPERTYPUT
;
1243 dispparams
.cNamedArgs
= 0;
1244 dispparams
.cArgs
= 0;
1245 dispparams
.rgdispidNamedArgs
= NULL
;
1246 dispparams
.rgvarg
= NULL
;
1247 VariantInit(&varresult
);
1248 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_ERROR
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, &excepinfo
, NULL
);
1249 ok(hr
== DISP_E_EXCEPTION
, "IDispatch_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr
);
1250 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== E_NOTIMPL
,
1251 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1252 excepinfo
.wCode
, excepinfo
.scode
);
1253 VariantClear(&varresult
);
1256 pTypeInfo
= NonOleAutomation_GetTypeInfo();
1257 dispparams
.cNamedArgs
= 0;
1258 dispparams
.cArgs
= 0;
1259 dispparams
.rgdispidNamedArgs
= NULL
;
1260 dispparams
.rgvarg
= NULL
;
1261 VariantInit(&varresult
);
1262 hr
= ITypeInfo_Invoke(pTypeInfo
, &NonOleAutomation
, DISPID_NOA_BSTRRET
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1263 ok_ole_success(hr
, ITypeInfo_Invoke
);
1264 ok(V_VT(&varresult
) == VT_BSTR
, "V_VT(&varresult) should be VT_BSTR instead of %d\n", V_VT(&varresult
));
1265 ok(V_BSTR(&varresult
) != NULL
, "V_BSTR(&varresult) should not be NULL\n");
1267 VariantClear(&varresult
);
1269 dispparams
.cNamedArgs
= 0;
1270 dispparams
.cArgs
= 0;
1271 dispparams
.rgdispidNamedArgs
= NULL
;
1272 dispparams
.rgvarg
= NULL
;
1273 hr
= ITypeInfo_Invoke(pTypeInfo
, &NonOleAutomation
, DISPID_NOA_ERROR
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1274 ok(hr
== DISP_E_EXCEPTION
, "ITypeInfo_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr
);
1275 ok(V_VT(&varresult
) == VT_EMPTY
, "V_VT(&varresult) should be VT_EMPTY instead of %d\n", V_VT(&varresult
));
1276 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== E_NOTIMPL
,
1277 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1278 excepinfo
.wCode
, excepinfo
.scode
);
1279 VariantClear(&varresult
);
1281 ITypeInfo_Release(pTypeInfo
);
1283 /* tests call put_Name without named arg */
1284 VariantInit(&vararg
[0]);
1285 dispparams
.cNamedArgs
= 0;
1286 dispparams
.rgdispidNamedArgs
= NULL
;
1287 dispparams
.cArgs
= 1;
1288 dispparams
.rgvarg
= vararg
;
1289 VariantInit(&varresult
);
1290 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1291 ok(hr
== DISP_E_PARAMNOTFOUND
, "IDispatch_Invoke should have returned DISP_E_PARAMNOTFOUND instead of 0x%08x\n", hr
);
1292 VariantClear(&varresult
);
1294 /* tests param type that cannot be coerced */
1295 VariantInit(&vararg
[0]);
1296 V_VT(&vararg
[0]) = VT_UNKNOWN
;
1297 V_UNKNOWN(&vararg
[0]) = NULL
;
1298 dispparams
.cNamedArgs
= 1;
1299 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1300 dispparams
.cArgs
= 1;
1301 dispparams
.rgvarg
= vararg
;
1302 VariantInit(&varresult
);
1303 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1304 ok(hr
== DISP_E_TYPEMISMATCH
, "IDispatch_Invoke should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hr
);
1305 VariantClear(&varresult
);
1307 /* tests bad param type */
1308 VariantInit(&vararg
[0]);
1309 V_VT(&vararg
[0]) = VT_CLSID
;
1310 V_BYREF(&vararg
[0]) = NULL
;
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_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1317 ok(hr
== DISP_E_BADVARTYPE
, "IDispatch_Invoke should have returned DISP_E_BADVARTYPE instead of 0x%08x\n", hr
);
1318 VariantClear(&varresult
);
1320 /* tests too small param count */
1321 dispparams
.cNamedArgs
= 0;
1322 dispparams
.rgdispidNamedArgs
= NULL
;
1323 dispparams
.cArgs
= 0;
1324 dispparams
.rgvarg
= NULL
;
1325 VariantInit(&varresult
);
1326 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_DOSOMETHING
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1327 ok(hr
== DISP_E_BADPARAMCOUNT
, "IDispatch_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr
);
1328 VariantClear(&varresult
);
1330 /* tests propget function with large param count */
1331 VariantInit(&vararg
[0]);
1332 V_VT(&vararg
[0]) = VT_BSTR
;
1333 V_BSTR(&vararg
[0]) = NULL
;
1334 V_VT(&vararg
[1]) = VT_I4
;
1335 V_I4(&vararg
[1]) = 1;
1336 dispparams
.cNamedArgs
= 0;
1337 dispparams
.cArgs
= 2;
1338 dispparams
.rgdispidNamedArgs
= NULL
;
1339 dispparams
.rgvarg
= vararg
;
1340 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_STATE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1341 ok(hr
== DISP_E_NOTACOLLECTION
, "IDispatch_Invoke should have returned DISP_E_NOTACOLLECTION instead of 0x%08x\n", hr
);
1343 /* test propput with lcid */
1345 /* the lcid passed to the function is the first lcid in the typelib header.
1346 Since we don't explicitly set an lcid in the idl, it'll default to US English. */
1347 VariantInit(&vararg
[0]);
1348 V_VT(&vararg
[0]) = VT_I4
;
1349 V_I4(&vararg
[0]) = 0xcafe;
1350 dispparams
.cNamedArgs
= 1;
1351 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1352 dispparams
.cArgs
= 1;
1353 dispparams
.rgvarg
= vararg
;
1354 VariantInit(&varresult
);
1355 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_WITH_LCID
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1356 ok_ole_success(hr
, ITypeInfo_Invoke
);
1357 VariantClear(&varresult
);
1359 /* test propget with lcid */
1360 dispparams
.cNamedArgs
= 0;
1361 dispparams
.cArgs
= 0;
1362 dispparams
.rgvarg
= NULL
;
1363 dispparams
.rgdispidNamedArgs
= NULL
;
1364 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_WITH_LCID
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1365 ok_ole_success(hr
, ITypeInfo_Invoke
);
1366 ok(V_VT(&varresult
) == VT_I4
, "got %x\n", V_VT(&varresult
));
1367 ok(V_I4(&varresult
) == 0x409, "got %x\n", V_I4(&varresult
));
1368 VariantClear(&varresult
);
1370 /* test propget of INT value */
1371 dispparams
.cNamedArgs
= 0;
1372 dispparams
.cArgs
= 0;
1373 dispparams
.rgvarg
= NULL
;
1374 dispparams
.rgdispidNamedArgs
= NULL
;
1375 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_INT
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1376 ok_ole_success(hr
, ITypeInfo_Invoke
);
1377 ok(V_VT(&varresult
) == VT_I4
, "got %x\n", V_VT(&varresult
));
1378 ok(V_I4(&varresult
) == -13, "got %x\n", V_I4(&varresult
));
1379 VariantClear(&varresult
);
1381 /* test propget of INT value */
1382 dispparams
.cNamedArgs
= 0;
1383 dispparams
.cArgs
= 0;
1384 dispparams
.rgvarg
= NULL
;
1385 dispparams
.rgdispidNamedArgs
= NULL
;
1386 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_UINT
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1387 ok_ole_success(hr
, ITypeInfo_Invoke
);
1388 ok(V_VT(&varresult
) == VT_UI4
, "got %x\n", V_VT(&varresult
));
1389 ok(V_UI4(&varresult
) == 42, "got %x\n", V_UI4(&varresult
));
1390 VariantClear(&varresult
);
1392 /* test byref marshalling */
1394 VariantInit(&vararg
[0]);
1395 V_VT(&vararg
[0]) = VT_UI4
|VT_BYREF
;
1396 V_UI4REF(&vararg
[0]) = &uval
;
1397 dispparams
.cNamedArgs
= 0;
1398 dispparams
.cArgs
= 1;
1399 dispparams
.rgvarg
= vararg
;
1400 dispparams
.rgdispidNamedArgs
= NULL
;
1401 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_BYREF_UINT
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1402 ok_ole_success(hr
, ITypeInfo_Invoke
);
1403 ok(V_VT(&varresult
) == VT_EMPTY
, "varresult should be VT_EMPTY\n");
1404 ok(V_VT(&vararg
[0]) == (VT_UI4
|VT_BYREF
), "arg VT not unmarshalled correctly: %x\n", V_VT(&vararg
[0]));
1405 ok(V_UI4REF(&vararg
[0]) == &uval
, "Byref pointer not preserved: %p/%p\n", &uval
, V_UI4REF(&vararg
[0]));
1406 ok(*V_UI4REF(&vararg
[0]) == 42, "Expected 42 to be returned instead of %u\n", *V_UI4REF(&vararg
[0]));
1407 VariantClear(&varresult
);
1408 VariantClear(&vararg
[0]);
1410 /* test propput with optional argument. */
1411 VariantInit(&vararg
[0]);
1412 V_VT(&vararg
[0]) = VT_I4
;
1413 V_I4(&vararg
[0]) = 0xcafe;
1414 dispparams
.cNamedArgs
= 1;
1415 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1416 dispparams
.cArgs
= 1;
1417 dispparams
.rgvarg
= vararg
;
1418 VariantInit(&varresult
);
1419 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_OPT_ARG
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1420 ok_ole_success(hr
, ITypeInfo_Invoke
);
1421 VariantClear(&varresult
);
1423 /* test propput with required argument. */
1424 VariantInit(&vararg
[0]);
1425 VariantInit(&vararg
[1]);
1426 V_VT(&vararg
[0]) = VT_I4
;
1427 V_I4(&vararg
[0]) = 0x1234;
1428 V_VT(&vararg
[1]) = VT_I4
;
1429 V_I4(&vararg
[1]) = 0x5678;
1430 dispparams
.cNamedArgs
= 1;
1431 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1432 dispparams
.cArgs
= 2;
1433 dispparams
.rgvarg
= vararg
;
1434 VariantInit(&varresult
);
1435 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_REQ_ARG
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1436 ok_ole_success(hr
, ITypeInfo_Invoke
);
1437 VariantClear(&varresult
);
1439 IDispatch_Release(pDispatch
);
1440 IWidget_Release(pWidget
);
1442 trace("calling end_host_object\n");
1443 end_host_object(tid
, thread
);
1446 static void test_DispCallFunc(void)
1448 static const WCHAR szEmpty
[] = { 0 };
1449 VARTYPE rgvt
[] = { VT_R8
, VT_BSTR
, VT_BSTR
, VT_VARIANT
|VT_BYREF
};
1450 VARIANTARG vararg
[4];
1452 VARIANTARG
*rgpvarg
[4] = { &vararg
[0], &vararg
[1], &vararg
[2], &vararg
[3] };
1453 VARIANTARG varresult
;
1455 IWidget
*pWidget
= Widget_Create();
1456 V_VT(&vararg
[0]) = VT_R8
;
1457 V_R8(&vararg
[0]) = 3.141;
1458 V_VT(&vararg
[1]) = VT_BSTR
;
1459 V_BSTRREF(&vararg
[1]) = CoTaskMemAlloc(sizeof(BSTR
));
1460 V_VT(&vararg
[2]) = VT_BSTR
;
1461 V_BSTR(&vararg
[2]) = SysAllocString(szEmpty
);
1462 V_VT(&vararg
[3]) = VT_VARIANT
|VT_BYREF
;
1463 V_VARIANTREF(&vararg
[3]) = &varref
;
1464 V_VT(&varref
) = VT_ERROR
;
1465 V_ERROR(&varref
) = DISP_E_PARAMNOTFOUND
;
1466 VariantInit(&varresult
);
1467 hr
= DispCallFunc(pWidget
, 9*sizeof(void*), CC_STDCALL
, VT_UI4
, 4, rgvt
, rgpvarg
, &varresult
);
1468 ok_ole_success(hr
, DispCallFunc
);
1469 VariantClear(&varresult
);
1470 SysFreeString(*V_BSTRREF(&vararg
[1]));
1471 CoTaskMemFree(V_BSTRREF(&vararg
[1]));
1472 VariantClear(&vararg
[2]);
1473 IWidget_Release(pWidget
);
1476 static void test_StaticWidget(void)
1478 ITypeInfo
*type_info
;
1479 DISPPARAMS dispparams
;
1480 VARIANTARG vararg
[4];
1481 EXCEPINFO excepinfo
;
1485 type_info
= get_type_info(&IID_IStaticWidget
);
1488 dispparams
.cNamedArgs
= 0;
1489 dispparams
.cArgs
= 1;
1490 dispparams
.rgdispidNamedArgs
= NULL
;
1491 dispparams
.rgvarg
= vararg
;
1492 V_VT(vararg
) = VT_DISPATCH
;
1493 V_DISPATCH(vararg
) = (IDispatch
*)&TestDualDisp
;
1494 VariantInit(&varresult
);
1495 hr
= ITypeInfo_Invoke(type_info
, &StaticWidget
, DISPID_TM_TESTDUAL
, DISPATCH_METHOD
,
1496 &dispparams
, &varresult
, &excepinfo
, NULL
);
1497 ok_ole_success(hr
, IDispatch_Invoke
);
1498 ok(V_VT(&varresult
) == VT_EMPTY
, "vt %x\n", V_VT(&varresult
));
1499 VariantClear(&varresult
);
1501 ITypeInfo_Release(type_info
);
1504 static void test_libattr(void)
1510 hr
= LoadRegTypeLib(&LIBID_TestTypelib
, 1, 0, LOCALE_NEUTRAL
, &pTypeLib
);
1511 ok_ole_success(hr
, LoadRegTypeLib
);
1515 hr
= ITypeLib_GetLibAttr(pTypeLib
, &pattr
);
1516 ok_ole_success(hr
, GetLibAttr
);
1519 ok(pattr
->lcid
== MAKELANGID(LANG_NEUTRAL
, SUBLANG_NEUTRAL
), "lcid %x\n", pattr
->lcid
);
1521 ITypeLib_ReleaseTLibAttr(pTypeLib
, pattr
);
1524 ITypeLib_Release(pTypeLib
);
1527 START_TEST(tmarshal
)
1531 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1533 hr
= register_current_module_typelib();
1534 ok_ole_success(hr
, register_current_module_typelib
);
1536 test_typelibmarshal();
1537 test_DispCallFunc();
1538 test_StaticWidget();
1541 hr
= UnRegisterTypeLib(&LIBID_TestTypelib
, 1, 0, LOCALE_NEUTRAL
,
1542 sizeof(void*) == 8 ? SYS_WIN64
: SYS_WIN32
);
1543 ok_ole_success(hr
, UnRegisterTypeLib
);