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
26 #include <wine/test.h>
29 #include "tmarshal_dispids.h"
31 #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%08lx\n", (unsigned long int)hr)
33 /* Debugging functions from wine/libs/wine/debug.c */
35 /* allocate some tmp string space */
36 /* FIXME: this is not 100% thread-safe */
37 static char *get_tmp_space( int size )
39 static char *list[32];
44 idx = ++pos % (sizeof(list)/sizeof(list[0]));
45 if ((ret = realloc( list[idx], size ))) list[idx] = ret;
49 /* default implementation of wine_dbgstr_wn */
50 static const char *default_dbgstr_wn( const WCHAR *str, int n )
56 if (!str) return "(null)";
57 res = get_tmp_space( 6 );
58 sprintf( res, "#%04x", LOWORD(str) );
61 if (n == -1) n = lstrlenW(str);
63 else if (n > 200) n = 200;
64 dst = res = get_tmp_space( n * 5 + 7 );
72 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
73 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
74 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
75 case '"': *dst++ = '\\'; *dst++ = '"'; break;
76 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
78 if (c >= ' ' && c <= 126)
83 sprintf(dst,"%04x",c);
99 const char *wine_dbgstr_wn( const WCHAR *s, int n )
101 return default_dbgstr_wn(s, n);
104 const char *wine_dbgstr_w( const WCHAR *s )
106 return default_dbgstr_wn( s, -1 );
110 #define RELEASEMARSHALDATA WM_USER
112 struct host_object_data
117 MSHLFLAGS marshal_flags;
118 HANDLE marshal_event;
119 IMessageFilter *filter;
122 static DWORD CALLBACK host_object_proc(LPVOID p)
124 struct host_object_data *data = (struct host_object_data *)p;
128 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
132 IMessageFilter * prev_filter = NULL;
133 hr = CoRegisterMessageFilter(data->filter, &prev_filter);
134 if (prev_filter) IMessageFilter_Release(prev_filter);
135 ok_ole_success(hr, CoRegisterMessageFilter);
138 hr = CoMarshalInterface(data->stream, &data->iid, data->object, MSHCTX_INPROC, NULL, data->marshal_flags);
139 ok_ole_success(hr, CoMarshalInterface);
141 /* force the message queue to be created before signaling parent thread */
142 PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
144 SetEvent(data->marshal_event);
146 while (GetMessage(&msg, NULL, 0, 0))
148 if (msg.hwnd == NULL && msg.message == RELEASEMARSHALDATA)
150 trace("releasing marshal data\n");
151 CoReleaseMarshalData(data->stream);
152 SetEvent((HANDLE)msg.lParam);
155 DispatchMessage(&msg);
158 HeapFree(GetProcessHeap(), 0, data);
165 static DWORD start_host_object2(IStream *stream, REFIID riid, IUnknown *object, MSHLFLAGS marshal_flags, IMessageFilter *filter, HANDLE *thread)
168 HANDLE marshal_event = CreateEvent(NULL, FALSE, FALSE, NULL);
169 struct host_object_data *data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data));
171 data->stream = stream;
173 data->object = object;
174 data->marshal_flags = marshal_flags;
175 data->marshal_event = marshal_event;
176 data->filter = filter;
178 *thread = CreateThread(NULL, 0, host_object_proc, data, 0, &tid);
180 /* wait for marshaling to complete before returning */
181 WaitForSingleObject(marshal_event, INFINITE);
182 CloseHandle(marshal_event);
187 static DWORD start_host_object(IStream *stream, REFIID riid, IUnknown *object, MSHLFLAGS marshal_flags, HANDLE *thread)
189 return start_host_object2(stream, riid, object, marshal_flags, NULL, thread);
193 /* asks thread to release the marshal data because it has to be done by the
194 * same thread that marshaled the interface in the first place. */
195 static void release_host_object(DWORD tid)
197 HANDLE event = CreateEvent(NULL, FALSE, FALSE, NULL);
198 PostThreadMessage(tid, RELEASEMARSHALDATA, 0, (LPARAM)event);
199 WaitForSingleObject(event, INFINITE);
204 static void end_host_object(DWORD tid, HANDLE thread)
206 BOOL ret = PostThreadMessage(tid, WM_QUIT, 0, 0);
207 ok(ret, "PostThreadMessage failed with error %d\n", GetLastError());
208 /* be careful of races - don't return until hosting thread has terminated */
209 WaitForSingleObject(thread, INFINITE);
213 typedef struct Widget
215 const IWidgetVtbl *lpVtbl;
217 IUnknown *pDispatchUnknown;
220 HRESULT WINAPI Widget_QueryInterface(
222 /* [in] */ REFIID riid,
223 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
225 if (IsEqualIID(riid, &IID_IWidget) || IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch))
227 IWidget_AddRef(iface);
234 return E_NOINTERFACE;
238 ULONG WINAPI Widget_AddRef(
241 Widget *This = (Widget *)iface;
243 return InterlockedIncrement(&This->refs);
246 ULONG WINAPI Widget_Release(
249 Widget *This = (Widget *)iface;
250 ULONG refs = InterlockedDecrement(&This->refs);
253 IUnknown_Release(This->pDispatchUnknown);
254 memset(This, 0xcc, sizeof(*This));
255 HeapFree(GetProcessHeap(), 0, This);
256 trace("Widget destroyed!\n");
262 HRESULT WINAPI Widget_GetTypeInfoCount(
264 /* [out] */ UINT __RPC_FAR *pctinfo)
266 Widget *This = (Widget *)iface;
267 IDispatch *pDispatch;
268 HRESULT hr = IUnknown_QueryInterface(This->pDispatchUnknown, &IID_IDispatch, (void **)&pDispatch);
271 hr = IDispatch_GetTypeInfoCount(pDispatch, pctinfo);
272 IDispatch_Release(pDispatch);
277 HRESULT WINAPI Widget_GetTypeInfo(
278 IWidget __RPC_FAR * iface,
279 /* [in] */ UINT iTInfo,
280 /* [in] */ LCID lcid,
281 /* [out] */ ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo)
283 Widget *This = (Widget *)iface;
284 IDispatch *pDispatch;
285 HRESULT hr = IUnknown_QueryInterface(This->pDispatchUnknown, &IID_IDispatch, (void **)&pDispatch);
288 hr = IDispatch_GetTypeInfo(pDispatch, iTInfo, lcid, ppTInfo);
289 IDispatch_Release(pDispatch);
294 HRESULT WINAPI Widget_GetIDsOfNames(
295 IWidget __RPC_FAR * iface,
296 /* [in] */ REFIID riid,
297 /* [size_is][in] */ LPOLESTR __RPC_FAR *rgszNames,
298 /* [in] */ UINT cNames,
299 /* [in] */ LCID lcid,
300 /* [size_is][out] */ DISPID __RPC_FAR *rgDispId)
302 Widget *This = (Widget *)iface;
303 IDispatch *pDispatch;
304 HRESULT hr = IUnknown_QueryInterface(This->pDispatchUnknown, &IID_IDispatch, (void **)&pDispatch);
307 hr = IDispatch_GetIDsOfNames(pDispatch, riid, rgszNames, cNames, lcid, rgDispId);
308 IDispatch_Release(pDispatch);
313 HRESULT WINAPI Widget_Invoke(
314 IWidget __RPC_FAR * iface,
315 /* [in] */ DISPID dispIdMember,
316 /* [in] */ REFIID riid,
317 /* [in] */ LCID lcid,
318 /* [in] */ WORD wFlags,
319 /* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams,
320 /* [out] */ VARIANT __RPC_FAR *pVarResult,
321 /* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo,
322 /* [out] */ UINT __RPC_FAR *puArgErr)
324 Widget *This = (Widget *)iface;
325 IDispatch *pDispatch;
326 HRESULT hr = IUnknown_QueryInterface(This->pDispatchUnknown, &IID_IDispatch, (void **)&pDispatch);
329 hr = IDispatch_Invoke(pDispatch, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
330 IDispatch_Release(pDispatch);
335 HRESULT WINAPI Widget_put_Name(
336 IWidget __RPC_FAR * iface,
337 /* [in] */ BSTR name)
339 trace("put_Name(%s)\n", wine_dbgstr_w(name));
343 HRESULT WINAPI Widget_get_Name(
344 IWidget __RPC_FAR * iface,
345 /* [out] */ BSTR __RPC_FAR *name)
347 static const WCHAR szCat[] = { 'C','a','t',0 };
348 trace("get_Name()\n");
349 *name = SysAllocString(szCat);
353 HRESULT WINAPI Widget_DoSomething(
354 IWidget __RPC_FAR * iface,
355 /* [in] */ double number,
356 /* [out] */ BSTR *str1,
357 /* [defaultvalue][in] */ BSTR str2,
358 /* [optional][in] */ VARIANT __RPC_FAR *opt)
360 static const WCHAR szString[] = { 'S','t','r','i','n','g',0 };
361 trace("DoSomething()\n");
363 ok(number == 3.141, "number(%f) != 3.141\n", number);
364 ok(*str2 == '\0', "str2(%s) != \"\"\n", wine_dbgstr_w(str2));
365 ok(V_VT(opt) == VT_ERROR, "V_VT(opt) should be VT_ERROR instead of 0x%x\n", V_VT(opt));
366 ok(V_ERROR(opt) == DISP_E_PARAMNOTFOUND, "V_ERROR(opt) should be DISP_E_PARAMNOTFOUND instead of 0x%08x\n", V_ERROR(opt));
367 *str1 = SysAllocString(szString);
372 HRESULT WINAPI Widget_get_State(
373 IWidget __RPC_FAR * iface,
374 /* [retval][out] */ STATE __RPC_FAR *state)
376 trace("get_State() = STATE_WIDGETIFIED\n");
377 *state = STATE_WIDGETIFIED;
381 HRESULT WINAPI Widget_put_State(
382 IWidget __RPC_FAR * iface,
383 /* [in] */ STATE state)
385 trace("put_State(%d)\n", state);
389 HRESULT WINAPI Widget_Map(
394 trace("Map(%s, %p)\n", wine_dbgstr_w(bstrId), sValue);
395 *sValue = SysAllocString(bstrId);
399 HRESULT WINAPI Widget_SetOleColor(
403 trace("SetOleColor(0x%x)\n", val);
407 HRESULT WINAPI Widget_GetOleColor(
411 trace("GetOleColor() = 0x8000000f\n");
416 HRESULT WINAPI Widget_Clone(
421 return Widget_QueryInterface(iface, &IID_IWidget, (void **)ppVal);
424 HRESULT WINAPI Widget_CloneDispatch(
428 trace("CloneDispatch()\n");
429 return Widget_QueryInterface(iface, &IID_IWidget, (void **)ppVal);
432 HRESULT WINAPI Widget_CloneCoclass(
434 ApplicationObject2 **ppVal)
436 trace("CloneCoclass()\n");
440 HRESULT WINAPI Widget_Value(
441 IWidget __RPC_FAR * iface,
445 trace("Value(%p, %p)\n", value, retval);
446 ok(V_VT(value) == VT_I2, "V_VT(value) was %d instead of VT_I2\n", V_VT(value));
447 ok(V_I2(value) == 1, "V_I2(value) was %d instead of 1\n", V_I2(value));
448 V_VT(retval) = VT_I2;
453 HRESULT WINAPI Widget_Array(
457 trace("Array(%p)\n", values);
461 HRESULT WINAPI Widget_VariantArrayPtr(
465 trace("VariantArrayPtr(%p)\n", values);
469 void WINAPI Widget_Variant(
470 IWidget __RPC_FAR * iface,
473 trace("Variant()\n");
474 ok(V_VT(&var) == VT_CY, "V_VT(&var) was %d\n", V_VT(&var));
475 ok(S(V_CY(&var)).Hi == 0xdababe, "V_CY(&var).Hi was 0x%x\n", S(V_CY(&var)).Hi);
476 ok(S(V_CY(&var)).Lo == 0xdeadbeef, "V_CY(&var).Lo was 0x%x\n", S(V_CY(&var)).Lo);
479 void WINAPI Widget_VarArg(
484 LONG lbound, ubound, i;
488 trace("VarArg(%p)\n", values);
490 hr = SafeArrayGetLBound(values, 1, &lbound);
491 ok(hr == S_OK, "SafeArrayGetLBound failed with %x\n", hr);
492 ok(lbound == 0, "SafeArrayGetLBound returned %d\n", lbound);
494 hr = SafeArrayGetUBound(values, 1, &ubound);
495 ok(hr == S_OK, "SafeArrayGetUBound failed with %x\n", hr);
496 ok(ubound == numexpect-1, "SafeArrayGetUBound returned %d, but expected %d\n", ubound, numexpect-1);
498 hr = SafeArrayAccessData(values, (LPVOID)&data);
499 ok(hr == S_OK, "SafeArrayAccessData failed with %x\n", hr);
501 for (i=0; i<=ubound-lbound; i++)
503 ok(V_VT(&data[i]) == VT_I4, "V_VT(&data[%d]) was %d\n", i, V_VT(&data[i]));
504 ok(V_I4(&data[i]) == i, "V_I4(&data[%d]) was %d\n", i, V_I4(&data[i]));
507 hr = SafeArrayUnaccessData(values);
508 ok(hr == S_OK, "SafeArrayUnaccessData failed with %x\n", hr);
511 HRESULT WINAPI Widget_Error(
512 IWidget __RPC_FAR * iface)
518 static const struct IWidgetVtbl Widget_VTable =
520 Widget_QueryInterface,
523 Widget_GetTypeInfoCount,
525 Widget_GetIDsOfNames,
536 Widget_CloneDispatch,
540 Widget_VariantArrayPtr,
547 typedef struct KindaEnum
549 const IKindaEnumWidgetVtbl *lpVtbl;
553 static HRESULT register_current_module_typelib(void)
555 WCHAR path[MAX_PATH];
559 GetModuleFileNameW(NULL, path, MAX_PATH);
561 hr = LoadTypeLib(path, &typelib);
564 hr = RegisterTypeLib(typelib, path, NULL);
565 ITypeLib_Release(typelib);
570 static IWidget *Widget_Create(void)
572 Widget *This = (Widget *)HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
576 This->lpVtbl = &Widget_VTable;
579 hr = LoadRegTypeLib(&LIBID_TestTypelib, 1, 0, LOCALE_NEUTRAL, &pTypeLib);
580 ok_ole_success(hr, LoadRegTypeLib);
583 ITypeInfo *pTypeInfo;
584 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IWidget, &pTypeInfo);
585 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
588 This->pDispatchUnknown = NULL;
589 hr = CreateStdDispatch((IUnknown *)&This->lpVtbl, This, pTypeInfo, &This->pDispatchUnknown);
590 ok_ole_success(hr, CreateStdDispatch);
591 ITypeInfo_Release(pTypeInfo);
596 return (IWidget *)&This->lpVtbl;
599 HeapFree(GetProcessHeap(), 0, This);
604 HRESULT WINAPI KindaEnum_QueryInterface(
605 IKindaEnumWidget *iface,
606 /* [in] */ REFIID riid,
607 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
609 if (IsEqualIID(riid, &IID_IKindaEnumWidget) || IsEqualIID(riid, &IID_IUnknown))
611 IKindaEnumWidget_AddRef(iface);
618 return E_NOINTERFACE;
622 ULONG WINAPI KindaEnum_AddRef(
623 IKindaEnumWidget *iface)
625 KindaEnum *This = (KindaEnum *)iface;
627 return InterlockedIncrement(&This->refs);
630 ULONG WINAPI KindaEnum_Release(
631 IKindaEnumWidget *iface)
633 KindaEnum *This = (KindaEnum *)iface;
634 ULONG refs = InterlockedDecrement(&This->refs);
637 memset(This, 0xcc, sizeof(*This));
638 HeapFree(GetProcessHeap(), 0, This);
639 trace("KindaEnumWidget destroyed!\n");
645 HRESULT WINAPI KindaEnum_Next(
646 IKindaEnumWidget *iface,
647 /* [out] */ IWidget __RPC_FAR *__RPC_FAR *widget)
649 *widget = Widget_Create();
653 return E_OUTOFMEMORY;
656 HRESULT WINAPI KindaEnum_Count(
657 IKindaEnumWidget *iface,
658 /* [out] */ unsigned long __RPC_FAR *count)
663 HRESULT WINAPI KindaEnum_Reset(
664 IKindaEnumWidget *iface)
669 HRESULT WINAPI KindaEnum_Clone(
670 IKindaEnumWidget *iface,
671 /* [out] */ IKindaEnumWidget __RPC_FAR *__RPC_FAR *ppenum)
676 static const IKindaEnumWidgetVtbl KindaEnumWidget_VTable =
678 KindaEnum_QueryInterface,
687 static IKindaEnumWidget *KindaEnumWidget_Create(void)
691 This = (KindaEnum *)HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
692 if (!This) return NULL;
693 This->lpVtbl = &KindaEnumWidget_VTable;
695 return (IKindaEnumWidget *)This;
698 static HRESULT WINAPI NonOleAutomation_QueryInterface(INonOleAutomation *iface, REFIID riid, void **ppv)
700 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_INonOleAutomation))
702 *(INonOleAutomation **)ppv = iface;
706 return E_NOINTERFACE;
709 static ULONG WINAPI NonOleAutomation_AddRef(INonOleAutomation *iface)
714 static ULONG WINAPI NonOleAutomation_Release(INonOleAutomation *iface)
719 static BSTR WINAPI NonOleAutomation_BstrRet(INonOleAutomation *iface)
721 static const WCHAR wszTestString[] = {'T','h','i','s',' ','i','s',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0};
722 return SysAllocString(wszTestString);
725 static INonOleAutomationVtbl NonOleAutomation_VTable =
727 NonOleAutomation_QueryInterface,
728 NonOleAutomation_AddRef,
729 NonOleAutomation_Release,
730 NonOleAutomation_BstrRet,
733 static INonOleAutomation NonOleAutomation = { &NonOleAutomation_VTable };
735 static ITypeInfo *NonOleAutomation_GetTypeInfo(void)
738 HRESULT hr = LoadRegTypeLib(&LIBID_TestTypelib, 1, 0, LOCALE_NEUTRAL, &pTypeLib);
739 ok_ole_success(hr, LoadRegTypeLib);
742 ITypeInfo *pTypeInfo;
743 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_INonOleAutomation, &pTypeInfo);
744 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
750 static void test_typelibmarshal(void)
752 static const WCHAR szCat[] = { 'C','a','t',0 };
753 static const WCHAR szTestTest[] = { 'T','e','s','t','T','e','s','t',0 };
754 static WCHAR szSuperman[] = { 'S','u','p','e','r','m','a','n',0 };
756 IKindaEnumWidget *pKEW = KindaEnumWidget_Create();
759 IDispatch *pDispatch;
760 static const LARGE_INTEGER ullZero;
763 DISPID dispidNamed = DISPID_PROPERTYPUT;
764 DISPPARAMS dispparams;
765 VARIANTARG vararg[4];
770 ITypeInfo *pTypeInfo;
772 ok(pKEW != NULL, "Widget creation failed\n");
774 hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
775 ok_ole_success(hr, CreateStreamOnHGlobal);
776 tid = start_host_object(pStream, &IID_IKindaEnumWidget, (IUnknown *)pKEW, MSHLFLAGS_NORMAL, &thread);
778 IStream_Seek(pStream, ullZero, STREAM_SEEK_SET, NULL);
779 hr = CoUnmarshalInterface(pStream, &IID_IKindaEnumWidget, (void **)&pKEW);
780 ok_ole_success(hr, CoUnmarshalInterface);
781 IStream_Release(pStream);
783 hr = IKindaEnumWidget_Next(pKEW, &pWidget);
784 ok_ole_success(hr, IKindaEnumWidget_Next);
786 IKindaEnumWidget_Release(pKEW);
788 hr = IWidget_QueryInterface(pWidget, &IID_IDispatch, (void **)&pDispatch);
791 VariantInit(&vararg[0]);
792 dispparams.cNamedArgs = 1;
793 dispparams.rgdispidNamedArgs = &dispidNamed;
794 dispparams.cArgs = 1;
795 dispparams.rgvarg = vararg;
796 VariantInit(&varresult);
797 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
798 ok_ole_success(hr, IDispatch_Invoke);
799 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
800 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
801 excepinfo.wCode, excepinfo.scode);
802 VariantClear(&varresult);
804 /* call put_Name (direct) */
805 bstr = SysAllocString(szSuperman);
806 hr = IWidget_put_Name(pWidget, bstr);
807 ok_ole_success(hr, IWidget_put_Name);
811 dispparams.cNamedArgs = 0;
812 dispparams.rgdispidNamedArgs = NULL;
813 dispparams.cArgs = 0;
814 dispparams.rgvarg = NULL;
815 VariantInit(&varresult);
816 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
817 ok_ole_success(hr, IDispatch_Invoke);
818 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
819 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
820 excepinfo.wCode, excepinfo.scode);
821 trace("Name = %s\n", wine_dbgstr_w(V_BSTR(&varresult)));
822 VariantClear(&varresult);
824 /* call get_Name (direct) */
826 hr = IWidget_get_Name(pWidget, &bstr);
827 ok_ole_success(hr, IWidget_get_Name);
828 ok(!lstrcmpW(bstr, szCat), "IWidget_get_Name should have returned string \"Cat\" instead of %s\n", wine_dbgstr_w(bstr));
831 /* call DoSomething */
832 VariantInit(&vararg[0]);
833 VariantInit(&vararg[1]);
834 V_VT(&vararg[1]) = VT_R8;
835 V_R8(&vararg[1]) = 3.141;
836 dispparams.cNamedArgs = 0;
837 dispparams.cArgs = 2;
838 dispparams.rgdispidNamedArgs = NULL;
839 dispparams.rgvarg = vararg;
840 VariantInit(&varresult);
841 hr = IDispatch_Invoke(pDispatch, DISPID_TM_DOSOMETHING, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
842 ok_ole_success(hr, IDispatch_Invoke);
843 ok(V_VT(&varresult) == VT_EMPTY, "varresult should be VT_EMPTY\n");
844 VariantClear(&varresult);
847 dispparams.cNamedArgs = 0;
848 dispparams.cArgs = 0;
849 dispparams.rgdispidNamedArgs = NULL;
850 dispparams.rgvarg = NULL;
851 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
852 ok_ole_success(hr, IDispatch_Invoke);
853 ok((V_VT(&varresult) == VT_I4) && (V_I4(&varresult) == STATE_WIDGETIFIED), "Return val mismatch\n");
855 /* call get_State (direct) */
856 hr = IWidget_get_State(pWidget, &the_state);
857 ok_ole_success(hr, IWidget_get_state);
858 ok(the_state == STATE_WIDGETIFIED, "should have returned WIDGET_WIDGETIFIED instead of %d\n", the_state);
861 the_state = STATE_WIDGETIFIED;
862 VariantInit(&vararg[0]);
863 V_VT(&vararg[0]) = VT_BYREF|VT_I4;
864 V_I4REF(&vararg[0]) = (int *)&the_state;
865 dispparams.cNamedArgs = 1;
866 dispparams.cArgs = 1;
867 dispparams.rgdispidNamedArgs = &dispidNamed;
868 dispparams.rgvarg = vararg;
869 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
870 ok_ole_success(hr, IDispatch_Invoke);
873 bstr = SysAllocString(szTestTest);
874 VariantInit(&vararg[0]);
875 V_VT(&vararg[0]) = VT_BYREF|VT_BSTR;
876 V_BSTRREF(&vararg[0]) = &bstr;
877 dispparams.cNamedArgs = 0;
878 dispparams.cArgs = 1;
879 dispparams.rgdispidNamedArgs = NULL;
880 dispparams.rgvarg = vararg;
881 VariantInit(&varresult);
882 hr = IDispatch_Invoke(pDispatch, DISPID_TM_MAP, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
883 ok_ole_success(hr, IDispatch_Invoke);
884 ok(V_VT(&varresult) == VT_BSTR, "Return value should be of type BSTR instead of %d\n", V_VT(&varresult));
885 ok(!lstrcmpW(V_BSTR(&varresult), szTestTest), "Return value should have been \"TestTest\" instead of %s\n", wine_dbgstr_w(V_BSTR(&varresult)));
886 VariantClear(&varresult);
888 /* call SetOleColor with large negative VT_I4 param */
889 VariantInit(&vararg[0]);
890 V_VT(&vararg[0]) = VT_I4;
891 V_I4(&vararg[0]) = 0x80000005;
892 dispparams.cNamedArgs = 0;
893 dispparams.cArgs = 1;
894 dispparams.rgdispidNamedArgs = NULL;
895 dispparams.rgvarg = vararg;
896 hr = IDispatch_Invoke(pDispatch, DISPID_TM_SETOLECOLOR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, &excepinfo, NULL);
897 ok_ole_success(hr, IDispatch_Invoke);
899 /* call GetOleColor */
900 dispparams.cNamedArgs = 0;
901 dispparams.cArgs = 0;
902 dispparams.rgdispidNamedArgs = NULL;
903 dispparams.rgvarg = NULL;
904 VariantInit(&varresult);
905 hr = IDispatch_Invoke(pDispatch, DISPID_TM_GETOLECOLOR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
906 ok_ole_success(hr, IDispatch_Invoke);
907 VariantClear(&varresult);
910 dispparams.cNamedArgs = 0;
911 dispparams.cArgs = 0;
912 dispparams.rgdispidNamedArgs = NULL;
913 dispparams.rgvarg = NULL;
914 VariantInit(&varresult);
915 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
916 ok_ole_success(hr, IDispatch_Invoke);
917 VariantClear(&varresult);
919 /* call CloneDispatch with automatic value getting */
920 V_VT(&vararg[0]) = VT_I2;
921 V_I2(&vararg[0]) = 1;
922 dispparams.cNamedArgs = 0;
923 dispparams.rgdispidNamedArgs = NULL;
924 dispparams.cArgs = 1;
925 dispparams.rgvarg = vararg;
926 VariantInit(&varresult);
927 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONEDISPATCH, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
928 ok_ole_success(hr, IDispatch_Invoke);
930 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
931 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
932 excepinfo.wCode, excepinfo.scode);
934 ok(V_VT(&varresult) == VT_I2, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult));
935 ok(V_I2(&varresult) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult));
936 VariantClear(&varresult);
938 /* call CloneCoclass */
939 dispparams.cNamedArgs = 0;
940 dispparams.cArgs = 0;
941 dispparams.rgdispidNamedArgs = NULL;
942 dispparams.rgvarg = NULL;
943 VariantInit(&varresult);
944 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONECOCLASS, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
945 ok_ole_success(hr, IDispatch_Invoke);
947 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
948 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
949 excepinfo.wCode, excepinfo.scode);
951 ok(V_VT(&varresult) == VT_DISPATCH, "V_VT(&varresult) was %d instead of VT_DISPATCH\n", V_VT(&varresult));
952 ok(!V_DISPATCH(&varresult), "V_DISPATCH(&varresult) should be NULL instead of %p\n", V_DISPATCH(&varresult));
953 VariantClear(&varresult);
955 /* call Value with a VT_VARIANT|VT_BYREF type */
956 V_VT(&vararg[0]) = VT_VARIANT|VT_BYREF;
957 V_VARIANTREF(&vararg[0]) = &vararg[1];
958 V_VT(&vararg[1]) = VT_I2;
959 V_I2(&vararg[1]) = 1;
960 dispparams.cNamedArgs = 0;
961 dispparams.rgdispidNamedArgs = NULL;
962 dispparams.cArgs = 1;
963 dispparams.rgvarg = vararg;
964 VariantInit(&varresult);
965 hr = IDispatch_Invoke(pDispatch, DISPID_VALUE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
966 ok_ole_success(hr, IDispatch_Invoke);
968 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
969 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
970 excepinfo.wCode, excepinfo.scode);
972 ok(V_VT(&varresult) == VT_I2, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult));
973 ok(V_I2(&varresult) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult));
974 VariantClear(&varresult);
976 /* call Variant - exercises variant copying in ITypeInfo::Invoke and
977 * handling of void return types */
978 /* use a big type to ensure that the variant was properly copied into the
979 * destination function's args */
980 V_VT(&vararg[0]) = VT_CY;
981 S(V_CY(&vararg[0])).Hi = 0xdababe;
982 S(V_CY(&vararg[0])).Lo = 0xdeadbeef;
983 dispparams.cNamedArgs = 0;
984 dispparams.cArgs = 1;
985 dispparams.rgdispidNamedArgs = NULL;
986 dispparams.rgvarg = vararg;
987 VariantInit(&varresult);
988 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARIANT, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
989 ok_ole_success(hr, IDispatch_Invoke);
990 VariantClear(&varresult);
993 VariantInit(&vararg[3]);
994 V_VT(&vararg[3]) = VT_I4;
995 V_I4(&vararg[3]) = 3;
996 VariantInit(&vararg[2]);
997 V_VT(&vararg[2]) = VT_I4;
998 V_I4(&vararg[2]) = 0;
999 VariantInit(&vararg[1]);
1000 V_VT(&vararg[1]) = VT_I4;
1001 V_I4(&vararg[1]) = 1;
1002 VariantInit(&vararg[0]);
1003 V_VT(&vararg[0]) = VT_I4;
1004 V_I4(&vararg[0]) = 2;
1005 dispparams.cNamedArgs = 0;
1006 dispparams.cArgs = 4;
1007 dispparams.rgdispidNamedArgs = NULL;
1008 dispparams.rgvarg = vararg;
1009 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARARG, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1010 ok_ole_success(hr, ITypeInfo_Invoke);
1012 /* call VarArg, even one (non-optional, non-safearray) named argument is not allowed */
1014 dispparams.cNamedArgs = 1;
1015 dispparams.rgdispidNamedArgs = &dispidNamed;
1016 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARARG, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1017 ok(hr == DISP_E_NONAMEDARGS, "IDispatch_Invoke should have returned DISP_E_NONAMEDARGS instead of 0x%08x\n", hr);
1018 dispidNamed = DISPID_PROPERTYPUT;
1021 dispparams.cNamedArgs = 0;
1022 dispparams.cArgs = 0;
1023 dispparams.rgdispidNamedArgs = NULL;
1024 dispparams.rgvarg = NULL;
1025 VariantInit(&varresult);
1026 hr = IDispatch_Invoke(pDispatch, DISPID_TM_ERROR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, &excepinfo, NULL);
1027 ok(hr == DISP_E_EXCEPTION, "IDispatch_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr);
1028 ok(excepinfo.wCode == 0x0 && excepinfo.scode == E_NOTIMPL,
1029 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1030 excepinfo.wCode, excepinfo.scode);
1031 VariantClear(&varresult);
1034 pTypeInfo = NonOleAutomation_GetTypeInfo();
1035 dispparams.cNamedArgs = 0;
1036 dispparams.cArgs = 0;
1037 dispparams.rgdispidNamedArgs = NULL;
1038 dispparams.rgvarg = NULL;
1039 VariantInit(&varresult);
1040 hr = ITypeInfo_Invoke(pTypeInfo, &NonOleAutomation, DISPID_NOA_BSTRRET, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1041 ok_ole_success(hr, ITypeInfo_Invoke);
1042 ok(V_VT(&varresult) == VT_BSTR, "V_VT(&varresult) should be VT_BSTR instead of %d\n", V_VT(&varresult));
1043 ok(V_BSTR(&varresult) != NULL, "V_BSTR(&varresult) should not be NULL\n");
1045 VariantClear(&varresult);
1046 ITypeInfo_Release(pTypeInfo);
1048 /* tests call put_Name without named arg */
1049 VariantInit(&vararg[0]);
1050 dispparams.cNamedArgs = 0;
1051 dispparams.rgdispidNamedArgs = NULL;
1052 dispparams.cArgs = 1;
1053 dispparams.rgvarg = vararg;
1054 VariantInit(&varresult);
1055 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1056 ok(hr == DISP_E_PARAMNOTFOUND, "IDispatch_Invoke should have returned DISP_E_PARAMNOTFOUND instead of 0x%08x\n", hr);
1057 VariantClear(&varresult);
1059 /* tests param type that cannot be coerced */
1060 VariantInit(&vararg[0]);
1061 V_VT(&vararg[0]) = VT_UNKNOWN;
1062 V_UNKNOWN(&vararg[0]) = NULL;
1063 dispparams.cNamedArgs = 1;
1064 dispparams.rgdispidNamedArgs = &dispidNamed;
1065 dispparams.cArgs = 1;
1066 dispparams.rgvarg = vararg;
1067 VariantInit(&varresult);
1068 #if 0 /* NULL unknown not currently marshaled correctly */
1069 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1070 ok(hr == DISP_E_TYPEMISMATCH, "IDispatch_Invoke should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hr);
1072 VariantClear(&varresult);
1074 /* tests bad param type */
1075 VariantInit(&vararg[0]);
1076 V_VT(&vararg[0]) = VT_CLSID;
1077 V_BYREF(&vararg[0]) = NULL;
1078 dispparams.cNamedArgs = 1;
1079 dispparams.rgdispidNamedArgs = &dispidNamed;
1080 dispparams.cArgs = 1;
1081 dispparams.rgvarg = vararg;
1082 VariantInit(&varresult);
1083 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1084 ok(hr == DISP_E_BADVARTYPE, "IDispatch_Invoke should have returned DISP_E_BADVARTYPE instead of 0x%08x\n", hr);
1085 VariantClear(&varresult);
1087 /* tests too small param count */
1088 dispparams.cNamedArgs = 0;
1089 dispparams.rgdispidNamedArgs = NULL;
1090 dispparams.cArgs = 0;
1091 dispparams.rgvarg = NULL;
1092 VariantInit(&varresult);
1093 hr = IDispatch_Invoke(pDispatch, DISPID_TM_DOSOMETHING, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1094 ok(hr == DISP_E_BADPARAMCOUNT, "IDispatch_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr);
1095 VariantClear(&varresult);
1097 /* tests propget function with large param count */
1098 VariantInit(&vararg[0]);
1099 V_VT(&vararg[0]) = VT_BSTR;
1100 V_BSTR(&vararg[0]) = NULL;
1101 V_VT(&vararg[1]) = VT_I4;
1102 V_I4(&vararg[1]) = 1;
1103 dispparams.cNamedArgs = 0;
1104 dispparams.cArgs = 2;
1105 dispparams.rgdispidNamedArgs = NULL;
1106 dispparams.rgvarg = vararg;
1107 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1108 ok(hr == DISP_E_NOTACOLLECTION, "IDispatch_Invoke should have returned DISP_E_NOTACOLLECTION instead of 0x%08x\n", hr);
1110 IDispatch_Release(pDispatch);
1111 IWidget_Release(pWidget);
1113 trace("calling end_host_object\n");
1114 end_host_object(tid, thread);
1117 static void test_DispCallFunc(void)
1119 static const WCHAR szEmpty[] = { 0 };
1120 VARTYPE rgvt[] = { VT_R8, VT_BSTR, VT_BSTR, VT_VARIANT|VT_BYREF };
1121 VARIANTARG vararg[4];
1123 VARIANTARG *rgpvarg[4] = { &vararg[0], &vararg[1], &vararg[2], &vararg[3] };
1124 VARIANTARG varresult;
1126 IWidget *pWidget = Widget_Create();
1127 V_VT(&vararg[0]) = VT_R8;
1128 V_R8(&vararg[0]) = 3.141;
1129 V_VT(&vararg[1]) = VT_BSTR;
1130 V_BSTR(&vararg[1]) = SysAllocString(szEmpty);
1131 V_VT(&vararg[2]) = VT_BSTR;
1132 V_BSTR(&vararg[2]) = SysAllocString(szEmpty);
1133 V_VT(&vararg[3]) = VT_VARIANT|VT_BYREF;
1134 V_VARIANTREF(&vararg[3]) = &varref;
1135 V_VT(&varref) = VT_ERROR;
1136 V_ERROR(&varref) = DISP_E_PARAMNOTFOUND;
1137 VariantInit(&varresult);
1138 hr = DispCallFunc(pWidget, 36, CC_STDCALL, VT_UI4, 4, rgvt, rgpvarg, &varresult);
1139 ok_ole_success(hr, DispCallFunc);
1140 VariantClear(&varresult);
1143 START_TEST(tmarshal)
1147 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1149 hr = register_current_module_typelib();
1150 ok_ole_success(hr, register_current_module_typelib);
1152 test_typelibmarshal();
1153 test_DispCallFunc();