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 const struct IWidgetVtbl Widget_VTable =
608 Widget_QueryInterface,
611 Widget_GetTypeInfoCount,
613 Widget_GetIDsOfNames,
624 Widget_CloneDispatch,
628 Widget_VariantArrayPtr,
633 Widget_CloneInterface,
634 Widget_put_prop_with_lcid,
635 Widget_get_prop_with_lcid,
637 Widget_get_prop_uint,
639 Widget_put_prop_opt_arg,
642 static HRESULT WINAPI StaticWidget_QueryInterface(IStaticWidget *iface, REFIID riid, void **ppvObject)
644 if (IsEqualIID(riid, &IID_IStaticWidget) || IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch))
646 IStaticWidget_AddRef(iface);
652 return E_NOINTERFACE;
655 static ULONG WINAPI StaticWidget_AddRef(IStaticWidget *iface)
660 static ULONG WINAPI StaticWidget_Release(IStaticWidget *iface)
665 static HRESULT WINAPI StaticWidget_GetTypeInfoCount(IStaticWidget *iface, UINT *pctinfo)
667 ok(0, "unexpected call\n");
671 static HRESULT WINAPI StaticWidget_GetTypeInfo(IStaticWidget *iface, UINT iTInfo, LCID lcid,
674 ok(0, "unexpected call\n");
678 static HRESULT WINAPI StaticWidget_GetIDsOfNames(IStaticWidget *iface, REFIID riid, LPOLESTR *rgszNames,
679 UINT cNames, LCID lcid, DISPID *rgDispId)
681 ok(0, "unexpected call\n");
685 static HRESULT WINAPI StaticWidget_Invoke(IStaticWidget *iface, DISPID dispIdMember, REFIID riid,
686 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
689 ok(0, "unexpected call\n");
693 static HRESULT WINAPI StaticWidget_TestDual(IStaticWidget *iface, ItestDual *p)
695 trace("TestDual()\n");
697 ok(p == &TestDual, "wrong ItestDual\n");
701 static const IStaticWidgetVtbl StaticWidgetVtbl = {
702 StaticWidget_QueryInterface,
704 StaticWidget_Release,
705 StaticWidget_GetTypeInfoCount,
706 StaticWidget_GetTypeInfo,
707 StaticWidget_GetIDsOfNames,
709 StaticWidget_TestDual
712 static IStaticWidget StaticWidget = { &StaticWidgetVtbl };
714 typedef struct KindaEnum
716 const IKindaEnumWidgetVtbl *lpVtbl;
720 static HRESULT register_current_module_typelib(void)
722 WCHAR path[MAX_PATH];
723 CHAR pathA[MAX_PATH];
727 GetModuleFileNameA(NULL, pathA, MAX_PATH);
728 MultiByteToWideChar(CP_ACP, 0, pathA, -1, path, MAX_PATH);
730 hr = LoadTypeLib(path, &typelib);
733 hr = RegisterTypeLib(typelib, path, NULL);
734 ITypeLib_Release(typelib);
739 static ITypeInfo *get_type_info(REFIID riid)
741 ITypeInfo *pTypeInfo;
745 hr = LoadRegTypeLib(&LIBID_TestTypelib, 1, 0, LOCALE_NEUTRAL, &pTypeLib);
746 ok_ole_success(hr, LoadRegTypeLib);
750 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, riid, &pTypeInfo);
751 ITypeLib_Release(pTypeLib);
752 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
759 static IWidget *Widget_Create(void)
762 ITypeInfo *pTypeInfo;
765 pTypeInfo = get_type_info(&IID_IWidget);
769 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
770 This->lpVtbl = &Widget_VTable;
772 This->pDispatchUnknown = NULL;
774 hr = CreateStdDispatch((IUnknown *)&This->lpVtbl, This, pTypeInfo, &This->pDispatchUnknown);
775 ok_ole_success(hr, CreateStdDispatch);
776 ITypeInfo_Release(pTypeInfo);
779 return (IWidget *)&This->lpVtbl;
782 HeapFree(GetProcessHeap(), 0, This);
787 static HRESULT WINAPI KindaEnum_QueryInterface(
788 IKindaEnumWidget *iface,
789 /* [in] */ REFIID riid,
790 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
792 if (IsEqualIID(riid, &IID_IKindaEnumWidget) || IsEqualIID(riid, &IID_IUnknown))
794 IKindaEnumWidget_AddRef(iface);
801 return E_NOINTERFACE;
805 static ULONG WINAPI KindaEnum_AddRef(
806 IKindaEnumWidget *iface)
808 KindaEnum *This = (KindaEnum *)iface;
810 return InterlockedIncrement(&This->refs);
813 static ULONG WINAPI KindaEnum_Release(
814 IKindaEnumWidget *iface)
816 KindaEnum *This = (KindaEnum *)iface;
817 ULONG refs = InterlockedDecrement(&This->refs);
820 memset(This, 0xcc, sizeof(*This));
821 HeapFree(GetProcessHeap(), 0, This);
822 trace("KindaEnumWidget destroyed!\n");
828 static HRESULT WINAPI KindaEnum_Next(
829 IKindaEnumWidget *iface,
830 /* [out] */ IWidget __RPC_FAR *__RPC_FAR *widget)
832 *widget = Widget_Create();
836 return E_OUTOFMEMORY;
839 static HRESULT WINAPI KindaEnum_Count(
840 IKindaEnumWidget *iface,
841 /* [out] */ ULONG __RPC_FAR *count)
846 static HRESULT WINAPI KindaEnum_Reset(
847 IKindaEnumWidget *iface)
852 static HRESULT WINAPI KindaEnum_Clone(
853 IKindaEnumWidget *iface,
854 /* [out] */ IKindaEnumWidget __RPC_FAR *__RPC_FAR *ppenum)
859 static const IKindaEnumWidgetVtbl KindaEnumWidget_VTable =
861 KindaEnum_QueryInterface,
870 static IKindaEnumWidget *KindaEnumWidget_Create(void)
874 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
875 if (!This) return NULL;
876 This->lpVtbl = &KindaEnumWidget_VTable;
878 return (IKindaEnumWidget *)This;
881 static HRESULT WINAPI NonOleAutomation_QueryInterface(INonOleAutomation *iface, REFIID riid, void **ppv)
883 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_INonOleAutomation))
885 *(INonOleAutomation **)ppv = iface;
889 return E_NOINTERFACE;
892 static ULONG WINAPI NonOleAutomation_AddRef(INonOleAutomation *iface)
897 static ULONG WINAPI NonOleAutomation_Release(INonOleAutomation *iface)
902 static BSTR WINAPI NonOleAutomation_BstrRet(INonOleAutomation *iface)
904 static const WCHAR wszTestString[] = {'T','h','i','s',' ','i','s',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0};
905 return SysAllocString(wszTestString);
908 static HRESULT WINAPI NonOleAutomation_Error(INonOleAutomation *iface)
913 static INonOleAutomationVtbl NonOleAutomation_VTable =
915 NonOleAutomation_QueryInterface,
916 NonOleAutomation_AddRef,
917 NonOleAutomation_Release,
918 NonOleAutomation_BstrRet,
919 NonOleAutomation_Error
922 static INonOleAutomation NonOleAutomation = { &NonOleAutomation_VTable };
924 static ITypeInfo *NonOleAutomation_GetTypeInfo(void)
927 HRESULT hr = LoadRegTypeLib(&LIBID_TestTypelib, 1, 0, LOCALE_NEUTRAL, &pTypeLib);
928 ok_ole_success(hr, LoadRegTypeLib);
931 ITypeInfo *pTypeInfo;
932 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_INonOleAutomation, &pTypeInfo);
933 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
934 ITypeLib_Release(pTypeLib);
940 static void test_typelibmarshal(void)
942 static const WCHAR szCat[] = { 'C','a','t',0 };
943 static const WCHAR szTestTest[] = { 'T','e','s','t','T','e','s','t',0 };
944 static WCHAR szSuperman[] = { 'S','u','p','e','r','m','a','n',0 };
946 IKindaEnumWidget *pKEW = KindaEnumWidget_Create();
949 IDispatch *pDispatch;
950 static const LARGE_INTEGER ullZero;
953 DISPID dispidNamed = DISPID_PROPERTYPUT;
954 DISPPARAMS dispparams;
955 VARIANTARG vararg[4];
960 ITypeInfo *pTypeInfo;
962 MYSTRUCT mystructArray[5];
965 ok(pKEW != NULL, "Widget creation failed\n");
967 hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
968 ok_ole_success(hr, CreateStreamOnHGlobal);
969 tid = start_host_object(pStream, &IID_IKindaEnumWidget, (IUnknown *)pKEW, MSHLFLAGS_NORMAL, &thread);
970 IKindaEnumWidget_Release(pKEW);
972 IStream_Seek(pStream, ullZero, STREAM_SEEK_SET, NULL);
973 hr = CoUnmarshalInterface(pStream, &IID_IKindaEnumWidget, (void **)&pKEW);
974 ok_ole_success(hr, CoUnmarshalInterface);
975 IStream_Release(pStream);
977 hr = IKindaEnumWidget_Next(pKEW, &pWidget);
978 ok_ole_success(hr, IKindaEnumWidget_Next);
980 IKindaEnumWidget_Release(pKEW);
982 hr = IWidget_QueryInterface(pWidget, &IID_IDispatch, (void **)&pDispatch);
985 VariantInit(&vararg[0]);
986 dispparams.cNamedArgs = 1;
987 dispparams.rgdispidNamedArgs = &dispidNamed;
988 dispparams.cArgs = 1;
989 dispparams.rgvarg = vararg;
990 VariantInit(&varresult);
991 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
992 ok_ole_success(hr, IDispatch_Invoke);
993 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
994 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
995 excepinfo.wCode, excepinfo.scode);
996 VariantClear(&varresult);
998 /* call put_Name (direct) */
999 bstr = SysAllocString(szSuperman);
1000 hr = IWidget_put_Name(pWidget, bstr);
1001 ok_ole_success(hr, IWidget_put_Name);
1002 SysFreeString(bstr);
1005 dispparams.cNamedArgs = 0;
1006 dispparams.rgdispidNamedArgs = NULL;
1007 dispparams.cArgs = 0;
1008 dispparams.rgvarg = NULL;
1009 VariantInit(&varresult);
1010 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1011 ok_ole_success(hr, IDispatch_Invoke);
1012 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1013 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1014 excepinfo.wCode, excepinfo.scode);
1015 trace("Name = %s\n", wine_dbgstr_w(V_BSTR(&varresult)));
1016 VariantClear(&varresult);
1018 /* call get_Name (direct) */
1020 hr = IWidget_get_Name(pWidget, &bstr);
1021 ok_ole_success(hr, IWidget_get_Name);
1022 ok(!lstrcmpW(bstr, szCat), "IWidget_get_Name should have returned string \"Cat\" instead of %s\n", wine_dbgstr_w(bstr));
1023 SysFreeString(bstr);
1025 /* call DoSomething */
1026 VariantInit(&vararg[0]);
1027 VariantInit(&vararg[1]);
1028 V_VT(&vararg[1]) = VT_R8;
1029 V_R8(&vararg[1]) = 3.141;
1030 dispparams.cNamedArgs = 0;
1031 dispparams.cArgs = 2;
1032 dispparams.rgdispidNamedArgs = NULL;
1033 dispparams.rgvarg = vararg;
1034 VariantInit(&varresult);
1035 hr = IDispatch_Invoke(pDispatch, DISPID_TM_DOSOMETHING, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1036 ok_ole_success(hr, IDispatch_Invoke);
1037 ok(V_VT(&varresult) == VT_EMPTY, "varresult should be VT_EMPTY\n");
1038 VariantClear(&varresult);
1040 /* call get_State */
1041 dispparams.cNamedArgs = 0;
1042 dispparams.cArgs = 0;
1043 dispparams.rgdispidNamedArgs = NULL;
1044 dispparams.rgvarg = NULL;
1045 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1046 ok_ole_success(hr, IDispatch_Invoke);
1047 ok((V_VT(&varresult) == VT_I4) && (V_I4(&varresult) == STATE_WIDGETIFIED), "Return val mismatch\n");
1049 /* call get_State (direct) */
1050 hr = IWidget_get_State(pWidget, &the_state);
1051 ok_ole_success(hr, IWidget_get_state);
1052 ok(the_state == STATE_WIDGETIFIED, "should have returned WIDGET_WIDGETIFIED instead of %d\n", the_state);
1054 /* call put_State */
1055 the_state = STATE_WIDGETIFIED;
1056 VariantInit(&vararg[0]);
1057 V_VT(&vararg[0]) = VT_BYREF|VT_I4;
1058 V_I4REF(&vararg[0]) = (int *)&the_state;
1059 dispparams.cNamedArgs = 1;
1060 dispparams.cArgs = 1;
1061 dispparams.rgdispidNamedArgs = &dispidNamed;
1062 dispparams.rgvarg = vararg;
1063 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1064 ok_ole_success(hr, IDispatch_Invoke);
1067 bstr = SysAllocString(szTestTest);
1068 VariantInit(&vararg[0]);
1069 V_VT(&vararg[0]) = VT_BYREF|VT_BSTR;
1070 V_BSTRREF(&vararg[0]) = &bstr;
1071 dispparams.cNamedArgs = 0;
1072 dispparams.cArgs = 1;
1073 dispparams.rgdispidNamedArgs = NULL;
1074 dispparams.rgvarg = vararg;
1075 VariantInit(&varresult);
1076 hr = IDispatch_Invoke(pDispatch, DISPID_TM_MAP, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1077 ok_ole_success(hr, IDispatch_Invoke);
1078 ok(V_VT(&varresult) == VT_BSTR, "Return value should be of type BSTR instead of %d\n", V_VT(&varresult));
1079 ok(!lstrcmpW(V_BSTR(&varresult), szTestTest), "Return value should have been \"TestTest\" instead of %s\n", wine_dbgstr_w(V_BSTR(&varresult)));
1080 VariantClear(&varresult);
1082 /* call SetOleColor with large negative VT_I4 param */
1083 VariantInit(&vararg[0]);
1084 V_VT(&vararg[0]) = VT_I4;
1085 V_I4(&vararg[0]) = 0x80000005;
1086 dispparams.cNamedArgs = 0;
1087 dispparams.cArgs = 1;
1088 dispparams.rgdispidNamedArgs = NULL;
1089 dispparams.rgvarg = vararg;
1090 hr = IDispatch_Invoke(pDispatch, DISPID_TM_SETOLECOLOR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, &excepinfo, NULL);
1091 ok_ole_success(hr, IDispatch_Invoke);
1093 /* call GetOleColor */
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_GETOLECOLOR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1100 ok_ole_success(hr, IDispatch_Invoke);
1101 VariantClear(&varresult);
1103 /* call StructArgs (direct) */
1104 mystruct = MYSTRUCT_BYPTR;
1105 memcpy(mystructArray, MYSTRUCT_ARRAY, sizeof(mystructArray));
1106 hr = IWidget_StructArgs(pWidget, MYSTRUCT_BYVAL, &mystruct, mystructArray);
1107 ok_ole_success(hr, IWidget_StructArgs);
1110 dispparams.cNamedArgs = 0;
1111 dispparams.cArgs = 0;
1112 dispparams.rgdispidNamedArgs = NULL;
1113 dispparams.rgvarg = NULL;
1114 VariantInit(&varresult);
1115 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1116 ok_ole_success(hr, IDispatch_Invoke);
1117 ok(V_VT(&varresult) == VT_DISPATCH, "vt %x\n", V_VT(&varresult));
1118 VariantClear(&varresult);
1120 /* call CloneInterface */
1121 dispparams.cNamedArgs = 0;
1122 dispparams.cArgs = 0;
1123 dispparams.rgdispidNamedArgs = NULL;
1124 dispparams.rgvarg = NULL;
1125 VariantInit(&varresult);
1126 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONEINTERFACE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1127 ok_ole_success(hr, IDispatch_Invoke);
1128 ok(V_VT(&varresult) == VT_DISPATCH, "vt %x\n", V_VT(&varresult));
1129 VariantClear(&varresult);
1131 /* call CloneDispatch with automatic value getting */
1132 V_VT(&vararg[0]) = VT_I2;
1133 V_I2(&vararg[0]) = 1;
1134 dispparams.cNamedArgs = 0;
1135 dispparams.rgdispidNamedArgs = NULL;
1136 dispparams.cArgs = 1;
1137 dispparams.rgvarg = vararg;
1138 VariantInit(&varresult);
1139 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONEDISPATCH, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1140 ok_ole_success(hr, IDispatch_Invoke);
1142 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1143 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1144 excepinfo.wCode, excepinfo.scode);
1146 ok(V_VT(&varresult) == VT_I2, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult));
1147 ok(V_I2(&varresult) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult));
1148 VariantClear(&varresult);
1150 /* call CloneCoclass */
1151 dispparams.cNamedArgs = 0;
1152 dispparams.cArgs = 0;
1153 dispparams.rgdispidNamedArgs = NULL;
1154 dispparams.rgvarg = NULL;
1155 VariantInit(&varresult);
1156 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONECOCLASS, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1157 ok_ole_success(hr, IDispatch_Invoke);
1159 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1160 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1161 excepinfo.wCode, excepinfo.scode);
1163 ok(V_VT(&varresult) == VT_DISPATCH, "V_VT(&varresult) was %d instead of VT_DISPATCH\n", V_VT(&varresult));
1164 ok(!V_DISPATCH(&varresult), "V_DISPATCH(&varresult) should be NULL instead of %p\n", V_DISPATCH(&varresult));
1165 VariantClear(&varresult);
1167 /* call Value with a VT_VARIANT|VT_BYREF type */
1168 V_VT(&vararg[0]) = VT_VARIANT|VT_BYREF;
1169 V_VARIANTREF(&vararg[0]) = &vararg[1];
1170 V_VT(&vararg[1]) = VT_I2;
1171 V_I2(&vararg[1]) = 1;
1172 dispparams.cNamedArgs = 0;
1173 dispparams.rgdispidNamedArgs = NULL;
1174 dispparams.cArgs = 1;
1175 dispparams.rgvarg = vararg;
1176 VariantInit(&varresult);
1177 hr = IDispatch_Invoke(pDispatch, DISPID_VALUE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1178 ok_ole_success(hr, IDispatch_Invoke);
1180 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1181 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1182 excepinfo.wCode, excepinfo.scode);
1184 ok(V_VT(&varresult) == VT_I2, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult));
1185 ok(V_I2(&varresult) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult));
1186 VariantClear(&varresult);
1188 /* call Variant - exercises variant copying in ITypeInfo::Invoke and
1189 * handling of void return types */
1190 /* use a big type to ensure that the variant was properly copied into the
1191 * destination function's args */
1192 V_VT(&vararg[0]) = VT_CY;
1193 S(V_CY(&vararg[0])).Hi = 0xdababe;
1194 S(V_CY(&vararg[0])).Lo = 0xdeadbeef;
1195 dispparams.cNamedArgs = 0;
1196 dispparams.cArgs = 1;
1197 dispparams.rgdispidNamedArgs = NULL;
1198 dispparams.rgvarg = vararg;
1199 VariantInit(&varresult);
1200 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARIANT, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1201 ok_ole_success(hr, IDispatch_Invoke);
1202 VariantClear(&varresult);
1205 VariantInit(&vararg[3]);
1206 V_VT(&vararg[3]) = VT_I4;
1207 V_I4(&vararg[3]) = 3;
1208 VariantInit(&vararg[2]);
1209 V_VT(&vararg[2]) = VT_I4;
1210 V_I4(&vararg[2]) = 0;
1211 VariantInit(&vararg[1]);
1212 V_VT(&vararg[1]) = VT_I4;
1213 V_I4(&vararg[1]) = 1;
1214 VariantInit(&vararg[0]);
1215 V_VT(&vararg[0]) = VT_I4;
1216 V_I4(&vararg[0]) = 2;
1217 dispparams.cNamedArgs = 0;
1218 dispparams.cArgs = 4;
1219 dispparams.rgdispidNamedArgs = NULL;
1220 dispparams.rgvarg = vararg;
1221 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARARG, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1222 ok_ole_success(hr, ITypeInfo_Invoke);
1224 /* call VarArg, even one (non-optional, non-safearray) named argument is not allowed */
1226 dispparams.cNamedArgs = 1;
1227 dispparams.rgdispidNamedArgs = &dispidNamed;
1228 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARARG, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1229 ok(hr == DISP_E_NONAMEDARGS, "IDispatch_Invoke should have returned DISP_E_NONAMEDARGS instead of 0x%08x\n", hr);
1230 dispidNamed = DISPID_PROPERTYPUT;
1233 dispparams.cNamedArgs = 0;
1234 dispparams.cArgs = 0;
1235 dispparams.rgdispidNamedArgs = NULL;
1236 dispparams.rgvarg = NULL;
1237 VariantInit(&varresult);
1238 hr = IDispatch_Invoke(pDispatch, DISPID_TM_ERROR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, &excepinfo, NULL);
1239 ok(hr == DISP_E_EXCEPTION, "IDispatch_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr);
1240 ok(excepinfo.wCode == 0x0 && excepinfo.scode == E_NOTIMPL,
1241 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1242 excepinfo.wCode, excepinfo.scode);
1243 VariantClear(&varresult);
1246 pTypeInfo = NonOleAutomation_GetTypeInfo();
1247 dispparams.cNamedArgs = 0;
1248 dispparams.cArgs = 0;
1249 dispparams.rgdispidNamedArgs = NULL;
1250 dispparams.rgvarg = NULL;
1251 VariantInit(&varresult);
1252 hr = ITypeInfo_Invoke(pTypeInfo, &NonOleAutomation, DISPID_NOA_BSTRRET, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1253 ok_ole_success(hr, ITypeInfo_Invoke);
1254 ok(V_VT(&varresult) == VT_BSTR, "V_VT(&varresult) should be VT_BSTR instead of %d\n", V_VT(&varresult));
1255 ok(V_BSTR(&varresult) != NULL, "V_BSTR(&varresult) should not be NULL\n");
1257 VariantClear(&varresult);
1259 dispparams.cNamedArgs = 0;
1260 dispparams.cArgs = 0;
1261 dispparams.rgdispidNamedArgs = NULL;
1262 dispparams.rgvarg = NULL;
1263 hr = ITypeInfo_Invoke(pTypeInfo, &NonOleAutomation, DISPID_NOA_ERROR, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1264 ok(hr == DISP_E_EXCEPTION, "ITypeInfo_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr);
1265 ok(V_VT(&varresult) == VT_EMPTY, "V_VT(&varresult) should be VT_EMPTY instead of %d\n", V_VT(&varresult));
1266 ok(excepinfo.wCode == 0x0 && excepinfo.scode == E_NOTIMPL,
1267 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1268 excepinfo.wCode, excepinfo.scode);
1269 VariantClear(&varresult);
1271 ITypeInfo_Release(pTypeInfo);
1273 /* tests call put_Name without named arg */
1274 VariantInit(&vararg[0]);
1275 dispparams.cNamedArgs = 0;
1276 dispparams.rgdispidNamedArgs = NULL;
1277 dispparams.cArgs = 1;
1278 dispparams.rgvarg = vararg;
1279 VariantInit(&varresult);
1280 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1281 ok(hr == DISP_E_PARAMNOTFOUND, "IDispatch_Invoke should have returned DISP_E_PARAMNOTFOUND instead of 0x%08x\n", hr);
1282 VariantClear(&varresult);
1284 /* tests param type that cannot be coerced */
1285 VariantInit(&vararg[0]);
1286 V_VT(&vararg[0]) = VT_UNKNOWN;
1287 V_UNKNOWN(&vararg[0]) = NULL;
1288 dispparams.cNamedArgs = 1;
1289 dispparams.rgdispidNamedArgs = &dispidNamed;
1290 dispparams.cArgs = 1;
1291 dispparams.rgvarg = vararg;
1292 VariantInit(&varresult);
1293 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1294 ok(hr == DISP_E_TYPEMISMATCH, "IDispatch_Invoke should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hr);
1295 VariantClear(&varresult);
1297 /* tests bad param type */
1298 VariantInit(&vararg[0]);
1299 V_VT(&vararg[0]) = VT_CLSID;
1300 V_BYREF(&vararg[0]) = NULL;
1301 dispparams.cNamedArgs = 1;
1302 dispparams.rgdispidNamedArgs = &dispidNamed;
1303 dispparams.cArgs = 1;
1304 dispparams.rgvarg = vararg;
1305 VariantInit(&varresult);
1306 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1307 ok(hr == DISP_E_BADVARTYPE, "IDispatch_Invoke should have returned DISP_E_BADVARTYPE instead of 0x%08x\n", hr);
1308 VariantClear(&varresult);
1310 /* tests too small param count */
1311 dispparams.cNamedArgs = 0;
1312 dispparams.rgdispidNamedArgs = NULL;
1313 dispparams.cArgs = 0;
1314 dispparams.rgvarg = NULL;
1315 VariantInit(&varresult);
1316 hr = IDispatch_Invoke(pDispatch, DISPID_TM_DOSOMETHING, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1317 ok(hr == DISP_E_BADPARAMCOUNT, "IDispatch_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr);
1318 VariantClear(&varresult);
1320 /* tests propget function with large param count */
1321 VariantInit(&vararg[0]);
1322 V_VT(&vararg[0]) = VT_BSTR;
1323 V_BSTR(&vararg[0]) = NULL;
1324 V_VT(&vararg[1]) = VT_I4;
1325 V_I4(&vararg[1]) = 1;
1326 dispparams.cNamedArgs = 0;
1327 dispparams.cArgs = 2;
1328 dispparams.rgdispidNamedArgs = NULL;
1329 dispparams.rgvarg = vararg;
1330 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1331 ok(hr == DISP_E_NOTACOLLECTION, "IDispatch_Invoke should have returned DISP_E_NOTACOLLECTION instead of 0x%08x\n", hr);
1333 /* test propput with lcid */
1335 /* the lcid passed to the function is the first lcid in the typelib header.
1336 Since we don't explicitly set an lcid in the idl, it'll default to US English. */
1337 VariantInit(&vararg[0]);
1338 V_VT(&vararg[0]) = VT_I4;
1339 V_I4(&vararg[0]) = 0xcafe;
1340 dispparams.cNamedArgs = 1;
1341 dispparams.rgdispidNamedArgs = &dispidNamed;
1342 dispparams.cArgs = 1;
1343 dispparams.rgvarg = vararg;
1344 VariantInit(&varresult);
1345 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_WITH_LCID, &IID_NULL, 0x40c, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1346 ok_ole_success(hr, ITypeInfo_Invoke);
1347 VariantClear(&varresult);
1349 /* test propget with lcid */
1350 dispparams.cNamedArgs = 0;
1351 dispparams.cArgs = 0;
1352 dispparams.rgvarg = NULL;
1353 dispparams.rgdispidNamedArgs = NULL;
1354 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_WITH_LCID, &IID_NULL, 0x40c, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1355 ok_ole_success(hr, ITypeInfo_Invoke);
1356 ok(V_VT(&varresult) == VT_I4, "got %x\n", V_VT(&varresult));
1357 ok(V_I4(&varresult) == 0x409, "got %x\n", V_I4(&varresult));
1358 VariantClear(&varresult);
1360 /* test propget of INT value */
1361 dispparams.cNamedArgs = 0;
1362 dispparams.cArgs = 0;
1363 dispparams.rgvarg = NULL;
1364 dispparams.rgdispidNamedArgs = NULL;
1365 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_INT, &IID_NULL, 0x40c, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1366 ok_ole_success(hr, ITypeInfo_Invoke);
1367 ok(V_VT(&varresult) == VT_I4, "got %x\n", V_VT(&varresult));
1368 ok(V_I4(&varresult) == -13, "got %x\n", V_I4(&varresult));
1369 VariantClear(&varresult);
1371 /* test propget of INT value */
1372 dispparams.cNamedArgs = 0;
1373 dispparams.cArgs = 0;
1374 dispparams.rgvarg = NULL;
1375 dispparams.rgdispidNamedArgs = NULL;
1376 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_UINT, &IID_NULL, 0x40c, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1377 ok_ole_success(hr, ITypeInfo_Invoke);
1378 ok(V_VT(&varresult) == VT_UI4, "got %x\n", V_VT(&varresult));
1379 ok(V_UI4(&varresult) == 42, "got %x\n", V_UI4(&varresult));
1380 VariantClear(&varresult);
1382 /* test byref marshalling */
1384 VariantInit(&vararg[0]);
1385 V_VT(&vararg[0]) = VT_UI4|VT_BYREF;
1386 V_UI4REF(&vararg[0]) = &uval;
1387 dispparams.cNamedArgs = 0;
1388 dispparams.cArgs = 1;
1389 dispparams.rgvarg = vararg;
1390 dispparams.rgdispidNamedArgs = NULL;
1391 hr = IDispatch_Invoke(pDispatch, DISPID_TM_BYREF_UINT, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1392 ok_ole_success(hr, ITypeInfo_Invoke);
1393 ok(V_VT(&varresult) == VT_EMPTY, "varresult should be VT_EMPTY\n");
1394 ok(V_VT(&vararg[0]) == (VT_UI4|VT_BYREF), "arg VT not unmarshalled correctly: %x\n", V_VT(&vararg[0]));
1395 ok(V_UI4REF(&vararg[0]) == &uval, "Byref pointer not preserved: %p/%p\n", &uval, V_UI4REF(&vararg[0]));
1396 ok(*V_UI4REF(&vararg[0]) == 42, "Expected 42 to be returned instead of %u\n", *V_UI4REF(&vararg[0]));
1397 VariantClear(&varresult);
1398 VariantClear(&vararg[0]);
1400 /* test propput with optional argument. */
1401 VariantInit(&vararg[0]);
1402 V_VT(&vararg[0]) = VT_I4;
1403 V_I4(&vararg[0]) = 0xcafe;
1404 dispparams.cNamedArgs = 1;
1405 dispparams.rgdispidNamedArgs = &dispidNamed;
1406 dispparams.cArgs = 1;
1407 dispparams.rgvarg = vararg;
1408 VariantInit(&varresult);
1409 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_OPT_ARG, &IID_NULL, 0x40c, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1410 ok_ole_success(hr, ITypeInfo_Invoke);
1411 VariantClear(&varresult);
1413 IDispatch_Release(pDispatch);
1414 IWidget_Release(pWidget);
1416 trace("calling end_host_object\n");
1417 end_host_object(tid, thread);
1420 static void test_DispCallFunc(void)
1422 static const WCHAR szEmpty[] = { 0 };
1423 VARTYPE rgvt[] = { VT_R8, VT_BSTR, VT_BSTR, VT_VARIANT|VT_BYREF };
1424 VARIANTARG vararg[4];
1426 VARIANTARG *rgpvarg[4] = { &vararg[0], &vararg[1], &vararg[2], &vararg[3] };
1427 VARIANTARG varresult;
1429 IWidget *pWidget = Widget_Create();
1430 V_VT(&vararg[0]) = VT_R8;
1431 V_R8(&vararg[0]) = 3.141;
1432 V_VT(&vararg[1]) = VT_BSTR;
1433 V_BSTRREF(&vararg[1]) = CoTaskMemAlloc(sizeof(BSTR));
1434 V_VT(&vararg[2]) = VT_BSTR;
1435 V_BSTR(&vararg[2]) = SysAllocString(szEmpty);
1436 V_VT(&vararg[3]) = VT_VARIANT|VT_BYREF;
1437 V_VARIANTREF(&vararg[3]) = &varref;
1438 V_VT(&varref) = VT_ERROR;
1439 V_ERROR(&varref) = DISP_E_PARAMNOTFOUND;
1440 VariantInit(&varresult);
1441 hr = DispCallFunc(pWidget, 9*sizeof(void*), CC_STDCALL, VT_UI4, 4, rgvt, rgpvarg, &varresult);
1442 ok_ole_success(hr, DispCallFunc);
1443 VariantClear(&varresult);
1444 SysFreeString(*V_BSTRREF(&vararg[1]));
1445 CoTaskMemFree(V_BSTRREF(&vararg[1]));
1446 VariantClear(&vararg[2]);
1447 IWidget_Release(pWidget);
1450 static void test_StaticWidget(void)
1452 ITypeInfo *type_info;
1453 DISPPARAMS dispparams;
1454 VARIANTARG vararg[4];
1455 EXCEPINFO excepinfo;
1459 type_info = get_type_info(&IID_IStaticWidget);
1462 dispparams.cNamedArgs = 0;
1463 dispparams.cArgs = 1;
1464 dispparams.rgdispidNamedArgs = NULL;
1465 dispparams.rgvarg = vararg;
1466 V_VT(vararg) = VT_DISPATCH;
1467 V_DISPATCH(vararg) = (IDispatch*)&TestDualDisp;
1468 VariantInit(&varresult);
1469 hr = ITypeInfo_Invoke(type_info, &StaticWidget, DISPID_TM_TESTDUAL, DISPATCH_METHOD,
1470 &dispparams, &varresult, &excepinfo, NULL);
1471 ok_ole_success(hr, IDispatch_Invoke);
1472 ok(V_VT(&varresult) == VT_EMPTY, "vt %x\n", V_VT(&varresult));
1473 VariantClear(&varresult);
1475 ITypeInfo_Release(type_info);
1478 static void test_libattr(void)
1484 hr = LoadRegTypeLib(&LIBID_TestTypelib, 1, 0, LOCALE_NEUTRAL, &pTypeLib);
1485 ok_ole_success(hr, LoadRegTypeLib);
1489 hr = ITypeLib_GetLibAttr(pTypeLib, &pattr);
1490 ok_ole_success(hr, GetLibAttr);
1493 ok(pattr->lcid == MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), "lcid %x\n", pattr->lcid);
1495 ITypeLib_ReleaseTLibAttr(pTypeLib, pattr);
1498 ITypeLib_Release(pTypeLib);
1501 START_TEST(tmarshal)
1505 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1507 hr = register_current_module_typelib();
1508 ok_ole_success(hr, register_current_module_typelib);
1510 test_typelibmarshal();
1511 test_DispCallFunc();
1512 test_StaticWidget();
1515 hr = UnRegisterTypeLib(&LIBID_TestTypelib, 1, 0, LOCALE_NEUTRAL,
1516 sizeof(void*) == 8 ? SYS_WIN64 : SYS_WIN32);
1517 ok_ole_success(hr, UnRegisterTypeLib);