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 static HRESULT (WINAPI *pVarAdd)(LPVARIANT,LPVARIANT,LPVARIANT);
35 #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%08lx\n", (unsigned long int)hr)
37 /* ULL suffix is not portable */
38 #define ULL_CONST(dw1, dw2) ((((ULONGLONG)dw1) << 32) | (ULONGLONG)dw2)
40 const MYSTRUCT MYSTRUCT_BYVAL = {0x12345678, ULL_CONST(0xdeadbeef, 0x98765432), {0,1,2,3,4,5,6,7}};
41 const MYSTRUCT MYSTRUCT_BYPTR = {0x91827364, ULL_CONST(0x88776655, 0x44332211), {0,1,2,3,4,5,6,7}};
42 const MYSTRUCT MYSTRUCT_ARRAY[5] = {
43 {0x1a1b1c1d, ULL_CONST(0x1e1f1011, 0x12131415), {0,1,2,3,4,5,6,7}},
44 {0x2a2b2c2d, ULL_CONST(0x2e2f2021, 0x22232425), {0,1,2,3,4,5,6,7}},
45 {0x3a3b3c3d, ULL_CONST(0x3e3f3031, 0x32333435), {0,1,2,3,4,5,6,7}},
46 {0x4a4b4c4d, ULL_CONST(0x4e4f4041, 0x42434445), {0,1,2,3,4,5,6,7}},
47 {0x5a5b5c5d, ULL_CONST(0x5e5f5051, 0x52535455), {0,1,2,3,4,5,6,7}},
51 #define RELEASEMARSHALDATA WM_USER
53 struct host_object_data
58 MSHLFLAGS marshal_flags;
60 IMessageFilter *filter;
63 static DWORD CALLBACK host_object_proc(LPVOID p)
65 struct host_object_data *data = p;
69 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
73 IMessageFilter * prev_filter = NULL;
74 hr = CoRegisterMessageFilter(data->filter, &prev_filter);
75 if (prev_filter) IMessageFilter_Release(prev_filter);
76 ok_ole_success(hr, CoRegisterMessageFilter);
79 hr = CoMarshalInterface(data->stream, &data->iid, data->object, MSHCTX_INPROC, NULL, data->marshal_flags);
80 ok_ole_success(hr, CoMarshalInterface);
82 /* force the message queue to be created before signaling parent thread */
83 PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
85 SetEvent(data->marshal_event);
87 while (GetMessage(&msg, NULL, 0, 0))
89 if (msg.hwnd == NULL && msg.message == RELEASEMARSHALDATA)
91 trace("releasing marshal data\n");
92 CoReleaseMarshalData(data->stream);
93 SetEvent((HANDLE)msg.lParam);
96 DispatchMessage(&msg);
99 HeapFree(GetProcessHeap(), 0, data);
106 static DWORD start_host_object2(IStream *stream, REFIID riid, IUnknown *object, MSHLFLAGS marshal_flags, IMessageFilter *filter, HANDLE *thread)
109 HANDLE marshal_event = CreateEvent(NULL, FALSE, FALSE, NULL);
110 struct host_object_data *data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data));
112 data->stream = stream;
114 data->object = object;
115 data->marshal_flags = marshal_flags;
116 data->marshal_event = marshal_event;
117 data->filter = filter;
119 *thread = CreateThread(NULL, 0, host_object_proc, data, 0, &tid);
121 /* wait for marshaling to complete before returning */
122 WaitForSingleObject(marshal_event, INFINITE);
123 CloseHandle(marshal_event);
128 static DWORD start_host_object(IStream *stream, REFIID riid, IUnknown *object, MSHLFLAGS marshal_flags, HANDLE *thread)
130 return start_host_object2(stream, riid, object, marshal_flags, NULL, thread);
134 /* asks thread to release the marshal data because it has to be done by the
135 * same thread that marshaled the interface in the first place. */
136 static void release_host_object(DWORD tid)
138 HANDLE event = CreateEvent(NULL, FALSE, FALSE, NULL);
139 PostThreadMessage(tid, RELEASEMARSHALDATA, 0, (LPARAM)event);
140 WaitForSingleObject(event, INFINITE);
145 static void end_host_object(DWORD tid, HANDLE thread)
147 BOOL ret = PostThreadMessage(tid, WM_QUIT, 0, 0);
148 ok(ret, "PostThreadMessage failed with error %d\n", GetLastError());
149 /* be careful of races - don't return until hosting thread has terminated */
150 WaitForSingleObject(thread, INFINITE);
154 static ItestDual TestDual, TestDualDisp;
156 static HRESULT WINAPI TestSecondIface_QueryInterface(ITestSecondIface *iface, REFIID riid, void **ppv)
158 return ItestDual_QueryInterface(&TestDual, riid, ppv);
161 static ULONG WINAPI TestSecondIface_AddRef(ITestSecondIface *iface)
166 static ULONG WINAPI TestSecondIface_Release(ITestSecondIface *iface)
171 static HRESULT WINAPI TestSecondIface_test(ITestSecondIface *iface)
176 static const ITestSecondIfaceVtbl TestSecondIfaceVtbl = {
177 TestSecondIface_QueryInterface,
178 TestSecondIface_AddRef,
179 TestSecondIface_Release,
183 static ITestSecondIface TestSecondIface = { &TestSecondIfaceVtbl };
185 static HRESULT WINAPI TestDual_QueryInterface(ItestDual *iface, REFIID riid, void **ppvObject)
187 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch)) {
188 *ppvObject = &TestDualDisp;
190 }else if(IsEqualGUID(riid, &IID_ItestDual)) {
191 *ppvObject = &TestDual;
193 }else if(IsEqualGUID(riid, &IID_ITestSecondIface)) {
194 *ppvObject = &TestSecondIface;
199 return E_NOINTERFACE;
202 static ULONG WINAPI TestDual_AddRef(ItestDual *iface)
207 static ULONG WINAPI TestDual_Release(ItestDual *iface)
212 static HRESULT WINAPI TestDual_GetTypeInfoCount(ItestDual *iface, UINT *pctinfo)
214 ok(0, "unexpected call\n");
218 static HRESULT WINAPI TestDual_GetTypeInfo(ItestDual *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
220 ok(0, "unexpected call\n");
224 static HRESULT WINAPI TestDual_GetIDsOfNames(ItestDual *iface, REFIID riid, LPOLESTR *rgszNames,
225 UINT cNames, LCID lcid, DISPID *rgDispId)
227 ok(0, "unexpected call\n");
231 static HRESULT WINAPI TestDual_Invoke(ItestDual *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
232 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
235 ok(0, "unexpected call\n");
239 static ItestDualVtbl TestDualVtbl = {
240 TestDual_QueryInterface,
243 TestDual_GetTypeInfoCount,
244 TestDual_GetTypeInfo,
245 TestDual_GetIDsOfNames,
249 static ItestDual TestDual = { &TestDualVtbl };
250 static ItestDual TestDualDisp = { &TestDualVtbl };
252 typedef struct Widget
254 IWidget IWidget_iface;
256 IUnknown *pDispatchUnknown;
259 static inline Widget *impl_from_IWidget(IWidget *iface)
261 return CONTAINING_RECORD(iface, Widget, IWidget_iface);
264 static HRESULT WINAPI Widget_QueryInterface(
266 /* [in] */ REFIID riid,
267 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
269 if (IsEqualIID(riid, &IID_IWidget) || IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch))
271 IWidget_AddRef(iface);
278 return E_NOINTERFACE;
282 static ULONG WINAPI Widget_AddRef(
285 Widget *This = impl_from_IWidget(iface);
287 return InterlockedIncrement(&This->refs);
290 static ULONG WINAPI Widget_Release(
293 Widget *This = impl_from_IWidget(iface);
294 ULONG refs = InterlockedDecrement(&This->refs);
297 IUnknown_Release(This->pDispatchUnknown);
298 memset(This, 0xcc, sizeof(*This));
299 HeapFree(GetProcessHeap(), 0, This);
300 trace("Widget destroyed!\n");
306 static HRESULT WINAPI Widget_GetTypeInfoCount(
308 /* [out] */ UINT __RPC_FAR *pctinfo)
310 Widget *This = impl_from_IWidget(iface);
311 IDispatch *pDispatch;
312 HRESULT hr = IUnknown_QueryInterface(This->pDispatchUnknown, &IID_IDispatch, (void **)&pDispatch);
315 hr = IDispatch_GetTypeInfoCount(pDispatch, pctinfo);
316 IDispatch_Release(pDispatch);
321 static HRESULT WINAPI Widget_GetTypeInfo(
322 IWidget __RPC_FAR * iface,
323 /* [in] */ UINT iTInfo,
324 /* [in] */ LCID lcid,
325 /* [out] */ ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo)
327 Widget *This = impl_from_IWidget(iface);
328 IDispatch *pDispatch;
329 HRESULT hr = IUnknown_QueryInterface(This->pDispatchUnknown, &IID_IDispatch, (void **)&pDispatch);
332 hr = IDispatch_GetTypeInfo(pDispatch, iTInfo, lcid, ppTInfo);
333 IDispatch_Release(pDispatch);
338 static HRESULT WINAPI Widget_GetIDsOfNames(
339 IWidget __RPC_FAR * iface,
340 /* [in] */ REFIID riid,
341 /* [size_is][in] */ LPOLESTR __RPC_FAR *rgszNames,
342 /* [in] */ UINT cNames,
343 /* [in] */ LCID lcid,
344 /* [size_is][out] */ DISPID __RPC_FAR *rgDispId)
346 Widget *This = impl_from_IWidget(iface);
347 IDispatch *pDispatch;
348 HRESULT hr = IUnknown_QueryInterface(This->pDispatchUnknown, &IID_IDispatch, (void **)&pDispatch);
351 hr = IDispatch_GetIDsOfNames(pDispatch, riid, rgszNames, cNames, lcid, rgDispId);
352 IDispatch_Release(pDispatch);
357 static HRESULT WINAPI Widget_Invoke(
358 IWidget __RPC_FAR * iface,
359 /* [in] */ DISPID dispIdMember,
360 /* [in] */ REFIID riid,
361 /* [in] */ LCID lcid,
362 /* [in] */ WORD wFlags,
363 /* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams,
364 /* [out] */ VARIANT __RPC_FAR *pVarResult,
365 /* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo,
366 /* [out] */ UINT __RPC_FAR *puArgErr)
368 Widget *This = impl_from_IWidget(iface);
369 IDispatch *pDispatch;
370 HRESULT hr = IUnknown_QueryInterface(This->pDispatchUnknown, &IID_IDispatch, (void **)&pDispatch);
373 hr = IDispatch_Invoke(pDispatch, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
374 IDispatch_Release(pDispatch);
379 static HRESULT WINAPI Widget_put_Name(
380 IWidget __RPC_FAR * iface,
381 /* [in] */ BSTR name)
383 trace("put_Name(%s)\n", wine_dbgstr_w(name));
387 static HRESULT WINAPI Widget_get_Name(
388 IWidget __RPC_FAR * iface,
389 /* [out] */ BSTR __RPC_FAR *name)
391 static const WCHAR szCat[] = { 'C','a','t',0 };
392 trace("get_Name()\n");
393 *name = SysAllocString(szCat);
397 static HRESULT WINAPI Widget_DoSomething(
398 IWidget __RPC_FAR * iface,
399 /* [in] */ double number,
400 /* [out] */ BSTR *str1,
401 /* [defaultvalue][in] */ BSTR str2,
402 /* [optional][in] */ VARIANT __RPC_FAR *opt)
404 static const WCHAR szString[] = { 'S','t','r','i','n','g',0 };
405 trace("DoSomething()\n");
407 ok(number == 3.141, "number(%f) != 3.141\n", number);
408 ok(*str2 == '\0', "str2(%s) != \"\"\n", wine_dbgstr_w(str2));
409 ok(V_VT(opt) == VT_ERROR, "V_VT(opt) should be VT_ERROR instead of 0x%x\n", V_VT(opt));
410 ok(V_ERROR(opt) == DISP_E_PARAMNOTFOUND, "V_ERROR(opt) should be DISP_E_PARAMNOTFOUND instead of 0x%08x\n", V_ERROR(opt));
411 *str1 = SysAllocString(szString);
416 static HRESULT WINAPI Widget_get_State(
417 IWidget __RPC_FAR * iface,
418 /* [retval][out] */ STATE __RPC_FAR *state)
420 trace("get_State() = STATE_WIDGETIFIED\n");
421 *state = STATE_WIDGETIFIED;
425 static HRESULT WINAPI Widget_put_State(
426 IWidget __RPC_FAR * iface,
427 /* [in] */ STATE state)
429 trace("put_State(%d)\n", state);
433 static HRESULT WINAPI Widget_Map(
438 trace("Map(%s, %p)\n", wine_dbgstr_w(bstrId), sValue);
439 *sValue = SysAllocString(bstrId);
443 static HRESULT WINAPI Widget_SetOleColor(
447 trace("SetOleColor(0x%x)\n", val);
451 static HRESULT WINAPI Widget_GetOleColor(
455 trace("GetOleColor() = 0x8000000f\n");
460 static HRESULT WINAPI Widget_Clone(
465 return Widget_QueryInterface(iface, &IID_IWidget, (void **)ppVal);
468 static HRESULT WINAPI Widget_CloneDispatch(
472 trace("CloneDispatch()\n");
473 return Widget_QueryInterface(iface, &IID_IWidget, (void **)ppVal);
476 static HRESULT WINAPI Widget_CloneCoclass(
478 ApplicationObject2 **ppVal)
480 trace("CloneCoclass()\n");
484 static HRESULT WINAPI Widget_Value(
485 IWidget __RPC_FAR * iface,
489 trace("Value(%p, %p)\n", value, retval);
490 ok(V_VT(value) == VT_I2, "V_VT(value) was %d instead of VT_I2\n", V_VT(value));
491 ok(V_I2(value) == 1, "V_I2(value) was %d instead of 1\n", V_I2(value));
492 V_VT(retval) = VT_I2;
497 static HRESULT WINAPI Widget_Array(
501 trace("Array(%p)\n", values);
505 static HRESULT WINAPI Widget_VariantArrayPtr(
509 trace("VariantArrayPtr(%p)\n", values);
513 static HRESULT WINAPI Widget_VariantCArray(
520 trace("VariantCArray(%u,%p)\n", count, values);
522 ok(count == 2, "count is %d\n", count);
523 for (i = 0; i < count; i++)
524 ok(V_VT(&values[i]) == VT_I4, "values[%d] is not VT_I4\n", i);
533 for (i = 0; i < count; i++) {
535 hr = pVarAdd(&values[i], &inc, &res);
537 ok(0, "VarAdd failed at %u with error 0x%x\n", i, hr);
540 hr = VariantCopy(&values[i], &res);
542 ok(0, "VariantCopy failed at %u with error 0x%x\n", i, hr);
548 win_skip("VarAdd is not available\n");
553 static HRESULT WINAPI Widget_Variant(
554 IWidget __RPC_FAR * iface,
557 trace("Variant()\n");
558 ok(V_VT(&var) == VT_CY, "V_VT(&var) was %d\n", V_VT(&var));
559 ok(S(V_CY(&var)).Hi == 0xdababe, "V_CY(&var).Hi was 0x%x\n", S(V_CY(&var)).Hi);
560 ok(S(V_CY(&var)).Lo == 0xdeadbeef, "V_CY(&var).Lo was 0x%x\n", S(V_CY(&var)).Lo);
564 static HRESULT WINAPI Widget_VarArg(
569 LONG lbound, ubound, i;
573 trace("VarArg(%p)\n", values);
575 hr = SafeArrayGetLBound(values, 1, &lbound);
576 ok(hr == S_OK, "SafeArrayGetLBound failed with %x\n", hr);
577 ok(lbound == 0, "SafeArrayGetLBound returned %d\n", lbound);
579 hr = SafeArrayGetUBound(values, 1, &ubound);
580 ok(hr == S_OK, "SafeArrayGetUBound failed with %x\n", hr);
581 ok(ubound == numexpect-1, "SafeArrayGetUBound returned %d, but expected %d\n", ubound, numexpect-1);
583 hr = SafeArrayAccessData(values, (LPVOID)&data);
584 ok(hr == S_OK, "SafeArrayAccessData failed with %x\n", hr);
586 for (i=0; i<=ubound-lbound; i++)
588 ok(V_VT(&data[i]) == VT_I4, "V_VT(&data[%d]) was %d\n", i, V_VT(&data[i]));
589 ok(V_I4(&data[i]) == i, "V_I4(&data[%d]) was %d\n", i, V_I4(&data[i]));
592 hr = SafeArrayUnaccessData(values);
593 ok(hr == S_OK, "SafeArrayUnaccessData failed with %x\n", hr);
599 static BOOL mystruct_uint_ordered(MYSTRUCT *mystruct)
602 for (i = 0; i < sizeof(mystruct->uarr)/sizeof(mystruct->uarr[0]); i++)
603 if (mystruct->uarr[i] != i)
609 static HRESULT WINAPI Widget_StructArgs(
616 ok(byval.field1 == MYSTRUCT_BYVAL.field1 &&
617 byval.field2 == MYSTRUCT_BYVAL.field2 &&
618 mystruct_uint_ordered(&byval),
619 "Struct parameter passed by value corrupted\n");
620 ok(byptr->field1 == MYSTRUCT_BYPTR.field1 &&
621 byptr->field2 == MYSTRUCT_BYPTR.field2 &&
622 mystruct_uint_ordered(byptr),
623 "Struct parameter passed by pointer corrupted\n");
624 for (i = 0; i < 5; i++)
625 if (arr[i].field1 != MYSTRUCT_ARRAY[i].field1 ||
626 arr[i].field2 != MYSTRUCT_ARRAY[i].field2 ||
627 ! mystruct_uint_ordered(&arr[i]))
629 ok(diff == 0, "Array of structs corrupted\n");
634 static HRESULT WINAPI Widget_Error(
635 IWidget __RPC_FAR * iface)
641 static HRESULT WINAPI Widget_CloneInterface(
642 IWidget __RPC_FAR * iface,
643 ISomethingFromDispatch **ppVal)
645 trace("CloneInterface()\n");
650 static HRESULT WINAPI Widget_put_prop_with_lcid(
651 IWidget* iface, LONG lcid, INT i)
653 trace("put_prop_with_lcid(%08x, %x)\n", lcid, i);
654 ok(lcid == MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), "got lcid %08x\n", lcid);
655 ok(i == 0xcafe, "got %08x\n", i);
659 static HRESULT WINAPI Widget_get_prop_with_lcid(
660 IWidget* iface, LONG lcid, INT *i)
662 trace("get_prop_with_lcid(%08x, %p)\n", lcid, i);
663 ok(lcid == MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), "got lcid %08x\n", lcid);
668 static HRESULT WINAPI Widget_get_prop_int(
669 IWidget* iface, INT *i)
671 trace("get_prop_int(%p)\n", i);
676 static HRESULT WINAPI Widget_get_prop_uint(
677 IWidget* iface, UINT *i)
679 trace("get_prop_uint(%p)\n", i);
684 static HRESULT WINAPI Widget_ByRefUInt(
685 IWidget* iface, UINT *i)
691 static HRESULT WINAPI Widget_put_prop_opt_arg(
692 IWidget* iface, INT opt, INT i)
694 trace("put_prop_opt_arg(%08x, %08x)\n", opt, i);
695 todo_wine ok(opt == 0, "got opt=%08x\n", opt);
696 ok(i == 0xcafe, "got i=%08x\n", i);
700 static HRESULT WINAPI Widget_put_prop_req_arg(
701 IWidget* iface, INT req, INT i)
703 trace("put_prop_req_arg(%08x, %08x)\n", req, i);
704 ok(req == 0x5678, "got req=%08x\n", req);
705 ok(i == 0x1234, "got i=%08x\n", i);
709 static HRESULT WINAPI Widget_restrict(IWidget* iface, INT *i)
712 *i = DISPID_TM_RESTRICTED;
716 static HRESULT WINAPI Widget_neg_restrict(IWidget* iface, INT *i)
718 trace("neg_restrict\n");
719 *i = DISPID_TM_NEG_RESTRICTED;
723 static const struct IWidgetVtbl Widget_VTable =
725 Widget_QueryInterface,
728 Widget_GetTypeInfoCount,
730 Widget_GetIDsOfNames,
741 Widget_CloneDispatch,
745 Widget_VariantArrayPtr,
746 Widget_VariantCArray,
751 Widget_CloneInterface,
752 Widget_put_prop_with_lcid,
753 Widget_get_prop_with_lcid,
755 Widget_get_prop_uint,
757 Widget_put_prop_opt_arg,
758 Widget_put_prop_req_arg,
763 static HRESULT WINAPI StaticWidget_QueryInterface(IStaticWidget *iface, REFIID riid, void **ppvObject)
765 if (IsEqualIID(riid, &IID_IStaticWidget) || IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch))
767 IStaticWidget_AddRef(iface);
773 return E_NOINTERFACE;
776 static ULONG WINAPI StaticWidget_AddRef(IStaticWidget *iface)
781 static ULONG WINAPI StaticWidget_Release(IStaticWidget *iface)
786 static HRESULT WINAPI StaticWidget_GetTypeInfoCount(IStaticWidget *iface, UINT *pctinfo)
788 ok(0, "unexpected call\n");
792 static HRESULT WINAPI StaticWidget_GetTypeInfo(IStaticWidget *iface, UINT iTInfo, LCID lcid,
795 ok(0, "unexpected call\n");
799 static HRESULT WINAPI StaticWidget_GetIDsOfNames(IStaticWidget *iface, REFIID riid, LPOLESTR *rgszNames,
800 UINT cNames, LCID lcid, DISPID *rgDispId)
802 ok(0, "unexpected call\n");
806 static HRESULT WINAPI StaticWidget_Invoke(IStaticWidget *iface, DISPID dispIdMember, REFIID riid,
807 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
810 ok(0, "unexpected call\n");
814 static HRESULT WINAPI StaticWidget_TestDual(IStaticWidget *iface, ItestDual *p)
816 trace("TestDual()\n");
817 ok(p == &TestDual, "wrong ItestDual\n");
821 static HRESULT WINAPI StaticWidget_TestSecondIface(IStaticWidget *iface, ITestSecondIface *p)
823 trace("TestSecondIface()\n");
824 ok(p == &TestSecondIface, "wrong ItestSecondIface\n");
828 static const IStaticWidgetVtbl StaticWidgetVtbl = {
829 StaticWidget_QueryInterface,
831 StaticWidget_Release,
832 StaticWidget_GetTypeInfoCount,
833 StaticWidget_GetTypeInfo,
834 StaticWidget_GetIDsOfNames,
836 StaticWidget_TestDual,
837 StaticWidget_TestSecondIface
840 static IStaticWidget StaticWidget = { &StaticWidgetVtbl };
842 typedef struct KindaEnum
844 IKindaEnumWidget IKindaEnumWidget_iface;
848 static inline KindaEnum *impl_from_IKindaEnumWidget(IKindaEnumWidget *iface)
850 return CONTAINING_RECORD(iface, KindaEnum, IKindaEnumWidget_iface);
853 static HRESULT register_current_module_typelib(void)
855 WCHAR path[MAX_PATH];
856 CHAR pathA[MAX_PATH];
860 GetModuleFileNameA(NULL, pathA, MAX_PATH);
861 MultiByteToWideChar(CP_ACP, 0, pathA, -1, path, MAX_PATH);
863 hr = LoadTypeLib(path, &typelib);
866 hr = RegisterTypeLib(typelib, path, NULL);
867 ITypeLib_Release(typelib);
872 static ITypeInfo *get_type_info(REFIID riid)
874 ITypeInfo *pTypeInfo;
878 hr = LoadRegTypeLib(&LIBID_TestTypelib, 1, 0, LOCALE_NEUTRAL, &pTypeLib);
879 ok_ole_success(hr, LoadRegTypeLib);
883 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, riid, &pTypeInfo);
884 ITypeLib_Release(pTypeLib);
885 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
892 static IWidget *Widget_Create(void)
895 ITypeInfo *pTypeInfo;
898 pTypeInfo = get_type_info(&IID_IWidget);
902 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
903 This->IWidget_iface.lpVtbl = &Widget_VTable;
905 This->pDispatchUnknown = NULL;
907 hr = CreateStdDispatch((IUnknown *)&This->IWidget_iface, This, pTypeInfo,
908 &This->pDispatchUnknown);
909 ok_ole_success(hr, CreateStdDispatch);
910 ITypeInfo_Release(pTypeInfo);
913 return &This->IWidget_iface;
916 HeapFree(GetProcessHeap(), 0, This);
921 static HRESULT WINAPI KindaEnum_QueryInterface(
922 IKindaEnumWidget *iface,
923 /* [in] */ REFIID riid,
924 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
926 if (IsEqualIID(riid, &IID_IKindaEnumWidget) || IsEqualIID(riid, &IID_IUnknown))
928 IKindaEnumWidget_AddRef(iface);
935 return E_NOINTERFACE;
939 static ULONG WINAPI KindaEnum_AddRef(
940 IKindaEnumWidget *iface)
942 KindaEnum *This = impl_from_IKindaEnumWidget(iface);
944 return InterlockedIncrement(&This->refs);
947 static ULONG WINAPI KindaEnum_Release(
948 IKindaEnumWidget *iface)
950 KindaEnum *This = impl_from_IKindaEnumWidget(iface);
951 ULONG refs = InterlockedDecrement(&This->refs);
954 memset(This, 0xcc, sizeof(*This));
955 HeapFree(GetProcessHeap(), 0, This);
956 trace("KindaEnumWidget destroyed!\n");
962 static HRESULT WINAPI KindaEnum_Next(
963 IKindaEnumWidget *iface,
964 /* [out] */ IWidget __RPC_FAR *__RPC_FAR *widget)
966 *widget = Widget_Create();
970 return E_OUTOFMEMORY;
973 static HRESULT WINAPI KindaEnum_Count(
974 IKindaEnumWidget *iface,
975 /* [out] */ ULONG __RPC_FAR *count)
980 static HRESULT WINAPI KindaEnum_Reset(
981 IKindaEnumWidget *iface)
986 static HRESULT WINAPI KindaEnum_Clone(
987 IKindaEnumWidget *iface,
988 /* [out] */ IKindaEnumWidget __RPC_FAR *__RPC_FAR *ppenum)
993 static const IKindaEnumWidgetVtbl KindaEnumWidget_VTable =
995 KindaEnum_QueryInterface,
1004 static IKindaEnumWidget *KindaEnumWidget_Create(void)
1008 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1009 if (!This) return NULL;
1010 This->IKindaEnumWidget_iface.lpVtbl = &KindaEnumWidget_VTable;
1012 return &This->IKindaEnumWidget_iface;
1015 static HRESULT WINAPI NonOleAutomation_QueryInterface(INonOleAutomation *iface, REFIID riid, void **ppv)
1017 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_INonOleAutomation))
1019 *(INonOleAutomation **)ppv = iface;
1023 return E_NOINTERFACE;
1026 static ULONG WINAPI NonOleAutomation_AddRef(INonOleAutomation *iface)
1031 static ULONG WINAPI NonOleAutomation_Release(INonOleAutomation *iface)
1036 static BSTR WINAPI NonOleAutomation_BstrRet(INonOleAutomation *iface)
1038 static const WCHAR wszTestString[] = {'T','h','i','s',' ','i','s',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0};
1039 return SysAllocString(wszTestString);
1042 static HRESULT WINAPI NonOleAutomation_Error(INonOleAutomation *iface)
1047 static INonOleAutomationVtbl NonOleAutomation_VTable =
1049 NonOleAutomation_QueryInterface,
1050 NonOleAutomation_AddRef,
1051 NonOleAutomation_Release,
1052 NonOleAutomation_BstrRet,
1053 NonOleAutomation_Error
1056 static INonOleAutomation NonOleAutomation = { &NonOleAutomation_VTable };
1058 static ITypeInfo *NonOleAutomation_GetTypeInfo(void)
1061 HRESULT hr = LoadRegTypeLib(&LIBID_TestTypelib, 1, 0, LOCALE_NEUTRAL, &pTypeLib);
1062 ok_ole_success(hr, LoadRegTypeLib);
1065 ITypeInfo *pTypeInfo;
1066 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_INonOleAutomation, &pTypeInfo);
1067 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
1068 ITypeLib_Release(pTypeLib);
1074 static void test_typelibmarshal(void)
1076 static const WCHAR szCat[] = { 'C','a','t',0 };
1077 static const WCHAR szTestTest[] = { 'T','e','s','t','T','e','s','t',0 };
1078 static WCHAR szSuperman[] = { 'S','u','p','e','r','m','a','n',0 };
1080 IKindaEnumWidget *pKEW = KindaEnumWidget_Create();
1083 IDispatch *pDispatch;
1084 static const LARGE_INTEGER ullZero;
1085 EXCEPINFO excepinfo;
1087 DISPID dispidNamed = DISPID_PROPERTYPUT;
1088 DISPPARAMS dispparams;
1089 VARIANTARG vararg[4];
1094 ITypeInfo *pTypeInfo;
1096 MYSTRUCT mystructArray[5];
1099 ok(pKEW != NULL, "Widget creation failed\n");
1101 hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
1102 ok_ole_success(hr, CreateStreamOnHGlobal);
1103 tid = start_host_object(pStream, &IID_IKindaEnumWidget, (IUnknown *)pKEW, MSHLFLAGS_NORMAL, &thread);
1104 IKindaEnumWidget_Release(pKEW);
1106 IStream_Seek(pStream, ullZero, STREAM_SEEK_SET, NULL);
1107 hr = CoUnmarshalInterface(pStream, &IID_IKindaEnumWidget, (void **)&pKEW);
1108 ok_ole_success(hr, CoUnmarshalInterface);
1109 IStream_Release(pStream);
1111 hr = IKindaEnumWidget_Next(pKEW, &pWidget);
1112 ok_ole_success(hr, IKindaEnumWidget_Next);
1114 IKindaEnumWidget_Release(pKEW);
1116 /* call GetTypeInfoCount (direct) */
1117 hr = IWidget_GetTypeInfoCount(pWidget, &uval);
1118 ok_ole_success(hr, IWidget_GetTypeInfoCount);
1119 hr = IWidget_GetTypeInfoCount(pWidget, &uval);
1120 ok_ole_success(hr, IWidget_GetTypeInfoCount);
1122 hr = IWidget_QueryInterface(pWidget, &IID_IDispatch, (void **)&pDispatch);
1123 ok_ole_success(hr, IWidget_QueryInterface);
1126 VariantInit(&vararg[0]);
1127 dispparams.cNamedArgs = 1;
1128 dispparams.rgdispidNamedArgs = &dispidNamed;
1129 dispparams.cArgs = 1;
1130 dispparams.rgvarg = vararg;
1131 VariantInit(&varresult);
1132 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1133 ok_ole_success(hr, IDispatch_Invoke);
1134 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1135 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1136 excepinfo.wCode, excepinfo.scode);
1137 VariantClear(&varresult);
1139 /* call put_Name (direct) */
1140 bstr = SysAllocString(szSuperman);
1141 hr = IWidget_put_Name(pWidget, bstr);
1142 ok_ole_success(hr, IWidget_put_Name);
1143 SysFreeString(bstr);
1146 dispparams.cNamedArgs = 0;
1147 dispparams.rgdispidNamedArgs = NULL;
1148 dispparams.cArgs = 0;
1149 dispparams.rgvarg = NULL;
1150 VariantInit(&varresult);
1151 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1152 ok_ole_success(hr, IDispatch_Invoke);
1153 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1154 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1155 excepinfo.wCode, excepinfo.scode);
1156 trace("Name = %s\n", wine_dbgstr_w(V_BSTR(&varresult)));
1157 VariantClear(&varresult);
1159 /* call get_Name (direct) */
1160 bstr = (void *)0xdeadbeef;
1161 hr = IWidget_get_Name(pWidget, &bstr);
1162 ok_ole_success(hr, IWidget_get_Name);
1163 ok(!lstrcmpW(bstr, szCat), "IWidget_get_Name should have returned string \"Cat\" instead of %s\n", wine_dbgstr_w(bstr));
1164 SysFreeString(bstr);
1166 /* call DoSomething */
1167 VariantInit(&vararg[0]);
1168 VariantInit(&vararg[1]);
1169 V_VT(&vararg[1]) = VT_R8;
1170 V_R8(&vararg[1]) = 3.141;
1171 dispparams.cNamedArgs = 0;
1172 dispparams.cArgs = 2;
1173 dispparams.rgdispidNamedArgs = NULL;
1174 dispparams.rgvarg = vararg;
1175 VariantInit(&varresult);
1176 hr = IDispatch_Invoke(pDispatch, DISPID_TM_DOSOMETHING, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1177 ok_ole_success(hr, IDispatch_Invoke);
1178 ok(V_VT(&varresult) == VT_EMPTY, "varresult should be VT_EMPTY\n");
1179 VariantClear(&varresult);
1181 /* call get_State */
1182 dispparams.cNamedArgs = 0;
1183 dispparams.cArgs = 0;
1184 dispparams.rgdispidNamedArgs = NULL;
1185 dispparams.rgvarg = NULL;
1186 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1187 ok_ole_success(hr, IDispatch_Invoke);
1188 ok((V_VT(&varresult) == VT_I4) && (V_I4(&varresult) == STATE_WIDGETIFIED), "Return val mismatch\n");
1190 /* call get_State (direct) */
1191 hr = IWidget_get_State(pWidget, &the_state);
1192 ok_ole_success(hr, IWidget_get_state);
1193 ok(the_state == STATE_WIDGETIFIED, "should have returned WIDGET_WIDGETIFIED instead of %d\n", the_state);
1195 /* call put_State */
1196 the_state = STATE_WIDGETIFIED;
1197 VariantInit(&vararg[0]);
1198 V_VT(&vararg[0]) = VT_BYREF|VT_I4;
1199 V_I4REF(&vararg[0]) = (int *)&the_state;
1200 dispparams.cNamedArgs = 1;
1201 dispparams.cArgs = 1;
1202 dispparams.rgdispidNamedArgs = &dispidNamed;
1203 dispparams.rgvarg = vararg;
1204 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1205 ok_ole_success(hr, IDispatch_Invoke);
1208 bstr = SysAllocString(szTestTest);
1209 VariantInit(&vararg[0]);
1210 V_VT(&vararg[0]) = VT_BYREF|VT_BSTR;
1211 V_BSTRREF(&vararg[0]) = &bstr;
1212 dispparams.cNamedArgs = 0;
1213 dispparams.cArgs = 1;
1214 dispparams.rgdispidNamedArgs = NULL;
1215 dispparams.rgvarg = vararg;
1216 VariantInit(&varresult);
1217 hr = IDispatch_Invoke(pDispatch, DISPID_TM_MAP, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1218 ok_ole_success(hr, IDispatch_Invoke);
1219 ok(V_VT(&varresult) == VT_BSTR, "Return value should be of type BSTR instead of %d\n", V_VT(&varresult));
1220 ok(!lstrcmpW(V_BSTR(&varresult), szTestTest), "Return value should have been \"TestTest\" instead of %s\n", wine_dbgstr_w(V_BSTR(&varresult)));
1221 VariantClear(&varresult);
1222 SysFreeString(bstr);
1224 /* call SetOleColor with large negative VT_I4 param */
1225 VariantInit(&vararg[0]);
1226 V_VT(&vararg[0]) = VT_I4;
1227 V_I4(&vararg[0]) = 0x80000005;
1228 dispparams.cNamedArgs = 0;
1229 dispparams.cArgs = 1;
1230 dispparams.rgdispidNamedArgs = NULL;
1231 dispparams.rgvarg = vararg;
1232 hr = IDispatch_Invoke(pDispatch, DISPID_TM_SETOLECOLOR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, &excepinfo, NULL);
1233 ok_ole_success(hr, IDispatch_Invoke);
1235 /* call GetOleColor */
1236 dispparams.cNamedArgs = 0;
1237 dispparams.cArgs = 0;
1238 dispparams.rgdispidNamedArgs = NULL;
1239 dispparams.rgvarg = NULL;
1240 VariantInit(&varresult);
1241 hr = IDispatch_Invoke(pDispatch, DISPID_TM_GETOLECOLOR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1242 ok_ole_success(hr, IDispatch_Invoke);
1243 VariantClear(&varresult);
1245 /* call StructArgs (direct) */
1246 mystruct = MYSTRUCT_BYPTR;
1247 memcpy(mystructArray, MYSTRUCT_ARRAY, sizeof(mystructArray));
1248 hr = IWidget_StructArgs(pWidget, MYSTRUCT_BYVAL, &mystruct, mystructArray);
1249 ok_ole_success(hr, IWidget_StructArgs);
1252 dispparams.cNamedArgs = 0;
1253 dispparams.cArgs = 0;
1254 dispparams.rgdispidNamedArgs = NULL;
1255 dispparams.rgvarg = NULL;
1256 VariantInit(&varresult);
1257 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1258 ok_ole_success(hr, IDispatch_Invoke);
1259 ok(V_VT(&varresult) == VT_DISPATCH, "vt %x\n", V_VT(&varresult));
1260 VariantClear(&varresult);
1262 /* call CloneInterface */
1263 dispparams.cNamedArgs = 0;
1264 dispparams.cArgs = 0;
1265 dispparams.rgdispidNamedArgs = NULL;
1266 dispparams.rgvarg = NULL;
1267 VariantInit(&varresult);
1268 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONEINTERFACE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1269 ok_ole_success(hr, IDispatch_Invoke);
1270 ok(V_VT(&varresult) == VT_DISPATCH, "vt %x\n", V_VT(&varresult));
1271 VariantClear(&varresult);
1273 /* call CloneDispatch with automatic value getting */
1274 V_VT(&vararg[0]) = VT_I2;
1275 V_I2(&vararg[0]) = 1;
1276 dispparams.cNamedArgs = 0;
1277 dispparams.rgdispidNamedArgs = NULL;
1278 dispparams.cArgs = 1;
1279 dispparams.rgvarg = vararg;
1280 VariantInit(&varresult);
1281 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONEDISPATCH, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1282 ok_ole_success(hr, IDispatch_Invoke);
1284 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1285 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1286 excepinfo.wCode, excepinfo.scode);
1288 ok(V_VT(&varresult) == VT_I2, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult));
1289 ok(V_I2(&varresult) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult));
1290 VariantClear(&varresult);
1292 /* call CloneCoclass */
1293 dispparams.cNamedArgs = 0;
1294 dispparams.cArgs = 0;
1295 dispparams.rgdispidNamedArgs = NULL;
1296 dispparams.rgvarg = NULL;
1297 VariantInit(&varresult);
1298 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONECOCLASS, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1299 ok_ole_success(hr, IDispatch_Invoke);
1301 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1302 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1303 excepinfo.wCode, excepinfo.scode);
1305 ok(V_VT(&varresult) == VT_DISPATCH, "V_VT(&varresult) was %d instead of VT_DISPATCH\n", V_VT(&varresult));
1306 ok(!V_DISPATCH(&varresult), "V_DISPATCH(&varresult) should be NULL instead of %p\n", V_DISPATCH(&varresult));
1307 VariantClear(&varresult);
1309 /* call Value with a VT_VARIANT|VT_BYREF type */
1310 V_VT(&vararg[0]) = VT_VARIANT|VT_BYREF;
1311 V_VARIANTREF(&vararg[0]) = &vararg[1];
1312 V_VT(&vararg[1]) = VT_I2;
1313 V_I2(&vararg[1]) = 1;
1314 dispparams.cNamedArgs = 0;
1315 dispparams.rgdispidNamedArgs = NULL;
1316 dispparams.cArgs = 1;
1317 dispparams.rgvarg = vararg;
1318 VariantInit(&varresult);
1319 hr = IDispatch_Invoke(pDispatch, DISPID_VALUE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1320 ok_ole_success(hr, IDispatch_Invoke);
1322 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1323 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1324 excepinfo.wCode, excepinfo.scode);
1326 ok(V_VT(&varresult) == VT_I2, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult));
1327 ok(V_I2(&varresult) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult));
1328 VariantClear(&varresult);
1330 /* call Variant - exercises variant copying in ITypeInfo::Invoke and
1331 * handling of void return types */
1332 /* use a big type to ensure that the variant was properly copied into the
1333 * destination function's args */
1334 V_VT(&vararg[0]) = VT_CY;
1335 S(V_CY(&vararg[0])).Hi = 0xdababe;
1336 S(V_CY(&vararg[0])).Lo = 0xdeadbeef;
1337 dispparams.cNamedArgs = 0;
1338 dispparams.cArgs = 1;
1339 dispparams.rgdispidNamedArgs = NULL;
1340 dispparams.rgvarg = vararg;
1341 VariantInit(&varresult);
1342 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARIANT, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1343 ok_ole_success(hr, IDispatch_Invoke);
1344 VariantClear(&varresult);
1346 /* call VariantCArray - test marshaling of variant arrays */
1347 V_VT(&vararg[0]) = VT_I4;
1348 V_I4(&vararg[0]) = 1;
1349 V_VT(&vararg[1]) = VT_I4;
1350 V_I4(&vararg[1]) = 2;
1351 hr = IWidget_VariantCArray(pWidget, 2, vararg);
1352 ok_ole_success(hr, IWidget_VariantCArray);
1354 ok(V_VT(&vararg[0]) == VT_I4 && V_I4(&vararg[0]) == 2, "vararg[0] = %d[%d]\n", V_VT(&vararg[0]), V_I4(&vararg[0]));
1356 ok(V_VT(&vararg[1]) == VT_I4 && V_I4(&vararg[1]) == 3, "vararg[1] = %d[%d]\n", V_VT(&vararg[1]), V_I4(&vararg[1]));
1359 VariantInit(&vararg[3]);
1360 V_VT(&vararg[3]) = VT_I4;
1361 V_I4(&vararg[3]) = 3;
1362 VariantInit(&vararg[2]);
1363 V_VT(&vararg[2]) = VT_I4;
1364 V_I4(&vararg[2]) = 0;
1365 VariantInit(&vararg[1]);
1366 V_VT(&vararg[1]) = VT_I4;
1367 V_I4(&vararg[1]) = 1;
1368 VariantInit(&vararg[0]);
1369 V_VT(&vararg[0]) = VT_I4;
1370 V_I4(&vararg[0]) = 2;
1371 dispparams.cNamedArgs = 0;
1372 dispparams.cArgs = 4;
1373 dispparams.rgdispidNamedArgs = NULL;
1374 dispparams.rgvarg = vararg;
1375 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARARG, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1376 ok_ole_success(hr, ITypeInfo_Invoke);
1378 /* call VarArg, even one (non-optional, non-safearray) named argument is not allowed */
1380 dispparams.cNamedArgs = 1;
1381 dispparams.rgdispidNamedArgs = &dispidNamed;
1382 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARARG, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1383 ok(hr == DISP_E_NONAMEDARGS, "IDispatch_Invoke should have returned DISP_E_NONAMEDARGS instead of 0x%08x\n", hr);
1384 dispidNamed = DISPID_PROPERTYPUT;
1387 dispparams.cNamedArgs = 0;
1388 dispparams.cArgs = 0;
1389 dispparams.rgdispidNamedArgs = NULL;
1390 dispparams.rgvarg = NULL;
1391 VariantInit(&varresult);
1392 hr = IDispatch_Invoke(pDispatch, DISPID_TM_ERROR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, &excepinfo, NULL);
1393 ok(hr == DISP_E_EXCEPTION, "IDispatch_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr);
1394 ok(excepinfo.wCode == 0x0 && excepinfo.scode == E_NOTIMPL,
1395 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1396 excepinfo.wCode, excepinfo.scode);
1397 VariantClear(&varresult);
1400 pTypeInfo = NonOleAutomation_GetTypeInfo();
1401 dispparams.cNamedArgs = 0;
1402 dispparams.cArgs = 0;
1403 dispparams.rgdispidNamedArgs = NULL;
1404 dispparams.rgvarg = NULL;
1405 VariantInit(&varresult);
1406 hr = ITypeInfo_Invoke(pTypeInfo, &NonOleAutomation, DISPID_NOA_BSTRRET, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1407 ok_ole_success(hr, ITypeInfo_Invoke);
1408 ok(V_VT(&varresult) == VT_BSTR, "V_VT(&varresult) should be VT_BSTR instead of %d\n", V_VT(&varresult));
1409 ok(V_BSTR(&varresult) != NULL, "V_BSTR(&varresult) should not be NULL\n");
1411 VariantClear(&varresult);
1413 dispparams.cNamedArgs = 0;
1414 dispparams.cArgs = 0;
1415 dispparams.rgdispidNamedArgs = NULL;
1416 dispparams.rgvarg = NULL;
1417 hr = ITypeInfo_Invoke(pTypeInfo, &NonOleAutomation, DISPID_NOA_ERROR, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1418 ok(hr == DISP_E_EXCEPTION, "ITypeInfo_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr);
1419 ok(V_VT(&varresult) == VT_EMPTY, "V_VT(&varresult) should be VT_EMPTY instead of %d\n", V_VT(&varresult));
1420 ok(excepinfo.wCode == 0x0 && excepinfo.scode == E_NOTIMPL,
1421 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1422 excepinfo.wCode, excepinfo.scode);
1423 VariantClear(&varresult);
1425 ITypeInfo_Release(pTypeInfo);
1427 /* tests call put_Name without named arg */
1428 VariantInit(&vararg[0]);
1429 dispparams.cNamedArgs = 0;
1430 dispparams.rgdispidNamedArgs = NULL;
1431 dispparams.cArgs = 1;
1432 dispparams.rgvarg = vararg;
1433 VariantInit(&varresult);
1434 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1435 ok(hr == DISP_E_PARAMNOTFOUND, "IDispatch_Invoke should have returned DISP_E_PARAMNOTFOUND instead of 0x%08x\n", hr);
1436 VariantClear(&varresult);
1438 /* tests param type that cannot be coerced */
1439 VariantInit(&vararg[0]);
1440 V_VT(&vararg[0]) = VT_UNKNOWN;
1441 V_UNKNOWN(&vararg[0]) = NULL;
1442 dispparams.cNamedArgs = 1;
1443 dispparams.rgdispidNamedArgs = &dispidNamed;
1444 dispparams.cArgs = 1;
1445 dispparams.rgvarg = vararg;
1446 VariantInit(&varresult);
1447 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1448 ok(hr == DISP_E_TYPEMISMATCH, "IDispatch_Invoke should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hr);
1449 VariantClear(&varresult);
1451 /* tests bad param type */
1452 VariantInit(&vararg[0]);
1453 V_VT(&vararg[0]) = VT_CLSID;
1454 V_BYREF(&vararg[0]) = NULL;
1455 dispparams.cNamedArgs = 1;
1456 dispparams.rgdispidNamedArgs = &dispidNamed;
1457 dispparams.cArgs = 1;
1458 dispparams.rgvarg = vararg;
1459 VariantInit(&varresult);
1460 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1461 ok(hr == DISP_E_BADVARTYPE, "IDispatch_Invoke should have returned DISP_E_BADVARTYPE instead of 0x%08x\n", hr);
1462 VariantClear(&varresult);
1464 /* tests too small param count */
1465 dispparams.cNamedArgs = 0;
1466 dispparams.rgdispidNamedArgs = NULL;
1467 dispparams.cArgs = 0;
1468 dispparams.rgvarg = NULL;
1469 VariantInit(&varresult);
1470 hr = IDispatch_Invoke(pDispatch, DISPID_TM_DOSOMETHING, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1471 ok(hr == DISP_E_BADPARAMCOUNT, "IDispatch_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr);
1472 VariantClear(&varresult);
1474 /* tests propget function with large param count */
1475 VariantInit(&vararg[0]);
1476 V_VT(&vararg[0]) = VT_BSTR;
1477 V_BSTR(&vararg[0]) = NULL;
1478 V_VT(&vararg[1]) = VT_I4;
1479 V_I4(&vararg[1]) = 1;
1480 dispparams.cNamedArgs = 0;
1481 dispparams.cArgs = 2;
1482 dispparams.rgdispidNamedArgs = NULL;
1483 dispparams.rgvarg = vararg;
1484 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1485 ok(hr == DISP_E_NOTACOLLECTION, "IDispatch_Invoke should have returned DISP_E_NOTACOLLECTION instead of 0x%08x\n", hr);
1487 /* test propput with lcid */
1489 /* the lcid passed to the function is the first lcid in the typelib header.
1490 Since we don't explicitly set an lcid in the idl, it'll default to US English. */
1491 VariantInit(&vararg[0]);
1492 V_VT(&vararg[0]) = VT_I4;
1493 V_I4(&vararg[0]) = 0xcafe;
1494 dispparams.cNamedArgs = 1;
1495 dispparams.rgdispidNamedArgs = &dispidNamed;
1496 dispparams.cArgs = 1;
1497 dispparams.rgvarg = vararg;
1498 VariantInit(&varresult);
1499 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_WITH_LCID, &IID_NULL, 0x40c, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1500 ok_ole_success(hr, ITypeInfo_Invoke);
1501 VariantClear(&varresult);
1503 /* test propget with lcid */
1504 dispparams.cNamedArgs = 0;
1505 dispparams.cArgs = 0;
1506 dispparams.rgvarg = NULL;
1507 dispparams.rgdispidNamedArgs = NULL;
1508 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_WITH_LCID, &IID_NULL, 0x40c, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1509 ok_ole_success(hr, ITypeInfo_Invoke);
1510 ok(V_VT(&varresult) == VT_I4, "got %x\n", V_VT(&varresult));
1511 ok(V_I4(&varresult) == 0x409, "got %x\n", V_I4(&varresult));
1512 VariantClear(&varresult);
1514 /* test propget of INT value */
1515 dispparams.cNamedArgs = 0;
1516 dispparams.cArgs = 0;
1517 dispparams.rgvarg = NULL;
1518 dispparams.rgdispidNamedArgs = NULL;
1519 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_INT, &IID_NULL, 0x40c, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1520 ok_ole_success(hr, ITypeInfo_Invoke);
1521 ok(V_VT(&varresult) == VT_I4, "got %x\n", V_VT(&varresult));
1522 ok(V_I4(&varresult) == -13, "got %x\n", V_I4(&varresult));
1523 VariantClear(&varresult);
1525 /* test propget of INT value */
1526 dispparams.cNamedArgs = 0;
1527 dispparams.cArgs = 0;
1528 dispparams.rgvarg = NULL;
1529 dispparams.rgdispidNamedArgs = NULL;
1530 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_UINT, &IID_NULL, 0x40c, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1531 ok_ole_success(hr, ITypeInfo_Invoke);
1532 ok(V_VT(&varresult) == VT_UI4, "got %x\n", V_VT(&varresult));
1533 ok(V_UI4(&varresult) == 42, "got %x\n", V_UI4(&varresult));
1534 VariantClear(&varresult);
1536 /* test byref marshalling */
1538 VariantInit(&vararg[0]);
1539 V_VT(&vararg[0]) = VT_UI4|VT_BYREF;
1540 V_UI4REF(&vararg[0]) = &uval;
1541 dispparams.cNamedArgs = 0;
1542 dispparams.cArgs = 1;
1543 dispparams.rgvarg = vararg;
1544 dispparams.rgdispidNamedArgs = NULL;
1545 hr = IDispatch_Invoke(pDispatch, DISPID_TM_BYREF_UINT, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1546 ok_ole_success(hr, ITypeInfo_Invoke);
1547 ok(V_VT(&varresult) == VT_EMPTY, "varresult should be VT_EMPTY\n");
1548 ok(V_VT(&vararg[0]) == (VT_UI4|VT_BYREF), "arg VT not unmarshalled correctly: %x\n", V_VT(&vararg[0]));
1549 ok(V_UI4REF(&vararg[0]) == &uval, "Byref pointer not preserved: %p/%p\n", &uval, V_UI4REF(&vararg[0]));
1550 ok(*V_UI4REF(&vararg[0]) == 42, "Expected 42 to be returned instead of %u\n", *V_UI4REF(&vararg[0]));
1551 VariantClear(&varresult);
1552 VariantClear(&vararg[0]);
1554 /* test propput with optional argument. */
1555 VariantInit(&vararg[0]);
1556 V_VT(&vararg[0]) = VT_I4;
1557 V_I4(&vararg[0]) = 0xcafe;
1558 dispparams.cNamedArgs = 1;
1559 dispparams.rgdispidNamedArgs = &dispidNamed;
1560 dispparams.cArgs = 1;
1561 dispparams.rgvarg = vararg;
1562 VariantInit(&varresult);
1563 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_OPT_ARG, &IID_NULL, 0x40c, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1564 ok_ole_success(hr, ITypeInfo_Invoke);
1565 VariantClear(&varresult);
1567 /* test propput with required argument. */
1568 VariantInit(&vararg[0]);
1569 VariantInit(&vararg[1]);
1570 V_VT(&vararg[0]) = VT_I4;
1571 V_I4(&vararg[0]) = 0x1234;
1572 V_VT(&vararg[1]) = VT_I4;
1573 V_I4(&vararg[1]) = 0x5678;
1574 dispparams.cNamedArgs = 1;
1575 dispparams.rgdispidNamedArgs = &dispidNamed;
1576 dispparams.cArgs = 2;
1577 dispparams.rgvarg = vararg;
1578 VariantInit(&varresult);
1579 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_REQ_ARG, &IID_NULL, 0x40c, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1580 ok_ole_success(hr, ITypeInfo_Invoke);
1581 VariantClear(&varresult);
1583 /* restricted member */
1584 dispparams.cNamedArgs = 0;
1585 dispparams.rgdispidNamedArgs = NULL;
1586 dispparams.cArgs = 0;
1587 dispparams.rgvarg = NULL;
1588 VariantInit(&varresult);
1589 hr = IDispatch_Invoke(pDispatch, DISPID_TM_RESTRICTED, &IID_NULL, 0x40c, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1590 ok( hr == DISP_E_MEMBERNOTFOUND, "got %08x\n", hr );
1591 VariantClear(&varresult);
1593 /* restricted member with -ve memid (not restricted) */
1594 dispparams.cNamedArgs = 0;
1595 dispparams.rgdispidNamedArgs = NULL;
1596 dispparams.cArgs = 0;
1597 dispparams.rgvarg = NULL;
1598 VariantInit(&varresult);
1599 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NEG_RESTRICTED, &IID_NULL, 0x40c, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1600 ok( hr == S_OK, "got %08x\n", hr );
1601 ok(V_VT(&varresult) == VT_I4, "got %x\n", V_VT(&varresult));
1602 ok(V_I4(&varresult) == DISPID_TM_NEG_RESTRICTED, "got %x\n", V_I4(&varresult));
1603 VariantClear(&varresult);
1605 IDispatch_Release(pDispatch);
1606 IWidget_Release(pWidget);
1608 trace("calling end_host_object\n");
1609 end_host_object(tid, thread);
1612 static void test_DispCallFunc(void)
1614 static const WCHAR szEmpty[] = { 0 };
1615 VARTYPE rgvt[] = { VT_R8, VT_BSTR, VT_BSTR, VT_VARIANT|VT_BYREF };
1616 VARIANTARG vararg[4];
1618 VARIANTARG *rgpvarg[4] = { &vararg[0], &vararg[1], &vararg[2], &vararg[3] };
1619 VARIANTARG varresult;
1621 IWidget *pWidget = Widget_Create();
1622 V_VT(&vararg[0]) = VT_R8;
1623 V_R8(&vararg[0]) = 3.141;
1624 V_VT(&vararg[1]) = VT_BSTR;
1625 V_BSTRREF(&vararg[1]) = CoTaskMemAlloc(sizeof(BSTR));
1626 V_VT(&vararg[2]) = VT_BSTR;
1627 V_BSTR(&vararg[2]) = SysAllocString(szEmpty);
1628 V_VT(&vararg[3]) = VT_VARIANT|VT_BYREF;
1629 V_VARIANTREF(&vararg[3]) = &varref;
1630 V_VT(&varref) = VT_ERROR;
1631 V_ERROR(&varref) = DISP_E_PARAMNOTFOUND;
1632 VariantInit(&varresult);
1633 hr = DispCallFunc(pWidget, 9*sizeof(void*), CC_STDCALL, VT_UI4, 4, rgvt, rgpvarg, &varresult);
1634 ok_ole_success(hr, DispCallFunc);
1635 VariantClear(&varresult);
1636 SysFreeString(*V_BSTRREF(&vararg[1]));
1637 CoTaskMemFree(V_BSTRREF(&vararg[1]));
1638 VariantClear(&vararg[2]);
1639 IWidget_Release(pWidget);
1642 static void test_StaticWidget(void)
1644 ITypeInfo *type_info;
1645 DISPPARAMS dispparams;
1646 VARIANTARG vararg[4];
1647 EXCEPINFO excepinfo;
1651 type_info = get_type_info(&IID_IStaticWidget);
1654 dispparams.cNamedArgs = 0;
1655 dispparams.cArgs = 1;
1656 dispparams.rgdispidNamedArgs = NULL;
1657 dispparams.rgvarg = vararg;
1658 V_VT(vararg) = VT_DISPATCH;
1659 V_DISPATCH(vararg) = (IDispatch*)&TestDualDisp;
1660 VariantInit(&varresult);
1661 hr = ITypeInfo_Invoke(type_info, &StaticWidget, DISPID_TM_TESTDUAL, DISPATCH_METHOD,
1662 &dispparams, &varresult, &excepinfo, NULL);
1663 ok_ole_success(hr, IDispatch_Invoke);
1664 ok(V_VT(&varresult) == VT_EMPTY, "vt %x\n", V_VT(&varresult));
1665 VariantClear(&varresult);
1667 /* call TestSecondIface */
1668 dispparams.cNamedArgs = 0;
1669 dispparams.cArgs = 1;
1670 dispparams.rgdispidNamedArgs = NULL;
1671 dispparams.rgvarg = vararg;
1672 V_VT(vararg) = VT_DISPATCH;
1673 V_DISPATCH(vararg) = (IDispatch*)&TestDualDisp;
1674 VariantInit(&varresult);
1675 hr = ITypeInfo_Invoke(type_info, &StaticWidget, DISPID_TM_TESTSECONDIFACE, DISPATCH_METHOD,
1676 &dispparams, &varresult, &excepinfo, NULL);
1677 ok_ole_success(hr, IDispatch_Invoke);
1678 ok(V_VT(&varresult) == VT_EMPTY, "vt %x\n", V_VT(&varresult));
1679 VariantClear(&varresult);
1681 ITypeInfo_Release(type_info);
1684 static void test_libattr(void)
1690 hr = LoadRegTypeLib(&LIBID_TestTypelib, 1, 0, LOCALE_NEUTRAL, &pTypeLib);
1691 ok_ole_success(hr, LoadRegTypeLib);
1695 hr = ITypeLib_GetLibAttr(pTypeLib, &pattr);
1696 ok_ole_success(hr, GetLibAttr);
1699 ok(pattr->lcid == MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), "lcid %x\n", pattr->lcid);
1701 ITypeLib_ReleaseTLibAttr(pTypeLib, pattr);
1704 ITypeLib_Release(pTypeLib);
1707 START_TEST(tmarshal)
1710 HANDLE hOleaut32 = GetModuleHandleA("oleaut32.dll");
1711 pVarAdd = (void*)GetProcAddress(hOleaut32, "VarAdd");
1713 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1715 hr = register_current_module_typelib();
1719 win_skip("Registration of the test typelib failed, skipping tests\n");
1723 test_typelibmarshal();
1724 test_DispCallFunc();
1725 test_StaticWidget();
1728 hr = UnRegisterTypeLib(&LIBID_TestTypelib, 1, 0, LOCALE_NEUTRAL,
1729 sizeof(void*) == 8 ? SYS_WIN64 : SYS_WIN32);
1730 ok_ole_success(hr, UnRegisterTypeLib);