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 HRESULT WINAPI Widget_CloneInterface(
519 IWidget __RPC_FAR * iface,
520 ISomethingFromDispatch **ppVal)
522 trace("CloneInterface()\n");
527 static const struct IWidgetVtbl Widget_VTable =
529 Widget_QueryInterface,
532 Widget_GetTypeInfoCount,
534 Widget_GetIDsOfNames,
545 Widget_CloneDispatch,
549 Widget_VariantArrayPtr,
553 Widget_CloneInterface
557 typedef struct KindaEnum
559 const IKindaEnumWidgetVtbl *lpVtbl;
563 static HRESULT register_current_module_typelib(void)
565 WCHAR path[MAX_PATH];
569 GetModuleFileNameW(NULL, path, MAX_PATH);
571 hr = LoadTypeLib(path, &typelib);
574 hr = RegisterTypeLib(typelib, path, NULL);
575 ITypeLib_Release(typelib);
580 static IWidget *Widget_Create(void)
582 Widget *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
586 This->lpVtbl = &Widget_VTable;
589 hr = LoadRegTypeLib(&LIBID_TestTypelib, 1, 0, LOCALE_NEUTRAL, &pTypeLib);
590 ok_ole_success(hr, LoadRegTypeLib);
593 ITypeInfo *pTypeInfo;
594 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_IWidget, &pTypeInfo);
595 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
598 This->pDispatchUnknown = NULL;
599 hr = CreateStdDispatch((IUnknown *)&This->lpVtbl, This, pTypeInfo, &This->pDispatchUnknown);
600 ok_ole_success(hr, CreateStdDispatch);
601 ITypeInfo_Release(pTypeInfo);
603 ITypeLib_Release(pTypeLib);
607 return (IWidget *)&This->lpVtbl;
610 HeapFree(GetProcessHeap(), 0, This);
615 HRESULT WINAPI KindaEnum_QueryInterface(
616 IKindaEnumWidget *iface,
617 /* [in] */ REFIID riid,
618 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
620 if (IsEqualIID(riid, &IID_IKindaEnumWidget) || IsEqualIID(riid, &IID_IUnknown))
622 IKindaEnumWidget_AddRef(iface);
629 return E_NOINTERFACE;
633 ULONG WINAPI KindaEnum_AddRef(
634 IKindaEnumWidget *iface)
636 KindaEnum *This = (KindaEnum *)iface;
638 return InterlockedIncrement(&This->refs);
641 ULONG WINAPI KindaEnum_Release(
642 IKindaEnumWidget *iface)
644 KindaEnum *This = (KindaEnum *)iface;
645 ULONG refs = InterlockedDecrement(&This->refs);
648 memset(This, 0xcc, sizeof(*This));
649 HeapFree(GetProcessHeap(), 0, This);
650 trace("KindaEnumWidget destroyed!\n");
656 HRESULT WINAPI KindaEnum_Next(
657 IKindaEnumWidget *iface,
658 /* [out] */ IWidget __RPC_FAR *__RPC_FAR *widget)
660 *widget = Widget_Create();
664 return E_OUTOFMEMORY;
667 HRESULT WINAPI KindaEnum_Count(
668 IKindaEnumWidget *iface,
669 /* [out] */ unsigned long __RPC_FAR *count)
674 HRESULT WINAPI KindaEnum_Reset(
675 IKindaEnumWidget *iface)
680 HRESULT WINAPI KindaEnum_Clone(
681 IKindaEnumWidget *iface,
682 /* [out] */ IKindaEnumWidget __RPC_FAR *__RPC_FAR *ppenum)
687 static const IKindaEnumWidgetVtbl KindaEnumWidget_VTable =
689 KindaEnum_QueryInterface,
698 static IKindaEnumWidget *KindaEnumWidget_Create(void)
702 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
703 if (!This) return NULL;
704 This->lpVtbl = &KindaEnumWidget_VTable;
706 return (IKindaEnumWidget *)This;
709 static HRESULT WINAPI NonOleAutomation_QueryInterface(INonOleAutomation *iface, REFIID riid, void **ppv)
711 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_INonOleAutomation))
713 *(INonOleAutomation **)ppv = iface;
717 return E_NOINTERFACE;
720 static ULONG WINAPI NonOleAutomation_AddRef(INonOleAutomation *iface)
725 static ULONG WINAPI NonOleAutomation_Release(INonOleAutomation *iface)
730 static BSTR WINAPI NonOleAutomation_BstrRet(INonOleAutomation *iface)
732 static const WCHAR wszTestString[] = {'T','h','i','s',' ','i','s',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0};
733 return SysAllocString(wszTestString);
736 static INonOleAutomationVtbl NonOleAutomation_VTable =
738 NonOleAutomation_QueryInterface,
739 NonOleAutomation_AddRef,
740 NonOleAutomation_Release,
741 NonOleAutomation_BstrRet,
744 static INonOleAutomation NonOleAutomation = { &NonOleAutomation_VTable };
746 static ITypeInfo *NonOleAutomation_GetTypeInfo(void)
749 HRESULT hr = LoadRegTypeLib(&LIBID_TestTypelib, 1, 0, LOCALE_NEUTRAL, &pTypeLib);
750 ok_ole_success(hr, LoadRegTypeLib);
753 ITypeInfo *pTypeInfo;
754 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_INonOleAutomation, &pTypeInfo);
755 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
761 static void test_typelibmarshal(void)
763 static const WCHAR szCat[] = { 'C','a','t',0 };
764 static const WCHAR szTestTest[] = { 'T','e','s','t','T','e','s','t',0 };
765 static WCHAR szSuperman[] = { 'S','u','p','e','r','m','a','n',0 };
767 IKindaEnumWidget *pKEW = KindaEnumWidget_Create();
770 IDispatch *pDispatch;
771 static const LARGE_INTEGER ullZero;
774 DISPID dispidNamed = DISPID_PROPERTYPUT;
775 DISPPARAMS dispparams;
776 VARIANTARG vararg[4];
781 ITypeInfo *pTypeInfo;
783 ok(pKEW != NULL, "Widget creation failed\n");
785 hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
786 ok_ole_success(hr, CreateStreamOnHGlobal);
787 tid = start_host_object(pStream, &IID_IKindaEnumWidget, (IUnknown *)pKEW, MSHLFLAGS_NORMAL, &thread);
789 IStream_Seek(pStream, ullZero, STREAM_SEEK_SET, NULL);
790 hr = CoUnmarshalInterface(pStream, &IID_IKindaEnumWidget, (void **)&pKEW);
791 ok_ole_success(hr, CoUnmarshalInterface);
792 IStream_Release(pStream);
794 hr = IKindaEnumWidget_Next(pKEW, &pWidget);
795 ok_ole_success(hr, IKindaEnumWidget_Next);
797 IKindaEnumWidget_Release(pKEW);
799 hr = IWidget_QueryInterface(pWidget, &IID_IDispatch, (void **)&pDispatch);
802 VariantInit(&vararg[0]);
803 dispparams.cNamedArgs = 1;
804 dispparams.rgdispidNamedArgs = &dispidNamed;
805 dispparams.cArgs = 1;
806 dispparams.rgvarg = vararg;
807 VariantInit(&varresult);
808 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
809 ok_ole_success(hr, IDispatch_Invoke);
810 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
811 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
812 excepinfo.wCode, excepinfo.scode);
813 VariantClear(&varresult);
815 /* call put_Name (direct) */
816 bstr = SysAllocString(szSuperman);
817 hr = IWidget_put_Name(pWidget, bstr);
818 ok_ole_success(hr, IWidget_put_Name);
822 dispparams.cNamedArgs = 0;
823 dispparams.rgdispidNamedArgs = NULL;
824 dispparams.cArgs = 0;
825 dispparams.rgvarg = NULL;
826 VariantInit(&varresult);
827 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
828 ok_ole_success(hr, IDispatch_Invoke);
829 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
830 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
831 excepinfo.wCode, excepinfo.scode);
832 trace("Name = %s\n", wine_dbgstr_w(V_BSTR(&varresult)));
833 VariantClear(&varresult);
835 /* call get_Name (direct) */
837 hr = IWidget_get_Name(pWidget, &bstr);
838 ok_ole_success(hr, IWidget_get_Name);
839 ok(!lstrcmpW(bstr, szCat), "IWidget_get_Name should have returned string \"Cat\" instead of %s\n", wine_dbgstr_w(bstr));
842 /* call DoSomething */
843 VariantInit(&vararg[0]);
844 VariantInit(&vararg[1]);
845 V_VT(&vararg[1]) = VT_R8;
846 V_R8(&vararg[1]) = 3.141;
847 dispparams.cNamedArgs = 0;
848 dispparams.cArgs = 2;
849 dispparams.rgdispidNamedArgs = NULL;
850 dispparams.rgvarg = vararg;
851 VariantInit(&varresult);
852 hr = IDispatch_Invoke(pDispatch, DISPID_TM_DOSOMETHING, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
853 ok_ole_success(hr, IDispatch_Invoke);
854 ok(V_VT(&varresult) == VT_EMPTY, "varresult should be VT_EMPTY\n");
855 VariantClear(&varresult);
858 dispparams.cNamedArgs = 0;
859 dispparams.cArgs = 0;
860 dispparams.rgdispidNamedArgs = NULL;
861 dispparams.rgvarg = NULL;
862 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
863 ok_ole_success(hr, IDispatch_Invoke);
864 ok((V_VT(&varresult) == VT_I4) && (V_I4(&varresult) == STATE_WIDGETIFIED), "Return val mismatch\n");
866 /* call get_State (direct) */
867 hr = IWidget_get_State(pWidget, &the_state);
868 ok_ole_success(hr, IWidget_get_state);
869 ok(the_state == STATE_WIDGETIFIED, "should have returned WIDGET_WIDGETIFIED instead of %d\n", the_state);
872 the_state = STATE_WIDGETIFIED;
873 VariantInit(&vararg[0]);
874 V_VT(&vararg[0]) = VT_BYREF|VT_I4;
875 V_I4REF(&vararg[0]) = (int *)&the_state;
876 dispparams.cNamedArgs = 1;
877 dispparams.cArgs = 1;
878 dispparams.rgdispidNamedArgs = &dispidNamed;
879 dispparams.rgvarg = vararg;
880 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
881 ok_ole_success(hr, IDispatch_Invoke);
884 bstr = SysAllocString(szTestTest);
885 VariantInit(&vararg[0]);
886 V_VT(&vararg[0]) = VT_BYREF|VT_BSTR;
887 V_BSTRREF(&vararg[0]) = &bstr;
888 dispparams.cNamedArgs = 0;
889 dispparams.cArgs = 1;
890 dispparams.rgdispidNamedArgs = NULL;
891 dispparams.rgvarg = vararg;
892 VariantInit(&varresult);
893 hr = IDispatch_Invoke(pDispatch, DISPID_TM_MAP, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
894 ok_ole_success(hr, IDispatch_Invoke);
895 ok(V_VT(&varresult) == VT_BSTR, "Return value should be of type BSTR instead of %d\n", V_VT(&varresult));
896 ok(!lstrcmpW(V_BSTR(&varresult), szTestTest), "Return value should have been \"TestTest\" instead of %s\n", wine_dbgstr_w(V_BSTR(&varresult)));
897 VariantClear(&varresult);
899 /* call SetOleColor with large negative VT_I4 param */
900 VariantInit(&vararg[0]);
901 V_VT(&vararg[0]) = VT_I4;
902 V_I4(&vararg[0]) = 0x80000005;
903 dispparams.cNamedArgs = 0;
904 dispparams.cArgs = 1;
905 dispparams.rgdispidNamedArgs = NULL;
906 dispparams.rgvarg = vararg;
907 hr = IDispatch_Invoke(pDispatch, DISPID_TM_SETOLECOLOR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, &excepinfo, NULL);
908 ok_ole_success(hr, IDispatch_Invoke);
910 /* call GetOleColor */
911 dispparams.cNamedArgs = 0;
912 dispparams.cArgs = 0;
913 dispparams.rgdispidNamedArgs = NULL;
914 dispparams.rgvarg = NULL;
915 VariantInit(&varresult);
916 hr = IDispatch_Invoke(pDispatch, DISPID_TM_GETOLECOLOR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
917 ok_ole_success(hr, IDispatch_Invoke);
918 VariantClear(&varresult);
921 dispparams.cNamedArgs = 0;
922 dispparams.cArgs = 0;
923 dispparams.rgdispidNamedArgs = NULL;
924 dispparams.rgvarg = NULL;
925 VariantInit(&varresult);
926 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
927 ok_ole_success(hr, IDispatch_Invoke);
928 ok(V_VT(&varresult) == VT_DISPATCH, "vt %x\n", V_VT(&varresult));
929 VariantClear(&varresult);
931 /* call CloneInterface */
932 dispparams.cNamedArgs = 0;
933 dispparams.cArgs = 0;
934 dispparams.rgdispidNamedArgs = NULL;
935 dispparams.rgvarg = NULL;
936 VariantInit(&varresult);
937 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONEINTERFACE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
938 ok_ole_success(hr, IDispatch_Invoke);
939 ok(V_VT(&varresult) == VT_DISPATCH, "vt %x\n", V_VT(&varresult));
940 VariantClear(&varresult);
942 /* call CloneDispatch with automatic value getting */
943 V_VT(&vararg[0]) = VT_I2;
944 V_I2(&vararg[0]) = 1;
945 dispparams.cNamedArgs = 0;
946 dispparams.rgdispidNamedArgs = NULL;
947 dispparams.cArgs = 1;
948 dispparams.rgvarg = vararg;
949 VariantInit(&varresult);
950 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONEDISPATCH, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
951 ok_ole_success(hr, IDispatch_Invoke);
953 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
954 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
955 excepinfo.wCode, excepinfo.scode);
957 ok(V_VT(&varresult) == VT_I2, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult));
958 ok(V_I2(&varresult) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult));
959 VariantClear(&varresult);
961 /* call CloneCoclass */
962 dispparams.cNamedArgs = 0;
963 dispparams.cArgs = 0;
964 dispparams.rgdispidNamedArgs = NULL;
965 dispparams.rgvarg = NULL;
966 VariantInit(&varresult);
967 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONECOCLASS, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
968 ok_ole_success(hr, IDispatch_Invoke);
970 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
971 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
972 excepinfo.wCode, excepinfo.scode);
974 ok(V_VT(&varresult) == VT_DISPATCH, "V_VT(&varresult) was %d instead of VT_DISPATCH\n", V_VT(&varresult));
975 ok(!V_DISPATCH(&varresult), "V_DISPATCH(&varresult) should be NULL instead of %p\n", V_DISPATCH(&varresult));
976 VariantClear(&varresult);
978 /* call Value with a VT_VARIANT|VT_BYREF type */
979 V_VT(&vararg[0]) = VT_VARIANT|VT_BYREF;
980 V_VARIANTREF(&vararg[0]) = &vararg[1];
981 V_VT(&vararg[1]) = VT_I2;
982 V_I2(&vararg[1]) = 1;
983 dispparams.cNamedArgs = 0;
984 dispparams.rgdispidNamedArgs = NULL;
985 dispparams.cArgs = 1;
986 dispparams.rgvarg = vararg;
987 VariantInit(&varresult);
988 hr = IDispatch_Invoke(pDispatch, DISPID_VALUE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
989 ok_ole_success(hr, IDispatch_Invoke);
991 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
992 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
993 excepinfo.wCode, excepinfo.scode);
995 ok(V_VT(&varresult) == VT_I2, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult));
996 ok(V_I2(&varresult) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult));
997 VariantClear(&varresult);
999 /* call Variant - exercises variant copying in ITypeInfo::Invoke and
1000 * handling of void return types */
1001 /* use a big type to ensure that the variant was properly copied into the
1002 * destination function's args */
1003 V_VT(&vararg[0]) = VT_CY;
1004 S(V_CY(&vararg[0])).Hi = 0xdababe;
1005 S(V_CY(&vararg[0])).Lo = 0xdeadbeef;
1006 dispparams.cNamedArgs = 0;
1007 dispparams.cArgs = 1;
1008 dispparams.rgdispidNamedArgs = NULL;
1009 dispparams.rgvarg = vararg;
1010 VariantInit(&varresult);
1011 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARIANT, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1012 ok_ole_success(hr, IDispatch_Invoke);
1013 VariantClear(&varresult);
1016 VariantInit(&vararg[3]);
1017 V_VT(&vararg[3]) = VT_I4;
1018 V_I4(&vararg[3]) = 3;
1019 VariantInit(&vararg[2]);
1020 V_VT(&vararg[2]) = VT_I4;
1021 V_I4(&vararg[2]) = 0;
1022 VariantInit(&vararg[1]);
1023 V_VT(&vararg[1]) = VT_I4;
1024 V_I4(&vararg[1]) = 1;
1025 VariantInit(&vararg[0]);
1026 V_VT(&vararg[0]) = VT_I4;
1027 V_I4(&vararg[0]) = 2;
1028 dispparams.cNamedArgs = 0;
1029 dispparams.cArgs = 4;
1030 dispparams.rgdispidNamedArgs = NULL;
1031 dispparams.rgvarg = vararg;
1032 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARARG, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1033 ok_ole_success(hr, ITypeInfo_Invoke);
1035 /* call VarArg, even one (non-optional, non-safearray) named argument is not allowed */
1037 dispparams.cNamedArgs = 1;
1038 dispparams.rgdispidNamedArgs = &dispidNamed;
1039 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARARG, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1040 ok(hr == DISP_E_NONAMEDARGS, "IDispatch_Invoke should have returned DISP_E_NONAMEDARGS instead of 0x%08x\n", hr);
1041 dispidNamed = DISPID_PROPERTYPUT;
1044 dispparams.cNamedArgs = 0;
1045 dispparams.cArgs = 0;
1046 dispparams.rgdispidNamedArgs = NULL;
1047 dispparams.rgvarg = NULL;
1048 VariantInit(&varresult);
1049 hr = IDispatch_Invoke(pDispatch, DISPID_TM_ERROR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, &excepinfo, NULL);
1050 ok(hr == DISP_E_EXCEPTION, "IDispatch_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr);
1051 ok(excepinfo.wCode == 0x0 && excepinfo.scode == E_NOTIMPL,
1052 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1053 excepinfo.wCode, excepinfo.scode);
1054 VariantClear(&varresult);
1057 pTypeInfo = NonOleAutomation_GetTypeInfo();
1058 dispparams.cNamedArgs = 0;
1059 dispparams.cArgs = 0;
1060 dispparams.rgdispidNamedArgs = NULL;
1061 dispparams.rgvarg = NULL;
1062 VariantInit(&varresult);
1063 hr = ITypeInfo_Invoke(pTypeInfo, &NonOleAutomation, DISPID_NOA_BSTRRET, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1064 ok_ole_success(hr, ITypeInfo_Invoke);
1065 ok(V_VT(&varresult) == VT_BSTR, "V_VT(&varresult) should be VT_BSTR instead of %d\n", V_VT(&varresult));
1066 ok(V_BSTR(&varresult) != NULL, "V_BSTR(&varresult) should not be NULL\n");
1068 VariantClear(&varresult);
1069 ITypeInfo_Release(pTypeInfo);
1071 /* tests call put_Name without named arg */
1072 VariantInit(&vararg[0]);
1073 dispparams.cNamedArgs = 0;
1074 dispparams.rgdispidNamedArgs = NULL;
1075 dispparams.cArgs = 1;
1076 dispparams.rgvarg = vararg;
1077 VariantInit(&varresult);
1078 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1079 ok(hr == DISP_E_PARAMNOTFOUND, "IDispatch_Invoke should have returned DISP_E_PARAMNOTFOUND instead of 0x%08x\n", hr);
1080 VariantClear(&varresult);
1082 /* tests param type that cannot be coerced */
1083 VariantInit(&vararg[0]);
1084 V_VT(&vararg[0]) = VT_UNKNOWN;
1085 V_UNKNOWN(&vararg[0]) = NULL;
1086 dispparams.cNamedArgs = 1;
1087 dispparams.rgdispidNamedArgs = &dispidNamed;
1088 dispparams.cArgs = 1;
1089 dispparams.rgvarg = vararg;
1090 VariantInit(&varresult);
1091 #if 0 /* NULL unknown not currently marshaled correctly */
1092 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1093 ok(hr == DISP_E_TYPEMISMATCH, "IDispatch_Invoke should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hr);
1095 VariantClear(&varresult);
1097 /* tests bad param type */
1098 VariantInit(&vararg[0]);
1099 V_VT(&vararg[0]) = VT_CLSID;
1100 V_BYREF(&vararg[0]) = NULL;
1101 dispparams.cNamedArgs = 1;
1102 dispparams.rgdispidNamedArgs = &dispidNamed;
1103 dispparams.cArgs = 1;
1104 dispparams.rgvarg = vararg;
1105 VariantInit(&varresult);
1106 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1107 ok(hr == DISP_E_BADVARTYPE, "IDispatch_Invoke should have returned DISP_E_BADVARTYPE instead of 0x%08x\n", hr);
1108 VariantClear(&varresult);
1110 /* tests too small param count */
1111 dispparams.cNamedArgs = 0;
1112 dispparams.rgdispidNamedArgs = NULL;
1113 dispparams.cArgs = 0;
1114 dispparams.rgvarg = NULL;
1115 VariantInit(&varresult);
1116 hr = IDispatch_Invoke(pDispatch, DISPID_TM_DOSOMETHING, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1117 ok(hr == DISP_E_BADPARAMCOUNT, "IDispatch_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr);
1118 VariantClear(&varresult);
1120 /* tests propget function with large param count */
1121 VariantInit(&vararg[0]);
1122 V_VT(&vararg[0]) = VT_BSTR;
1123 V_BSTR(&vararg[0]) = NULL;
1124 V_VT(&vararg[1]) = VT_I4;
1125 V_I4(&vararg[1]) = 1;
1126 dispparams.cNamedArgs = 0;
1127 dispparams.cArgs = 2;
1128 dispparams.rgdispidNamedArgs = NULL;
1129 dispparams.rgvarg = vararg;
1130 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1131 ok(hr == DISP_E_NOTACOLLECTION, "IDispatch_Invoke should have returned DISP_E_NOTACOLLECTION instead of 0x%08x\n", hr);
1133 IDispatch_Release(pDispatch);
1134 IWidget_Release(pWidget);
1136 trace("calling end_host_object\n");
1137 end_host_object(tid, thread);
1140 static void test_DispCallFunc(void)
1142 static const WCHAR szEmpty[] = { 0 };
1143 VARTYPE rgvt[] = { VT_R8, VT_BSTR, VT_BSTR, VT_VARIANT|VT_BYREF };
1144 VARIANTARG vararg[4];
1146 VARIANTARG *rgpvarg[4] = { &vararg[0], &vararg[1], &vararg[2], &vararg[3] };
1147 VARIANTARG varresult;
1149 IWidget *pWidget = Widget_Create();
1150 V_VT(&vararg[0]) = VT_R8;
1151 V_R8(&vararg[0]) = 3.141;
1152 V_VT(&vararg[1]) = VT_BSTR;
1153 V_BSTR(&vararg[1]) = SysAllocString(szEmpty);
1154 V_VT(&vararg[2]) = VT_BSTR;
1155 V_BSTR(&vararg[2]) = SysAllocString(szEmpty);
1156 V_VT(&vararg[3]) = VT_VARIANT|VT_BYREF;
1157 V_VARIANTREF(&vararg[3]) = &varref;
1158 V_VT(&varref) = VT_ERROR;
1159 V_ERROR(&varref) = DISP_E_PARAMNOTFOUND;
1160 VariantInit(&varresult);
1161 hr = DispCallFunc(pWidget, 36, CC_STDCALL, VT_UI4, 4, rgvt, rgpvarg, &varresult);
1162 ok_ole_success(hr, DispCallFunc);
1163 VariantClear(&varresult);
1164 VariantClear(&vararg[1]);
1165 VariantClear(&vararg[2]);
1168 START_TEST(tmarshal)
1172 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1174 hr = register_current_module_typelib();
1175 ok_ole_success(hr, register_current_module_typelib);
1177 test_typelibmarshal();
1178 test_DispCallFunc();