oleaut32/tests: Add a test for calling a varargs method using typelib marshaller.
[wine.git] / dlls / oleaut32 / tests / tmarshal.c
blob18935343481cb47d26d4600eacf8d0bac80519bf
1 /*
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
20 #define COBJMACROS
21 #define CONST_VTABLE
23 #include <windows.h>
24 #include <ocidl.h>
25 #include <stdio.h>
27 #include "wine/test.h"
29 #include "tmarshal.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%08x\n", 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
55 IStream *stream;
56 IID iid;
57 IUnknown *object;
58 MSHLFLAGS marshal_flags;
59 HANDLE marshal_event;
60 IMessageFilter *filter;
63 static DWORD CALLBACK host_object_proc(LPVOID p)
65 struct host_object_data *data = p;
66 HRESULT hr;
67 MSG msg;
69 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
71 if (data->filter)
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 PeekMessageA(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
85 SetEvent(data->marshal_event);
87 while (GetMessageA(&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);
95 else
96 DispatchMessageA(&msg);
99 HeapFree(GetProcessHeap(), 0, data);
101 CoUninitialize();
103 return hr;
106 static DWORD start_host_object2(IStream *stream, REFIID riid, IUnknown *object, MSHLFLAGS marshal_flags, IMessageFilter *filter, HANDLE *thread)
108 DWORD tid = 0;
109 HANDLE marshal_event = CreateEventA(NULL, FALSE, FALSE, NULL);
110 struct host_object_data *data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data));
112 data->stream = stream;
113 data->iid = *riid;
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);
125 return tid;
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);
133 #if 0 /* not used */
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 = CreateEventA(NULL, FALSE, FALSE, NULL);
139 PostThreadMessageA(tid, RELEASEMARSHALDATA, 0, (LPARAM)event);
140 WaitForSingleObject(event, INFINITE);
141 CloseHandle(event);
143 #endif
145 static void end_host_object(DWORD tid, HANDLE thread)
147 BOOL ret = PostThreadMessageA(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);
151 CloseHandle(thread);
154 static int external_connections;
155 static BOOL expect_last_release_closes;
157 static HRESULT WINAPI ExternalConnection_QueryInterface(IExternalConnection *iface, REFIID riid, void **ppv)
159 ok(0, "unexpected call\n");
160 *ppv = NULL;
161 return E_NOINTERFACE;
164 static ULONG WINAPI ExternalConnection_AddRef(IExternalConnection *iface)
166 return 2;
169 static ULONG WINAPI ExternalConnection_Release(IExternalConnection *iface)
171 return 1;
174 static DWORD WINAPI ExternalConnection_AddConnection(IExternalConnection *iface, DWORD extconn, DWORD reserved)
176 trace("add connection\n");
178 ok(extconn == EXTCONN_STRONG, "extconn = %d\n", extconn);
179 ok(!reserved, "reserved = %x\n", reserved);
180 return ++external_connections;
183 static DWORD WINAPI ExternalConnection_ReleaseConnection(IExternalConnection *iface, DWORD extconn,
184 DWORD reserved, BOOL fLastReleaseCloses)
186 trace("release connection\n");
188 ok(extconn == EXTCONN_STRONG, "extconn = %d\n", extconn);
189 ok(!reserved, "reserved = %x\n", reserved);
191 ok(fLastReleaseCloses == expect_last_release_closes, "fLastReleaseCloses = %x, expected %x\n",
192 fLastReleaseCloses, expect_last_release_closes);
193 return --external_connections;
196 static const IExternalConnectionVtbl ExternalConnectionVtbl = {
197 ExternalConnection_QueryInterface,
198 ExternalConnection_AddRef,
199 ExternalConnection_Release,
200 ExternalConnection_AddConnection,
201 ExternalConnection_ReleaseConnection
204 static IExternalConnection ExternalConnection = { &ExternalConnectionVtbl };
206 static ItestDual TestDual, TestDualDisp;
208 static HRESULT WINAPI TestSecondIface_QueryInterface(ITestSecondIface *iface, REFIID riid, void **ppv)
210 return ItestDual_QueryInterface(&TestDual, riid, ppv);
213 static ULONG WINAPI TestSecondIface_AddRef(ITestSecondIface *iface)
215 return 2;
218 static ULONG WINAPI TestSecondIface_Release(ITestSecondIface *iface)
220 return 1;
223 static HRESULT WINAPI TestSecondIface_test(ITestSecondIface *iface)
225 return 1;
228 static const ITestSecondIfaceVtbl TestSecondIfaceVtbl = {
229 TestSecondIface_QueryInterface,
230 TestSecondIface_AddRef,
231 TestSecondIface_Release,
232 TestSecondIface_test
235 static ITestSecondIface TestSecondIface = { &TestSecondIfaceVtbl };
237 static HRESULT WINAPI TestSecondDisp_QueryInterface(ITestSecondDisp *iface, REFIID riid, void **ppv)
239 return ItestDual_QueryInterface(&TestDual, riid, ppv);
242 static ULONG WINAPI TestSecondDisp_AddRef(ITestSecondDisp *iface)
244 return 2;
247 static ULONG WINAPI TestSecondDisp_Release(ITestSecondDisp *iface)
249 return 1;
252 static HRESULT WINAPI TestSecondDisp_GetTypeInfoCount(ITestSecondDisp *iface, UINT *pctinfo)
254 ok(0, "unexpected call\n");
255 return E_NOTIMPL;
258 static HRESULT WINAPI TestSecondDisp_GetTypeInfo(ITestSecondDisp *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
260 ok(0, "unexpected call\n");
261 return E_NOTIMPL;
264 static HRESULT WINAPI TestSecondDisp_GetIDsOfNames(ITestSecondDisp *iface, REFIID riid, LPOLESTR *rgszNames,
265 UINT cNames, LCID lcid, DISPID *rgDispId)
267 ok(0, "unexpected call\n");
268 return E_NOTIMPL;
271 static HRESULT WINAPI TestSecondDisp_Invoke(ITestSecondDisp *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
272 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
273 UINT *puArgErr)
275 ok(0, "unexpected call\n");
276 return E_NOTIMPL;
279 static HRESULT WINAPI TestSecondDisp_test(ITestSecondDisp *iface)
281 ok(0, "unexpected call\n");
282 return E_NOTIMPL;
285 static ITestSecondDispVtbl TestSecondDispVtbl = {
286 TestSecondDisp_QueryInterface,
287 TestSecondDisp_AddRef,
288 TestSecondDisp_Release,
289 TestSecondDisp_GetTypeInfoCount,
290 TestSecondDisp_GetTypeInfo,
291 TestSecondDisp_GetIDsOfNames,
292 TestSecondDisp_Invoke,
293 TestSecondDisp_test
296 static ITestSecondDisp TestSecondDisp = { &TestSecondDispVtbl };
298 static HRESULT WINAPI TestDual_QueryInterface(ItestDual *iface, REFIID riid, void **ppvObject)
300 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch)) {
301 *ppvObject = &TestDualDisp;
302 return S_OK;
303 }else if(IsEqualGUID(riid, &IID_ItestDual)) {
304 *ppvObject = &TestDual;
305 return S_OK;
306 }else if(IsEqualGUID(riid, &IID_ITestSecondIface)) {
307 *ppvObject = &TestSecondIface;
308 return S_OK;
309 }else if(IsEqualGUID(riid, &IID_ITestSecondDisp)) {
310 *ppvObject = &TestSecondDisp;
311 return S_OK;
312 }else if (IsEqualGUID(riid, &IID_IExternalConnection)) {
313 trace("QI external connection\n");
314 *ppvObject = &ExternalConnection;
315 return S_OK;
318 *ppvObject = NULL;
319 return E_NOINTERFACE;
322 static ULONG WINAPI TestDual_AddRef(ItestDual *iface)
324 return 2;
327 static ULONG WINAPI TestDual_Release(ItestDual *iface)
329 return 1;
332 static HRESULT WINAPI TestDual_GetTypeInfoCount(ItestDual *iface, UINT *pctinfo)
334 ok(0, "unexpected call\n");
335 return E_NOTIMPL;
338 static HRESULT WINAPI TestDual_GetTypeInfo(ItestDual *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
340 ok(0, "unexpected call\n");
341 return E_NOTIMPL;
344 static HRESULT WINAPI TestDual_GetIDsOfNames(ItestDual *iface, REFIID riid, LPOLESTR *rgszNames,
345 UINT cNames, LCID lcid, DISPID *rgDispId)
347 ok(0, "unexpected call\n");
348 return E_NOTIMPL;
351 static HRESULT WINAPI TestDual_Invoke(ItestDual *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
352 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
353 UINT *puArgErr)
355 ok(0, "unexpected call\n");
356 return E_NOTIMPL;
359 static ItestDualVtbl TestDualVtbl = {
360 TestDual_QueryInterface,
361 TestDual_AddRef,
362 TestDual_Release,
363 TestDual_GetTypeInfoCount,
364 TestDual_GetTypeInfo,
365 TestDual_GetIDsOfNames,
366 TestDual_Invoke
369 static ItestDual TestDual = { &TestDualVtbl };
370 static ItestDual TestDualDisp = { &TestDualVtbl };
372 typedef struct Widget
374 IWidget IWidget_iface;
375 LONG refs;
376 IUnknown *pDispatchUnknown;
377 } Widget;
379 static inline Widget *impl_from_IWidget(IWidget *iface)
381 return CONTAINING_RECORD(iface, Widget, IWidget_iface);
384 static HRESULT WINAPI Widget_QueryInterface(
385 IWidget *iface,
386 /* [in] */ REFIID riid,
387 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
389 if (IsEqualIID(riid, &IID_IWidget) || IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch))
391 IWidget_AddRef(iface);
392 *ppvObject = iface;
393 return S_OK;
395 else
397 *ppvObject = NULL;
398 return E_NOINTERFACE;
402 static ULONG WINAPI Widget_AddRef(
403 IWidget *iface)
405 Widget *This = impl_from_IWidget(iface);
407 return InterlockedIncrement(&This->refs);
410 static ULONG WINAPI Widget_Release(
411 IWidget *iface)
413 Widget *This = impl_from_IWidget(iface);
414 ULONG refs = InterlockedDecrement(&This->refs);
415 if (!refs)
417 IUnknown_Release(This->pDispatchUnknown);
418 memset(This, 0xcc, sizeof(*This));
419 HeapFree(GetProcessHeap(), 0, This);
420 trace("Widget destroyed!\n");
423 return refs;
426 static HRESULT WINAPI Widget_GetTypeInfoCount(
427 IWidget *iface,
428 /* [out] */ UINT __RPC_FAR *pctinfo)
430 Widget *This = impl_from_IWidget(iface);
431 IDispatch *pDispatch;
432 HRESULT hr = IUnknown_QueryInterface(This->pDispatchUnknown, &IID_IDispatch, (void **)&pDispatch);
433 if (SUCCEEDED(hr))
435 hr = IDispatch_GetTypeInfoCount(pDispatch, pctinfo);
436 IDispatch_Release(pDispatch);
438 return hr;
441 static HRESULT WINAPI Widget_GetTypeInfo(
442 IWidget __RPC_FAR * iface,
443 /* [in] */ UINT iTInfo,
444 /* [in] */ LCID lcid,
445 /* [out] */ ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo)
447 Widget *This = impl_from_IWidget(iface);
448 IDispatch *pDispatch;
449 HRESULT hr = IUnknown_QueryInterface(This->pDispatchUnknown, &IID_IDispatch, (void **)&pDispatch);
450 if (SUCCEEDED(hr))
452 hr = IDispatch_GetTypeInfo(pDispatch, iTInfo, lcid, ppTInfo);
453 IDispatch_Release(pDispatch);
455 return hr;
458 static HRESULT WINAPI Widget_GetIDsOfNames(
459 IWidget __RPC_FAR * iface,
460 /* [in] */ REFIID riid,
461 /* [size_is][in] */ LPOLESTR __RPC_FAR *rgszNames,
462 /* [in] */ UINT cNames,
463 /* [in] */ LCID lcid,
464 /* [size_is][out] */ DISPID __RPC_FAR *rgDispId)
466 Widget *This = impl_from_IWidget(iface);
467 IDispatch *pDispatch;
468 HRESULT hr = IUnknown_QueryInterface(This->pDispatchUnknown, &IID_IDispatch, (void **)&pDispatch);
469 if (SUCCEEDED(hr))
471 hr = IDispatch_GetIDsOfNames(pDispatch, riid, rgszNames, cNames, lcid, rgDispId);
472 IDispatch_Release(pDispatch);
474 return hr;
477 static HRESULT WINAPI Widget_Invoke(
478 IWidget __RPC_FAR * iface,
479 /* [in] */ DISPID dispIdMember,
480 /* [in] */ REFIID riid,
481 /* [in] */ LCID lcid,
482 /* [in] */ WORD wFlags,
483 /* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams,
484 /* [out] */ VARIANT __RPC_FAR *pVarResult,
485 /* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo,
486 /* [out] */ UINT __RPC_FAR *puArgErr)
488 Widget *This = impl_from_IWidget(iface);
489 IDispatch *pDispatch;
490 HRESULT hr = IUnknown_QueryInterface(This->pDispatchUnknown, &IID_IDispatch, (void **)&pDispatch);
491 if (SUCCEEDED(hr))
493 hr = IDispatch_Invoke(pDispatch, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
494 IDispatch_Release(pDispatch);
496 return hr;
499 static HRESULT WINAPI Widget_put_Name(
500 IWidget __RPC_FAR * iface,
501 /* [in] */ BSTR name)
503 trace("put_Name(%s)\n", wine_dbgstr_w(name));
504 return S_OK;
507 static HRESULT WINAPI Widget_get_Name(
508 IWidget __RPC_FAR * iface,
509 /* [out] */ BSTR __RPC_FAR *name)
511 static const WCHAR szCat[] = { 'C','a','t',0 };
512 trace("get_Name()\n");
513 *name = SysAllocString(szCat);
514 return S_OK;
517 static HRESULT WINAPI Widget_DoSomething(
518 IWidget __RPC_FAR * iface,
519 /* [in] */ double number,
520 /* [out] */ BSTR *str1,
521 /* [defaultvalue][in] */ BSTR str2,
522 /* [optional][in] */ VARIANT __RPC_FAR *opt)
524 static const WCHAR szString[] = { 'S','t','r','i','n','g',0 };
525 trace("DoSomething()\n");
527 ok(number == 3.141, "number(%f) != 3.141\n", number);
528 ok(*str2 == '\0', "str2(%s) != \"\"\n", wine_dbgstr_w(str2));
529 ok(V_VT(opt) == VT_ERROR, "V_VT(opt) should be VT_ERROR instead of 0x%x\n", V_VT(opt));
530 ok(V_ERROR(opt) == DISP_E_PARAMNOTFOUND, "V_ERROR(opt) should be DISP_E_PARAMNOTFOUND instead of 0x%08x\n", V_ERROR(opt));
531 *str1 = SysAllocString(szString);
533 return S_FALSE;
536 static HRESULT WINAPI Widget_get_State(
537 IWidget __RPC_FAR * iface,
538 /* [retval][out] */ STATE __RPC_FAR *state)
540 trace("get_State() = STATE_WIDGETIFIED\n");
541 *state = STATE_WIDGETIFIED;
542 return S_OK;
545 static HRESULT WINAPI Widget_put_State(
546 IWidget __RPC_FAR * iface,
547 /* [in] */ STATE state)
549 trace("put_State(%d)\n", state);
550 return S_OK;
553 static HRESULT WINAPI Widget_Map(
554 IWidget * iface,
555 BSTR bstrId,
556 BSTR *sValue)
558 trace("Map(%s, %p)\n", wine_dbgstr_w(bstrId), sValue);
559 *sValue = SysAllocString(bstrId);
560 return S_OK;
563 static HRESULT WINAPI Widget_SetOleColor(
564 IWidget * iface,
565 OLE_COLOR val)
567 trace("SetOleColor(0x%x)\n", val);
568 return S_OK;
571 static HRESULT WINAPI Widget_GetOleColor(
572 IWidget * iface,
573 OLE_COLOR *pVal)
575 trace("GetOleColor() = 0x8000000f\n");
576 *pVal = 0x8000000f;
577 return S_FALSE;
580 static HRESULT WINAPI Widget_Clone(
581 IWidget *iface,
582 IWidget **ppVal)
584 trace("Clone()\n");
585 return Widget_QueryInterface(iface, &IID_IWidget, (void **)ppVal);
588 static HRESULT WINAPI Widget_CloneDispatch(
589 IWidget *iface,
590 IDispatch **ppVal)
592 trace("CloneDispatch()\n");
593 return Widget_QueryInterface(iface, &IID_IWidget, (void **)ppVal);
596 static HRESULT WINAPI Widget_CloneCoclass(
597 IWidget *iface,
598 ApplicationObject2 **ppVal)
600 trace("CloneCoclass()\n");
601 return S_OK;
604 static HRESULT WINAPI Widget_Value(
605 IWidget __RPC_FAR * iface,
606 VARIANT *value,
607 VARIANT *retval)
609 trace("Value(%p, %p)\n", value, retval);
610 ok(V_VT(value) == VT_I2, "V_VT(value) was %d instead of VT_I2\n", V_VT(value));
611 ok(V_I2(value) == 1, "V_I2(value) was %d instead of 1\n", V_I2(value));
612 V_VT(retval) = VT_I2;
613 V_I2(retval) = 1234;
614 return S_OK;
617 static HRESULT WINAPI Widget_Array(
618 IWidget * iface,
619 SAFEARRAY * values)
621 trace("Array(%p)\n", values);
622 return S_OK;
625 static HRESULT WINAPI Widget_VariantArrayPtr(
626 IWidget * iface,
627 SAFEARRAY ** values)
629 trace("VariantArrayPtr(%p)\n", values);
630 return S_OK;
633 static HRESULT WINAPI Widget_VariantCArray(
634 IWidget * iface,
635 ULONG count,
636 VARIANT values[])
638 ULONG i;
640 trace("VariantCArray(%u,%p)\n", count, values);
642 ok(count == 2, "count is %d\n", count);
643 for (i = 0; i < count; i++)
644 ok(V_VT(&values[i]) == VT_I4, "values[%d] is not VT_I4\n", i);
646 if (pVarAdd)
648 VARIANT inc, res;
649 HRESULT hr;
651 V_VT(&inc) = VT_I4;
652 V_I4(&inc) = 1;
653 for (i = 0; i < count; i++) {
654 VariantInit(&res);
655 hr = pVarAdd(&values[i], &inc, &res);
656 if (FAILED(hr)) {
657 ok(0, "VarAdd failed at %u with error 0x%x\n", i, hr);
658 return hr;
660 hr = VariantCopy(&values[i], &res);
661 if (FAILED(hr)) {
662 ok(0, "VariantCopy failed at %u with error 0x%x\n", i, hr);
663 return hr;
667 else
668 win_skip("VarAdd is not available\n");
670 return S_OK;
673 static HRESULT WINAPI Widget_Variant(
674 IWidget __RPC_FAR * iface,
675 VARIANT var)
677 trace("Variant()\n");
678 ok(V_VT(&var) == VT_CY, "V_VT(&var) was %d\n", V_VT(&var));
679 ok(S(V_CY(&var)).Hi == 0xdababe, "V_CY(&var).Hi was 0x%x\n", S(V_CY(&var)).Hi);
680 ok(S(V_CY(&var)).Lo == 0xdeadbeef, "V_CY(&var).Lo was 0x%x\n", S(V_CY(&var)).Lo);
681 return S_OK;
684 static HRESULT WINAPI Widget_VarArg(
685 IWidget * iface,
686 int numexpect,
687 SAFEARRAY * values)
689 LONG lbound, ubound, i;
690 VARIANT * data;
691 HRESULT hr;
693 trace("VarArg(%p)\n", values);
695 hr = SafeArrayGetLBound(values, 1, &lbound);
696 ok(hr == S_OK, "SafeArrayGetLBound failed with %x\n", hr);
697 ok(lbound == 0, "SafeArrayGetLBound returned %d\n", lbound);
699 hr = SafeArrayGetUBound(values, 1, &ubound);
700 ok(hr == S_OK, "SafeArrayGetUBound failed with %x\n", hr);
701 ok(ubound == numexpect-1, "SafeArrayGetUBound returned %d, but expected %d\n", ubound, numexpect-1);
703 hr = SafeArrayAccessData(values, (LPVOID)&data);
704 ok(hr == S_OK, "SafeArrayAccessData failed with %x\n", hr);
706 for (i=0; i<=ubound-lbound; i++)
708 ok(V_VT(&data[i]) == VT_I4, "V_VT(&data[%d]) was %d\n", i, V_VT(&data[i]));
709 ok(V_I4(&data[i]) == i, "V_I4(&data[%d]) was %d\n", i, V_I4(&data[i]));
712 hr = SafeArrayUnaccessData(values);
713 ok(hr == S_OK, "SafeArrayUnaccessData failed with %x\n", hr);
715 return S_OK;
719 static BOOL mystruct_uint_ordered(MYSTRUCT *mystruct)
721 int i;
722 for (i = 0; i < sizeof(mystruct->uarr)/sizeof(mystruct->uarr[0]); i++)
723 if (mystruct->uarr[i] != i)
724 return FALSE;
725 return TRUE;
728 static HRESULT WINAPI Widget_StructArgs(
729 IWidget * iface,
730 MYSTRUCT byval,
731 MYSTRUCT *byptr,
732 MYSTRUCT arr[5])
734 int i, diff = 0;
735 ok(byval.field1 == MYSTRUCT_BYVAL.field1 &&
736 byval.field2 == MYSTRUCT_BYVAL.field2 &&
737 mystruct_uint_ordered(&byval),
738 "Struct parameter passed by value corrupted\n");
739 ok(byptr->field1 == MYSTRUCT_BYPTR.field1 &&
740 byptr->field2 == MYSTRUCT_BYPTR.field2 &&
741 mystruct_uint_ordered(byptr),
742 "Struct parameter passed by pointer corrupted\n");
743 for (i = 0; i < 5; i++)
744 if (arr[i].field1 != MYSTRUCT_ARRAY[i].field1 ||
745 arr[i].field2 != MYSTRUCT_ARRAY[i].field2 ||
746 ! mystruct_uint_ordered(&arr[i]))
747 diff++;
748 ok(diff == 0, "Array of structs corrupted\n");
749 return S_OK;
753 static HRESULT WINAPI Widget_Error(
754 IWidget __RPC_FAR * iface)
756 trace("Error()\n");
757 return E_NOTIMPL;
760 static HRESULT WINAPI Widget_CloneInterface(
761 IWidget __RPC_FAR * iface,
762 ISomethingFromDispatch **ppVal)
764 trace("CloneInterface()\n");
765 *ppVal = 0;
766 return S_OK;
769 static HRESULT WINAPI Widget_put_prop_with_lcid(
770 IWidget* iface, LONG lcid, INT i)
772 trace("put_prop_with_lcid(%08x, %x)\n", lcid, i);
773 ok(lcid == MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), "got lcid %08x\n", lcid);
774 ok(i == 0xcafe, "got %08x\n", i);
775 return S_OK;
778 static HRESULT WINAPI Widget_get_prop_with_lcid(
779 IWidget* iface, LONG lcid, INT *i)
781 trace("get_prop_with_lcid(%08x, %p)\n", lcid, i);
782 ok(lcid == MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), "got lcid %08x\n", lcid);
783 *i = lcid;
784 return S_OK;
787 static HRESULT WINAPI Widget_get_prop_int(
788 IWidget* iface, INT *i)
790 trace("get_prop_int(%p)\n", i);
791 *i = -13;
792 return S_OK;
795 static HRESULT WINAPI Widget_get_prop_uint(
796 IWidget* iface, UINT *i)
798 trace("get_prop_uint(%p)\n", i);
799 *i = 42;
800 return S_OK;
803 static HRESULT WINAPI Widget_ByRefUInt(
804 IWidget* iface, UINT *i)
806 *i = 42;
807 return S_OK;
810 static HRESULT WINAPI Widget_put_prop_opt_arg(
811 IWidget* iface, INT opt, INT i)
813 trace("put_prop_opt_arg(%08x, %08x)\n", opt, i);
814 todo_wine ok(opt == 0, "got opt=%08x\n", opt);
815 ok(i == 0xcafe, "got i=%08x\n", i);
816 return S_OK;
819 static HRESULT WINAPI Widget_put_prop_req_arg(
820 IWidget* iface, INT req, INT i)
822 trace("put_prop_req_arg(%08x, %08x)\n", req, i);
823 ok(req == 0x5678, "got req=%08x\n", req);
824 ok(i == 0x1234, "got i=%08x\n", i);
825 return S_OK;
828 static HRESULT WINAPI Widget_pos_restrict(IWidget* iface, INT *i)
830 trace("restrict\n");
831 *i = DISPID_TM_RESTRICTED;
832 return S_OK;
835 static HRESULT WINAPI Widget_neg_restrict(IWidget* iface, INT *i)
837 trace("neg_restrict\n");
838 *i = DISPID_TM_NEG_RESTRICTED;
839 return S_OK;
842 static HRESULT WINAPI Widget_VarArg_Run(
843 IWidget *iface, BSTR name, SAFEARRAY *params, VARIANT *result)
845 trace("VarArg_Run(%p,%p,%p)\n", name, params, result);
846 return S_OK;
849 static const struct IWidgetVtbl Widget_VTable =
851 Widget_QueryInterface,
852 Widget_AddRef,
853 Widget_Release,
854 Widget_GetTypeInfoCount,
855 Widget_GetTypeInfo,
856 Widget_GetIDsOfNames,
857 Widget_Invoke,
858 Widget_put_Name,
859 Widget_get_Name,
860 Widget_DoSomething,
861 Widget_get_State,
862 Widget_put_State,
863 Widget_Map,
864 Widget_SetOleColor,
865 Widget_GetOleColor,
866 Widget_Clone,
867 Widget_CloneDispatch,
868 Widget_CloneCoclass,
869 Widget_Value,
870 Widget_Array,
871 Widget_VariantArrayPtr,
872 Widget_VariantCArray,
873 Widget_Variant,
874 Widget_VarArg,
875 Widget_StructArgs,
876 Widget_Error,
877 Widget_CloneInterface,
878 Widget_put_prop_with_lcid,
879 Widget_get_prop_with_lcid,
880 Widget_get_prop_int,
881 Widget_get_prop_uint,
882 Widget_ByRefUInt,
883 Widget_put_prop_opt_arg,
884 Widget_put_prop_req_arg,
885 Widget_pos_restrict,
886 Widget_neg_restrict,
887 Widget_VarArg_Run
890 static HRESULT WINAPI StaticWidget_QueryInterface(IStaticWidget *iface, REFIID riid, void **ppvObject)
892 if (IsEqualIID(riid, &IID_IStaticWidget) || IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch))
894 IStaticWidget_AddRef(iface);
895 *ppvObject = iface;
896 return S_OK;
899 *ppvObject = NULL;
900 return E_NOINTERFACE;
903 static ULONG WINAPI StaticWidget_AddRef(IStaticWidget *iface)
905 return 2;
908 static ULONG WINAPI StaticWidget_Release(IStaticWidget *iface)
910 return 1;
913 static HRESULT WINAPI StaticWidget_GetTypeInfoCount(IStaticWidget *iface, UINT *pctinfo)
915 ok(0, "unexpected call\n");
916 return E_NOTIMPL;
919 static HRESULT WINAPI StaticWidget_GetTypeInfo(IStaticWidget *iface, UINT iTInfo, LCID lcid,
920 ITypeInfo **ppTInfo)
922 ok(0, "unexpected call\n");
923 return E_NOTIMPL;
926 static HRESULT WINAPI StaticWidget_GetIDsOfNames(IStaticWidget *iface, REFIID riid, LPOLESTR *rgszNames,
927 UINT cNames, LCID lcid, DISPID *rgDispId)
929 ok(0, "unexpected call\n");
930 return E_NOTIMPL;
933 static HRESULT WINAPI StaticWidget_Invoke(IStaticWidget *iface, DISPID dispIdMember, REFIID riid,
934 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
935 UINT *puArgErr)
937 ok(0, "unexpected call\n");
938 return E_NOTIMPL;
941 static HRESULT WINAPI StaticWidget_TestDual(IStaticWidget *iface, ItestDual *p)
943 trace("TestDual()\n");
944 ok(p == &TestDual, "wrong ItestDual\n");
945 return S_OK;
948 static HRESULT WINAPI StaticWidget_TestSecondIface(IStaticWidget *iface, ITestSecondIface *p)
950 trace("TestSecondIface()\n");
951 ok(p == &TestSecondIface, "wrong ItestSecondIface\n");
952 return S_OK;
955 static const IStaticWidgetVtbl StaticWidgetVtbl = {
956 StaticWidget_QueryInterface,
957 StaticWidget_AddRef,
958 StaticWidget_Release,
959 StaticWidget_GetTypeInfoCount,
960 StaticWidget_GetTypeInfo,
961 StaticWidget_GetIDsOfNames,
962 StaticWidget_Invoke,
963 StaticWidget_TestDual,
964 StaticWidget_TestSecondIface
967 static IStaticWidget StaticWidget = { &StaticWidgetVtbl };
969 typedef struct KindaEnum
971 IKindaEnumWidget IKindaEnumWidget_iface;
972 LONG refs;
973 } KindaEnum;
975 static inline KindaEnum *impl_from_IKindaEnumWidget(IKindaEnumWidget *iface)
977 return CONTAINING_RECORD(iface, KindaEnum, IKindaEnumWidget_iface);
980 static HRESULT register_current_module_typelib(void)
982 WCHAR path[MAX_PATH];
983 CHAR pathA[MAX_PATH];
984 HRESULT hr;
985 ITypeLib *typelib;
987 GetModuleFileNameA(NULL, pathA, MAX_PATH);
988 MultiByteToWideChar(CP_ACP, 0, pathA, -1, path, MAX_PATH);
990 hr = LoadTypeLib(path, &typelib);
991 if (SUCCEEDED(hr))
993 hr = RegisterTypeLib(typelib, path, NULL);
994 ITypeLib_Release(typelib);
996 return hr;
999 static ITypeInfo *get_type_info(REFIID riid)
1001 ITypeInfo *pTypeInfo;
1002 ITypeLib *pTypeLib;
1003 HRESULT hr;
1005 hr = LoadRegTypeLib(&LIBID_TestTypelib, 2, 5, LOCALE_NEUTRAL, &pTypeLib);
1006 ok_ole_success(hr, LoadRegTypeLib);
1007 if (FAILED(hr))
1008 return NULL;
1010 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, riid, &pTypeInfo);
1011 ITypeLib_Release(pTypeLib);
1012 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
1013 if (FAILED(hr))
1014 return NULL;
1016 return pTypeInfo;
1019 static IWidget *Widget_Create(void)
1021 Widget *This;
1022 ITypeInfo *pTypeInfo;
1023 HRESULT hr = E_FAIL;
1025 pTypeInfo = get_type_info(&IID_IWidget);
1026 if(!pTypeInfo)
1027 return NULL;
1029 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1030 This->IWidget_iface.lpVtbl = &Widget_VTable;
1031 This->refs = 1;
1032 This->pDispatchUnknown = NULL;
1034 hr = CreateStdDispatch((IUnknown *)&This->IWidget_iface, This, pTypeInfo,
1035 &This->pDispatchUnknown);
1036 ok_ole_success(hr, CreateStdDispatch);
1037 ITypeInfo_Release(pTypeInfo);
1039 if (SUCCEEDED(hr))
1040 return &This->IWidget_iface;
1041 else
1043 HeapFree(GetProcessHeap(), 0, This);
1044 return NULL;
1048 static HRESULT WINAPI KindaEnum_QueryInterface(
1049 IKindaEnumWidget *iface,
1050 /* [in] */ REFIID riid,
1051 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
1053 if (IsEqualIID(riid, &IID_IKindaEnumWidget) || IsEqualIID(riid, &IID_IUnknown))
1055 IKindaEnumWidget_AddRef(iface);
1056 *ppvObject = iface;
1057 return S_OK;
1059 else
1061 *ppvObject = NULL;
1062 return E_NOINTERFACE;
1066 static ULONG WINAPI KindaEnum_AddRef(
1067 IKindaEnumWidget *iface)
1069 KindaEnum *This = impl_from_IKindaEnumWidget(iface);
1071 return InterlockedIncrement(&This->refs);
1074 static ULONG WINAPI KindaEnum_Release(
1075 IKindaEnumWidget *iface)
1077 KindaEnum *This = impl_from_IKindaEnumWidget(iface);
1078 ULONG refs = InterlockedDecrement(&This->refs);
1079 if (!refs)
1081 memset(This, 0xcc, sizeof(*This));
1082 HeapFree(GetProcessHeap(), 0, This);
1083 trace("KindaEnumWidget destroyed!\n");
1086 return refs;
1089 static HRESULT WINAPI KindaEnum_Next(
1090 IKindaEnumWidget *iface,
1091 /* [out] */ IWidget __RPC_FAR *__RPC_FAR *widget)
1093 *widget = Widget_Create();
1094 if (*widget)
1095 return S_OK;
1096 else
1097 return E_OUTOFMEMORY;
1100 static HRESULT WINAPI KindaEnum_Count(
1101 IKindaEnumWidget *iface,
1102 /* [out] */ ULONG __RPC_FAR *count)
1104 return E_NOTIMPL;
1107 static HRESULT WINAPI KindaEnum_Reset(
1108 IKindaEnumWidget *iface)
1110 return E_NOTIMPL;
1113 static HRESULT WINAPI KindaEnum_Clone(
1114 IKindaEnumWidget *iface,
1115 /* [out] */ IKindaEnumWidget __RPC_FAR *__RPC_FAR *ppenum)
1117 return E_NOTIMPL;
1120 static const IKindaEnumWidgetVtbl KindaEnumWidget_VTable =
1122 KindaEnum_QueryInterface,
1123 KindaEnum_AddRef,
1124 KindaEnum_Release,
1125 KindaEnum_Next,
1126 KindaEnum_Count,
1127 KindaEnum_Reset,
1128 KindaEnum_Clone
1131 static IKindaEnumWidget *KindaEnumWidget_Create(void)
1133 KindaEnum *This;
1135 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1136 if (!This) return NULL;
1137 This->IKindaEnumWidget_iface.lpVtbl = &KindaEnumWidget_VTable;
1138 This->refs = 1;
1139 return &This->IKindaEnumWidget_iface;
1142 static HRESULT WINAPI NonOleAutomation_QueryInterface(INonOleAutomation *iface, REFIID riid, void **ppv)
1144 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_INonOleAutomation))
1146 *(INonOleAutomation **)ppv = iface;
1147 return S_OK;
1149 *ppv = NULL;
1150 return E_NOINTERFACE;
1153 static ULONG WINAPI NonOleAutomation_AddRef(INonOleAutomation *iface)
1155 return 2;
1158 static ULONG WINAPI NonOleAutomation_Release(INonOleAutomation *iface)
1160 return 1;
1163 static BSTR WINAPI NonOleAutomation_BstrRet(INonOleAutomation *iface)
1165 static const WCHAR wszTestString[] = {'T','h','i','s',' ','i','s',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0};
1166 return SysAllocString(wszTestString);
1169 static HRESULT WINAPI NonOleAutomation_Error(INonOleAutomation *iface)
1171 return E_NOTIMPL;
1174 static INonOleAutomationVtbl NonOleAutomation_VTable =
1176 NonOleAutomation_QueryInterface,
1177 NonOleAutomation_AddRef,
1178 NonOleAutomation_Release,
1179 NonOleAutomation_BstrRet,
1180 NonOleAutomation_Error
1183 static INonOleAutomation NonOleAutomation = { &NonOleAutomation_VTable };
1185 static ITypeInfo *NonOleAutomation_GetTypeInfo(void)
1187 ITypeLib *pTypeLib;
1188 HRESULT hr = LoadRegTypeLib(&LIBID_TestTypelib, 2, 5, LOCALE_NEUTRAL, &pTypeLib);
1189 ok_ole_success(hr, LoadRegTypeLib);
1190 if (SUCCEEDED(hr))
1192 ITypeInfo *pTypeInfo;
1193 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_INonOleAutomation, &pTypeInfo);
1194 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
1195 ITypeLib_Release(pTypeLib);
1196 return pTypeInfo;
1198 return NULL;
1201 static void test_typelibmarshal(void)
1203 static const WCHAR szCat[] = { 'C','a','t',0 };
1204 static const WCHAR szTestTest[] = { 'T','e','s','t','T','e','s','t',0 };
1205 static const WCHAR szSuperman[] = { 'S','u','p','e','r','m','a','n',0 };
1206 HRESULT hr;
1207 IKindaEnumWidget *pKEW = KindaEnumWidget_Create();
1208 IWidget *pWidget;
1209 IStream *pStream;
1210 IDispatch *pDispatch;
1211 static const LARGE_INTEGER ullZero;
1212 EXCEPINFO excepinfo;
1213 VARIANT varresult;
1214 DISPID dispidNamed = DISPID_PROPERTYPUT;
1215 DISPPARAMS dispparams;
1216 VARIANTARG vararg[4];
1217 STATE the_state;
1218 HANDLE thread;
1219 DWORD tid;
1220 BSTR bstr;
1221 ITypeInfo *pTypeInfo;
1222 MYSTRUCT mystruct;
1223 MYSTRUCT mystructArray[5];
1224 UINT uval;
1226 ok(pKEW != NULL, "Widget creation failed\n");
1228 hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
1229 ok_ole_success(hr, CreateStreamOnHGlobal);
1230 tid = start_host_object(pStream, &IID_IKindaEnumWidget, (IUnknown *)pKEW, MSHLFLAGS_NORMAL, &thread);
1231 IKindaEnumWidget_Release(pKEW);
1233 IStream_Seek(pStream, ullZero, STREAM_SEEK_SET, NULL);
1234 hr = CoUnmarshalInterface(pStream, &IID_IKindaEnumWidget, (void **)&pKEW);
1235 ok_ole_success(hr, CoUnmarshalInterface);
1236 IStream_Release(pStream);
1238 hr = IKindaEnumWidget_Next(pKEW, &pWidget);
1239 ok_ole_success(hr, IKindaEnumWidget_Next);
1241 IKindaEnumWidget_Release(pKEW);
1243 /* call GetTypeInfoCount (direct) */
1244 hr = IWidget_GetTypeInfoCount(pWidget, &uval);
1245 ok_ole_success(hr, IWidget_GetTypeInfoCount);
1246 hr = IWidget_GetTypeInfoCount(pWidget, &uval);
1247 ok_ole_success(hr, IWidget_GetTypeInfoCount);
1249 hr = IWidget_QueryInterface(pWidget, &IID_IDispatch, (void **)&pDispatch);
1250 ok_ole_success(hr, IWidget_QueryInterface);
1252 /* call put_Name */
1253 VariantInit(&vararg[0]);
1254 dispparams.cNamedArgs = 1;
1255 dispparams.rgdispidNamedArgs = &dispidNamed;
1256 dispparams.cArgs = 1;
1257 dispparams.rgvarg = vararg;
1258 VariantInit(&varresult);
1259 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1260 ok_ole_success(hr, IDispatch_Invoke);
1261 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1262 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1263 excepinfo.wCode, excepinfo.scode);
1264 VariantClear(&varresult);
1266 /* call put_Name (direct) */
1267 bstr = SysAllocString(szSuperman);
1268 hr = IWidget_put_Name(pWidget, bstr);
1269 ok_ole_success(hr, IWidget_put_Name);
1270 SysFreeString(bstr);
1272 /* call get_Name */
1273 dispparams.cNamedArgs = 0;
1274 dispparams.rgdispidNamedArgs = NULL;
1275 dispparams.cArgs = 0;
1276 dispparams.rgvarg = NULL;
1277 VariantInit(&varresult);
1278 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1279 ok_ole_success(hr, IDispatch_Invoke);
1280 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1281 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1282 excepinfo.wCode, excepinfo.scode);
1283 trace("Name = %s\n", wine_dbgstr_w(V_BSTR(&varresult)));
1284 VariantClear(&varresult);
1286 /* call get_Name (direct) */
1287 bstr = (void *)0xdeadbeef;
1288 hr = IWidget_get_Name(pWidget, &bstr);
1289 ok_ole_success(hr, IWidget_get_Name);
1290 ok(!lstrcmpW(bstr, szCat), "IWidget_get_Name should have returned string \"Cat\" instead of %s\n", wine_dbgstr_w(bstr));
1291 SysFreeString(bstr);
1293 /* call DoSomething */
1294 VariantInit(&vararg[0]);
1295 VariantInit(&vararg[1]);
1296 V_VT(&vararg[1]) = VT_R8;
1297 V_R8(&vararg[1]) = 3.141;
1298 dispparams.cNamedArgs = 0;
1299 dispparams.cArgs = 2;
1300 dispparams.rgdispidNamedArgs = NULL;
1301 dispparams.rgvarg = vararg;
1302 VariantInit(&varresult);
1303 hr = IDispatch_Invoke(pDispatch, DISPID_TM_DOSOMETHING, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1304 ok_ole_success(hr, IDispatch_Invoke);
1305 ok(V_VT(&varresult) == VT_EMPTY, "varresult should be VT_EMPTY\n");
1306 VariantClear(&varresult);
1308 /* call get_State */
1309 dispparams.cNamedArgs = 0;
1310 dispparams.cArgs = 0;
1311 dispparams.rgdispidNamedArgs = NULL;
1312 dispparams.rgvarg = NULL;
1313 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1314 ok_ole_success(hr, IDispatch_Invoke);
1315 ok((V_VT(&varresult) == VT_I4) && (V_I4(&varresult) == STATE_WIDGETIFIED), "Return val mismatch\n");
1317 /* call get_State (direct) */
1318 hr = IWidget_get_State(pWidget, &the_state);
1319 ok_ole_success(hr, IWidget_get_state);
1320 ok(the_state == STATE_WIDGETIFIED, "should have returned WIDGET_WIDGETIFIED instead of %d\n", the_state);
1322 /* call put_State */
1323 the_state = STATE_WIDGETIFIED;
1324 VariantInit(&vararg[0]);
1325 V_VT(&vararg[0]) = VT_BYREF|VT_I4;
1326 V_I4REF(&vararg[0]) = (int *)&the_state;
1327 dispparams.cNamedArgs = 1;
1328 dispparams.cArgs = 1;
1329 dispparams.rgdispidNamedArgs = &dispidNamed;
1330 dispparams.rgvarg = vararg;
1331 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1332 ok_ole_success(hr, IDispatch_Invoke);
1334 /* call Map */
1335 bstr = SysAllocString(szTestTest);
1336 VariantInit(&vararg[0]);
1337 V_VT(&vararg[0]) = VT_BYREF|VT_BSTR;
1338 V_BSTRREF(&vararg[0]) = &bstr;
1339 dispparams.cNamedArgs = 0;
1340 dispparams.cArgs = 1;
1341 dispparams.rgdispidNamedArgs = NULL;
1342 dispparams.rgvarg = vararg;
1343 VariantInit(&varresult);
1344 hr = IDispatch_Invoke(pDispatch, DISPID_TM_MAP, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1345 ok_ole_success(hr, IDispatch_Invoke);
1346 ok(V_VT(&varresult) == VT_BSTR, "Return value should be of type BSTR instead of %d\n", V_VT(&varresult));
1347 ok(!lstrcmpW(V_BSTR(&varresult), szTestTest), "Return value should have been \"TestTest\" instead of %s\n", wine_dbgstr_w(V_BSTR(&varresult)));
1348 VariantClear(&varresult);
1349 SysFreeString(bstr);
1351 /* call SetOleColor with large negative VT_I4 param */
1352 VariantInit(&vararg[0]);
1353 V_VT(&vararg[0]) = VT_I4;
1354 V_I4(&vararg[0]) = 0x80000005;
1355 dispparams.cNamedArgs = 0;
1356 dispparams.cArgs = 1;
1357 dispparams.rgdispidNamedArgs = NULL;
1358 dispparams.rgvarg = vararg;
1359 hr = IDispatch_Invoke(pDispatch, DISPID_TM_SETOLECOLOR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, &excepinfo, NULL);
1360 ok_ole_success(hr, IDispatch_Invoke);
1362 /* call GetOleColor */
1363 dispparams.cNamedArgs = 0;
1364 dispparams.cArgs = 0;
1365 dispparams.rgdispidNamedArgs = NULL;
1366 dispparams.rgvarg = NULL;
1367 VariantInit(&varresult);
1368 hr = IDispatch_Invoke(pDispatch, DISPID_TM_GETOLECOLOR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1369 ok_ole_success(hr, IDispatch_Invoke);
1370 VariantClear(&varresult);
1372 /* call StructArgs (direct) */
1373 mystruct = MYSTRUCT_BYPTR;
1374 memcpy(mystructArray, MYSTRUCT_ARRAY, sizeof(mystructArray));
1375 hr = IWidget_StructArgs(pWidget, MYSTRUCT_BYVAL, &mystruct, mystructArray);
1376 ok_ole_success(hr, IWidget_StructArgs);
1378 /* call Clone */
1379 dispparams.cNamedArgs = 0;
1380 dispparams.cArgs = 0;
1381 dispparams.rgdispidNamedArgs = NULL;
1382 dispparams.rgvarg = NULL;
1383 VariantInit(&varresult);
1384 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1385 ok_ole_success(hr, IDispatch_Invoke);
1386 ok(V_VT(&varresult) == VT_DISPATCH, "vt %x\n", V_VT(&varresult));
1387 VariantClear(&varresult);
1389 /* call CloneInterface */
1390 dispparams.cNamedArgs = 0;
1391 dispparams.cArgs = 0;
1392 dispparams.rgdispidNamedArgs = NULL;
1393 dispparams.rgvarg = NULL;
1394 VariantInit(&varresult);
1395 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONEINTERFACE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1396 ok_ole_success(hr, IDispatch_Invoke);
1397 ok(V_VT(&varresult) == VT_DISPATCH, "vt %x\n", V_VT(&varresult));
1398 VariantClear(&varresult);
1400 /* call CloneDispatch with automatic value getting */
1401 V_VT(&vararg[0]) = VT_I2;
1402 V_I2(&vararg[0]) = 1;
1403 dispparams.cNamedArgs = 0;
1404 dispparams.rgdispidNamedArgs = NULL;
1405 dispparams.cArgs = 1;
1406 dispparams.rgvarg = vararg;
1407 VariantInit(&varresult);
1408 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONEDISPATCH, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1409 ok_ole_success(hr, IDispatch_Invoke);
1411 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1412 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1413 excepinfo.wCode, excepinfo.scode);
1415 ok(V_VT(&varresult) == VT_I2, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult));
1416 ok(V_I2(&varresult) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult));
1417 VariantClear(&varresult);
1419 /* call CloneCoclass */
1420 dispparams.cNamedArgs = 0;
1421 dispparams.cArgs = 0;
1422 dispparams.rgdispidNamedArgs = NULL;
1423 dispparams.rgvarg = NULL;
1424 VariantInit(&varresult);
1425 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONECOCLASS, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1426 ok_ole_success(hr, IDispatch_Invoke);
1428 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1429 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1430 excepinfo.wCode, excepinfo.scode);
1432 ok(V_VT(&varresult) == VT_DISPATCH, "V_VT(&varresult) was %d instead of VT_DISPATCH\n", V_VT(&varresult));
1433 ok(!V_DISPATCH(&varresult), "V_DISPATCH(&varresult) should be NULL instead of %p\n", V_DISPATCH(&varresult));
1434 VariantClear(&varresult);
1436 /* call Value with a VT_VARIANT|VT_BYREF type */
1437 V_VT(&vararg[0]) = VT_VARIANT|VT_BYREF;
1438 V_VARIANTREF(&vararg[0]) = &vararg[1];
1439 V_VT(&vararg[1]) = VT_I2;
1440 V_I2(&vararg[1]) = 1;
1441 dispparams.cNamedArgs = 0;
1442 dispparams.rgdispidNamedArgs = NULL;
1443 dispparams.cArgs = 1;
1444 dispparams.rgvarg = vararg;
1445 VariantInit(&varresult);
1446 hr = IDispatch_Invoke(pDispatch, DISPID_VALUE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1447 ok_ole_success(hr, IDispatch_Invoke);
1449 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1450 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1451 excepinfo.wCode, excepinfo.scode);
1453 ok(V_VT(&varresult) == VT_I2, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult));
1454 ok(V_I2(&varresult) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult));
1455 VariantClear(&varresult);
1457 /* call Variant - exercises variant copying in ITypeInfo::Invoke and
1458 * handling of void return types */
1459 /* use a big type to ensure that the variant was properly copied into the
1460 * destination function's args */
1461 V_VT(&vararg[0]) = VT_CY;
1462 S(V_CY(&vararg[0])).Hi = 0xdababe;
1463 S(V_CY(&vararg[0])).Lo = 0xdeadbeef;
1464 dispparams.cNamedArgs = 0;
1465 dispparams.cArgs = 1;
1466 dispparams.rgdispidNamedArgs = NULL;
1467 dispparams.rgvarg = vararg;
1468 VariantInit(&varresult);
1469 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARIANT, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1470 ok_ole_success(hr, IDispatch_Invoke);
1471 VariantClear(&varresult);
1473 /* call VariantCArray - test marshaling of variant arrays */
1474 V_VT(&vararg[0]) = VT_I4;
1475 V_I4(&vararg[0]) = 1;
1476 V_VT(&vararg[1]) = VT_I4;
1477 V_I4(&vararg[1]) = 2;
1478 hr = IWidget_VariantCArray(pWidget, 2, vararg);
1479 ok_ole_success(hr, IWidget_VariantCArray);
1480 todo_wine
1481 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]));
1482 todo_wine
1483 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]));
1485 /* call VarArg */
1486 VariantInit(&vararg[3]);
1487 V_VT(&vararg[3]) = VT_I4;
1488 V_I4(&vararg[3]) = 3;
1489 VariantInit(&vararg[2]);
1490 V_VT(&vararg[2]) = VT_I4;
1491 V_I4(&vararg[2]) = 0;
1492 VariantInit(&vararg[1]);
1493 V_VT(&vararg[1]) = VT_I4;
1494 V_I4(&vararg[1]) = 1;
1495 VariantInit(&vararg[0]);
1496 V_VT(&vararg[0]) = VT_I4;
1497 V_I4(&vararg[0]) = 2;
1498 dispparams.cNamedArgs = 0;
1499 dispparams.cArgs = 4;
1500 dispparams.rgdispidNamedArgs = NULL;
1501 dispparams.rgvarg = vararg;
1502 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARARG, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1503 ok_ole_success(hr, IDispatch_Invoke);
1505 /* call VarArg, even one (non-optional, non-safearray) named argument is not allowed */
1506 dispidNamed = 0;
1507 dispparams.cNamedArgs = 1;
1508 dispparams.rgdispidNamedArgs = &dispidNamed;
1509 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARARG, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1510 ok(hr == DISP_E_NONAMEDARGS, "IDispatch_Invoke should have returned DISP_E_NONAMEDARGS instead of 0x%08x\n", hr);
1511 dispidNamed = DISPID_PROPERTYPUT;
1513 /* call VarArg_Run */
1514 VariantInit(&vararg[1]);
1515 V_VT(&vararg[1]) = VT_BSTR;
1516 V_BSTR(&vararg[1]) = SysAllocString(szCat);
1517 VariantInit(&vararg[0]);
1518 V_VT(&vararg[0]) = VT_BSTR;
1519 V_BSTR(&vararg[0]) = SysAllocString(NULL);
1520 dispparams.cNamedArgs = 0;
1521 dispparams.cArgs = 2;
1522 dispparams.rgdispidNamedArgs = NULL;
1523 dispparams.rgvarg = vararg;
1524 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARARG_RUN, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1525 todo_wine
1526 ok_ole_success(hr, IDispatch_Invoke);
1527 SysFreeString(V_BSTR(&vararg[1]));
1528 SysFreeString(V_BSTR(&vararg[0]));
1530 /* call Error */
1531 dispparams.cNamedArgs = 0;
1532 dispparams.cArgs = 0;
1533 dispparams.rgdispidNamedArgs = NULL;
1534 dispparams.rgvarg = NULL;
1535 VariantInit(&varresult);
1536 hr = IDispatch_Invoke(pDispatch, DISPID_TM_ERROR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, &excepinfo, NULL);
1537 ok(hr == DISP_E_EXCEPTION, "IDispatch_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr);
1538 ok(excepinfo.wCode == 0x0 && excepinfo.scode == E_NOTIMPL,
1539 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1540 excepinfo.wCode, excepinfo.scode);
1541 VariantClear(&varresult);
1543 /* call BstrRet */
1544 pTypeInfo = NonOleAutomation_GetTypeInfo();
1545 dispparams.cNamedArgs = 0;
1546 dispparams.cArgs = 0;
1547 dispparams.rgdispidNamedArgs = NULL;
1548 dispparams.rgvarg = NULL;
1549 VariantInit(&varresult);
1550 hr = ITypeInfo_Invoke(pTypeInfo, &NonOleAutomation, DISPID_NOA_BSTRRET, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1551 ok_ole_success(hr, ITypeInfo_Invoke);
1552 ok(V_VT(&varresult) == VT_BSTR, "V_VT(&varresult) should be VT_BSTR instead of %d\n", V_VT(&varresult));
1553 ok(V_BSTR(&varresult) != NULL, "V_BSTR(&varresult) should not be NULL\n");
1555 VariantClear(&varresult);
1557 dispparams.cNamedArgs = 0;
1558 dispparams.cArgs = 0;
1559 dispparams.rgdispidNamedArgs = NULL;
1560 dispparams.rgvarg = NULL;
1561 hr = ITypeInfo_Invoke(pTypeInfo, &NonOleAutomation, DISPID_NOA_ERROR, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1562 ok(hr == DISP_E_EXCEPTION, "ITypeInfo_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr);
1563 ok(V_VT(&varresult) == VT_EMPTY, "V_VT(&varresult) should be VT_EMPTY instead of %d\n", V_VT(&varresult));
1564 ok(excepinfo.wCode == 0x0 && excepinfo.scode == E_NOTIMPL,
1565 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1566 excepinfo.wCode, excepinfo.scode);
1567 VariantClear(&varresult);
1569 ITypeInfo_Release(pTypeInfo);
1571 /* tests call put_Name without named arg */
1572 VariantInit(&vararg[0]);
1573 dispparams.cNamedArgs = 0;
1574 dispparams.rgdispidNamedArgs = NULL;
1575 dispparams.cArgs = 1;
1576 dispparams.rgvarg = vararg;
1577 VariantInit(&varresult);
1578 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1579 ok(hr == DISP_E_PARAMNOTFOUND, "IDispatch_Invoke should have returned DISP_E_PARAMNOTFOUND instead of 0x%08x\n", hr);
1580 VariantClear(&varresult);
1582 /* tests param type that cannot be coerced */
1583 VariantInit(&vararg[0]);
1584 V_VT(&vararg[0]) = VT_UNKNOWN;
1585 V_UNKNOWN(&vararg[0]) = NULL;
1586 dispparams.cNamedArgs = 1;
1587 dispparams.rgdispidNamedArgs = &dispidNamed;
1588 dispparams.cArgs = 1;
1589 dispparams.rgvarg = vararg;
1590 VariantInit(&varresult);
1591 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1592 ok(hr == DISP_E_TYPEMISMATCH, "IDispatch_Invoke should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hr);
1593 VariantClear(&varresult);
1595 /* tests bad param type */
1596 VariantInit(&vararg[0]);
1597 V_VT(&vararg[0]) = VT_CLSID;
1598 V_BYREF(&vararg[0]) = NULL;
1599 dispparams.cNamedArgs = 1;
1600 dispparams.rgdispidNamedArgs = &dispidNamed;
1601 dispparams.cArgs = 1;
1602 dispparams.rgvarg = vararg;
1603 VariantInit(&varresult);
1604 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1605 ok(hr == DISP_E_BADVARTYPE, "IDispatch_Invoke should have returned DISP_E_BADVARTYPE instead of 0x%08x\n", hr);
1606 VariantClear(&varresult);
1608 /* tests too small param count */
1609 dispparams.cNamedArgs = 0;
1610 dispparams.rgdispidNamedArgs = NULL;
1611 dispparams.cArgs = 0;
1612 dispparams.rgvarg = NULL;
1613 VariantInit(&varresult);
1614 hr = IDispatch_Invoke(pDispatch, DISPID_TM_DOSOMETHING, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1615 ok(hr == DISP_E_BADPARAMCOUNT, "IDispatch_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr);
1616 VariantClear(&varresult);
1618 /* tests propget function with large param count */
1619 VariantInit(&vararg[0]);
1620 V_VT(&vararg[0]) = VT_BSTR;
1621 V_BSTR(&vararg[0]) = NULL;
1622 V_VT(&vararg[1]) = VT_I4;
1623 V_I4(&vararg[1]) = 1;
1624 dispparams.cNamedArgs = 0;
1625 dispparams.cArgs = 2;
1626 dispparams.rgdispidNamedArgs = NULL;
1627 dispparams.rgvarg = vararg;
1628 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1629 ok(hr == DISP_E_NOTACOLLECTION, "IDispatch_Invoke should have returned DISP_E_NOTACOLLECTION instead of 0x%08x\n", hr);
1631 /* test propput with lcid */
1633 /* the lcid passed to the function is the first lcid in the typelib header.
1634 Since we don't explicitly set an lcid in the idl, it'll default to US English. */
1635 VariantInit(&vararg[0]);
1636 V_VT(&vararg[0]) = VT_I4;
1637 V_I4(&vararg[0]) = 0xcafe;
1638 dispparams.cNamedArgs = 1;
1639 dispparams.rgdispidNamedArgs = &dispidNamed;
1640 dispparams.cArgs = 1;
1641 dispparams.rgvarg = vararg;
1642 VariantInit(&varresult);
1643 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_WITH_LCID, &IID_NULL, 0x40c, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1644 ok_ole_success(hr, ITypeInfo_Invoke);
1645 VariantClear(&varresult);
1647 /* test propget with lcid */
1648 dispparams.cNamedArgs = 0;
1649 dispparams.cArgs = 0;
1650 dispparams.rgvarg = NULL;
1651 dispparams.rgdispidNamedArgs = NULL;
1652 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_WITH_LCID, &IID_NULL, 0x40c, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1653 ok_ole_success(hr, ITypeInfo_Invoke);
1654 ok(V_VT(&varresult) == VT_I4, "got %x\n", V_VT(&varresult));
1655 ok(V_I4(&varresult) == 0x409, "got %x\n", V_I4(&varresult));
1656 VariantClear(&varresult);
1658 /* test propget of INT value */
1659 dispparams.cNamedArgs = 0;
1660 dispparams.cArgs = 0;
1661 dispparams.rgvarg = NULL;
1662 dispparams.rgdispidNamedArgs = NULL;
1663 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_INT, &IID_NULL, 0x40c, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1664 ok_ole_success(hr, ITypeInfo_Invoke);
1665 ok(V_VT(&varresult) == VT_I4, "got %x\n", V_VT(&varresult));
1666 ok(V_I4(&varresult) == -13, "got %x\n", V_I4(&varresult));
1667 VariantClear(&varresult);
1669 /* test propget of INT value */
1670 dispparams.cNamedArgs = 0;
1671 dispparams.cArgs = 0;
1672 dispparams.rgvarg = NULL;
1673 dispparams.rgdispidNamedArgs = NULL;
1674 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_UINT, &IID_NULL, 0x40c, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1675 ok_ole_success(hr, ITypeInfo_Invoke);
1676 ok(V_VT(&varresult) == VT_UI4, "got %x\n", V_VT(&varresult));
1677 ok(V_UI4(&varresult) == 42, "got %x\n", V_UI4(&varresult));
1678 VariantClear(&varresult);
1680 /* test byref marshalling */
1681 uval = 666;
1682 VariantInit(&vararg[0]);
1683 V_VT(&vararg[0]) = VT_UI4|VT_BYREF;
1684 V_UI4REF(&vararg[0]) = &uval;
1685 dispparams.cNamedArgs = 0;
1686 dispparams.cArgs = 1;
1687 dispparams.rgvarg = vararg;
1688 dispparams.rgdispidNamedArgs = NULL;
1689 hr = IDispatch_Invoke(pDispatch, DISPID_TM_BYREF_UINT, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1690 ok_ole_success(hr, ITypeInfo_Invoke);
1691 ok(V_VT(&varresult) == VT_EMPTY, "varresult should be VT_EMPTY\n");
1692 ok(V_VT(&vararg[0]) == (VT_UI4|VT_BYREF), "arg VT not unmarshalled correctly: %x\n", V_VT(&vararg[0]));
1693 ok(V_UI4REF(&vararg[0]) == &uval, "Byref pointer not preserved: %p/%p\n", &uval, V_UI4REF(&vararg[0]));
1694 ok(*V_UI4REF(&vararg[0]) == 42, "Expected 42 to be returned instead of %u\n", *V_UI4REF(&vararg[0]));
1695 VariantClear(&varresult);
1696 VariantClear(&vararg[0]);
1698 /* test propput with optional argument. */
1699 VariantInit(&vararg[0]);
1700 V_VT(&vararg[0]) = VT_I4;
1701 V_I4(&vararg[0]) = 0xcafe;
1702 dispparams.cNamedArgs = 1;
1703 dispparams.rgdispidNamedArgs = &dispidNamed;
1704 dispparams.cArgs = 1;
1705 dispparams.rgvarg = vararg;
1706 VariantInit(&varresult);
1707 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_OPT_ARG, &IID_NULL, 0x40c, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1708 ok_ole_success(hr, ITypeInfo_Invoke);
1709 VariantClear(&varresult);
1711 /* test propput with required argument. */
1712 VariantInit(&vararg[0]);
1713 VariantInit(&vararg[1]);
1714 V_VT(&vararg[0]) = VT_I4;
1715 V_I4(&vararg[0]) = 0x1234;
1716 V_VT(&vararg[1]) = VT_I4;
1717 V_I4(&vararg[1]) = 0x5678;
1718 dispparams.cNamedArgs = 1;
1719 dispparams.rgdispidNamedArgs = &dispidNamed;
1720 dispparams.cArgs = 2;
1721 dispparams.rgvarg = vararg;
1722 VariantInit(&varresult);
1723 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_REQ_ARG, &IID_NULL, 0x40c, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1724 ok_ole_success(hr, ITypeInfo_Invoke);
1725 VariantClear(&varresult);
1727 /* restricted member */
1728 dispparams.cNamedArgs = 0;
1729 dispparams.rgdispidNamedArgs = NULL;
1730 dispparams.cArgs = 0;
1731 dispparams.rgvarg = NULL;
1732 VariantInit(&varresult);
1733 hr = IDispatch_Invoke(pDispatch, DISPID_TM_RESTRICTED, &IID_NULL, 0x40c, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1734 ok( hr == DISP_E_MEMBERNOTFOUND, "got %08x\n", hr );
1735 VariantClear(&varresult);
1737 /* restricted member with -ve memid (not restricted) */
1738 dispparams.cNamedArgs = 0;
1739 dispparams.rgdispidNamedArgs = NULL;
1740 dispparams.cArgs = 0;
1741 dispparams.rgvarg = NULL;
1742 VariantInit(&varresult);
1743 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NEG_RESTRICTED, &IID_NULL, 0x40c, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1744 ok( hr == S_OK, "got %08x\n", hr );
1745 ok(V_VT(&varresult) == VT_I4, "got %x\n", V_VT(&varresult));
1746 ok(V_I4(&varresult) == DISPID_TM_NEG_RESTRICTED, "got %x\n", V_I4(&varresult));
1747 VariantClear(&varresult);
1749 IDispatch_Release(pDispatch);
1750 IWidget_Release(pWidget);
1752 trace("calling end_host_object\n");
1753 end_host_object(tid, thread);
1756 static void test_DispCallFunc(void)
1758 static const WCHAR szEmpty[] = { 0 };
1759 VARTYPE rgvt[] = { VT_R8, VT_BSTR, VT_BSTR, VT_VARIANT|VT_BYREF };
1760 VARIANTARG vararg[4];
1761 VARIANTARG varref;
1762 VARIANTARG *rgpvarg[4] = { &vararg[0], &vararg[1], &vararg[2], &vararg[3] };
1763 VARIANTARG varresult;
1764 HRESULT hr;
1765 IWidget *pWidget = Widget_Create();
1766 V_VT(&vararg[0]) = VT_R8;
1767 V_R8(&vararg[0]) = 3.141;
1768 V_VT(&vararg[1]) = VT_BSTR;
1769 V_BSTRREF(&vararg[1]) = CoTaskMemAlloc(sizeof(BSTR));
1770 V_VT(&vararg[2]) = VT_BSTR;
1771 V_BSTR(&vararg[2]) = SysAllocString(szEmpty);
1772 V_VT(&vararg[3]) = VT_VARIANT|VT_BYREF;
1773 V_VARIANTREF(&vararg[3]) = &varref;
1774 V_VT(&varref) = VT_ERROR;
1775 V_ERROR(&varref) = DISP_E_PARAMNOTFOUND;
1776 VariantInit(&varresult);
1777 hr = DispCallFunc(pWidget, 9*sizeof(void*), CC_STDCALL, VT_UI4, 4, rgvt, rgpvarg, &varresult);
1778 ok_ole_success(hr, DispCallFunc);
1779 VariantClear(&varresult);
1780 SysFreeString(*V_BSTRREF(&vararg[1]));
1781 CoTaskMemFree(V_BSTRREF(&vararg[1]));
1782 VariantClear(&vararg[2]);
1783 IWidget_Release(pWidget);
1786 static void test_StaticWidget(void)
1788 ITypeInfo *type_info;
1789 DISPPARAMS dispparams;
1790 VARIANTARG vararg[4];
1791 EXCEPINFO excepinfo;
1792 VARIANT varresult;
1793 HRESULT hr;
1795 type_info = get_type_info(&IID_IStaticWidget);
1797 /* call TestDual */
1798 dispparams.cNamedArgs = 0;
1799 dispparams.cArgs = 1;
1800 dispparams.rgdispidNamedArgs = NULL;
1801 dispparams.rgvarg = vararg;
1802 V_VT(vararg) = VT_DISPATCH;
1803 V_DISPATCH(vararg) = (IDispatch*)&TestDualDisp;
1804 VariantInit(&varresult);
1805 hr = ITypeInfo_Invoke(type_info, &StaticWidget, DISPID_TM_TESTDUAL, DISPATCH_METHOD,
1806 &dispparams, &varresult, &excepinfo, NULL);
1807 ok_ole_success(hr, IDispatch_Invoke);
1808 ok(V_VT(&varresult) == VT_EMPTY, "vt %x\n", V_VT(&varresult));
1809 VariantClear(&varresult);
1811 /* call TestSecondIface */
1812 dispparams.cNamedArgs = 0;
1813 dispparams.cArgs = 1;
1814 dispparams.rgdispidNamedArgs = NULL;
1815 dispparams.rgvarg = vararg;
1816 V_VT(vararg) = VT_DISPATCH;
1817 V_DISPATCH(vararg) = (IDispatch*)&TestDualDisp;
1818 VariantInit(&varresult);
1819 hr = ITypeInfo_Invoke(type_info, &StaticWidget, DISPID_TM_TESTSECONDIFACE, DISPATCH_METHOD,
1820 &dispparams, &varresult, &excepinfo, NULL);
1821 ok_ole_success(hr, IDispatch_Invoke);
1822 ok(V_VT(&varresult) == VT_EMPTY, "vt %x\n", V_VT(&varresult));
1823 VariantClear(&varresult);
1825 ITypeInfo_Release(type_info);
1828 static void test_libattr(void)
1830 ITypeLib *pTypeLib;
1831 HRESULT hr;
1832 TLIBATTR *pattr;
1834 hr = LoadRegTypeLib(&LIBID_TestTypelib, 2, 5, LOCALE_NEUTRAL, &pTypeLib);
1835 ok_ole_success(hr, LoadRegTypeLib);
1836 if (FAILED(hr))
1837 return;
1839 hr = ITypeLib_GetLibAttr(pTypeLib, &pattr);
1840 ok_ole_success(hr, GetLibAttr);
1841 if (SUCCEEDED(hr))
1843 ok(pattr->lcid == MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), "lcid %x\n", pattr->lcid);
1845 ITypeLib_ReleaseTLibAttr(pTypeLib, pattr);
1848 ITypeLib_Release(pTypeLib);
1851 static void test_external_connection(void)
1853 IStream *stream, *stream2;
1854 ITestSecondDisp *second;
1855 ItestDual *iface;
1856 HANDLE thread;
1857 DWORD tid;
1858 HRESULT hres;
1860 static const LARGE_INTEGER zero;
1862 trace("Testing IExternalConnection...\n");
1864 external_connections = 0;
1866 /* Marshaling an interface increases external connection count. */
1867 expect_last_release_closes = FALSE;
1868 hres = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1869 ok(hres == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hres);
1870 tid = start_host_object(stream, &IID_ItestDual, (IUnknown*)&TestDual, MSHLFLAGS_NORMAL, &thread);
1871 ok(external_connections == 1, "external_connections = %d\n", external_connections);
1873 IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
1874 hres = CoUnmarshalInterface(stream, &IID_ItestDual, (void**)&iface);
1875 ok(hres == S_OK, "CoUnmarshalInterface failed: %08x\n", hres);
1876 ok(external_connections == 1, "external_connections = %d\n", external_connections);
1878 IStream_Release(stream);
1879 ok(external_connections == 1, "external_connections = %d\n", external_connections);
1881 /* Creating a stub for new iface causes new external connection. */
1882 hres = ItestDual_QueryInterface(iface, &IID_ITestSecondDisp, (void**)&second);
1883 ok(hres == S_OK, "Could not get ITestSecondDisp iface: %08x\n", hres);
1884 todo_wine
1885 ok(external_connections == 2, "external_connections = %d\n", external_connections);
1887 ITestSecondDisp_Release(second);
1888 todo_wine
1889 ok(external_connections == 2, "external_connections = %d\n", external_connections);
1891 expect_last_release_closes = TRUE;
1892 ItestDual_Release(iface);
1893 ok(external_connections == 0, "external_connections = %d\n", external_connections);
1895 end_host_object(tid, thread);
1897 /* A test with direct CoMarshalInterface call. */
1898 hres = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1899 ok(hres == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hres);
1901 expect_last_release_closes = FALSE;
1902 hres = CoMarshalInterface(stream, &IID_ItestDual, (IUnknown*)&TestDual, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
1903 ok(hres == S_OK, "CoMarshalInterface failed: %08x\n", hres);
1904 ok(external_connections == 1, "external_connections = %d\n", external_connections);
1906 expect_last_release_closes = TRUE;
1907 IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
1908 hres = CoReleaseMarshalData(stream);
1909 ok(hres == S_OK, "CoReleaseMarshalData failed: %08x\n", hres);
1910 ok(external_connections == 0, "external_connections = %d\n", external_connections);
1912 /* Two separated marshal data are still one external connection. */
1913 hres = CreateStreamOnHGlobal(NULL, TRUE, &stream2);
1914 ok(hres == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hres);
1916 expect_last_release_closes = FALSE;
1917 IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
1918 hres = CoMarshalInterface(stream, &IID_ItestDual, (IUnknown*)&TestDual, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
1919 ok(hres == S_OK, "CoMarshalInterface failed: %08x\n", hres);
1920 ok(external_connections == 1, "external_connections = %d\n", external_connections);
1922 hres = CoMarshalInterface(stream2, &IID_ItestDual, (IUnknown*)&TestDual, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
1923 ok(hres == S_OK, "CoMarshalInterface failed: %08x\n", hres);
1924 ok(external_connections == 1, "external_connections = %d\n", external_connections);
1926 IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
1927 hres = CoReleaseMarshalData(stream);
1928 ok(hres == S_OK, "CoReleaseMarshalData failed: %08x\n", hres);
1929 ok(external_connections == 1, "external_connections = %d\n", external_connections);
1931 expect_last_release_closes = TRUE;
1932 IStream_Seek(stream2, zero, STREAM_SEEK_SET, NULL);
1933 hres = CoReleaseMarshalData(stream2);
1934 ok(hres == S_OK, "CoReleaseMarshalData failed: %08x\n", hres);
1935 ok(external_connections == 0, "external_connections = %d\n", external_connections);
1937 /* Weak table marshaling does not increment external connections */
1938 hres = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1939 ok(hres == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hres);
1941 hres = CoMarshalInterface(stream, &IID_ItestDual, (IUnknown*)&TestDual, MSHCTX_INPROC, NULL, MSHLFLAGS_TABLEWEAK);
1942 ok(hres == S_OK, "CoMarshalInterface failed: %08x\n", hres);
1943 ok(external_connections == 0, "external_connections = %d\n", external_connections);
1945 IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
1946 hres = CoUnmarshalInterface(stream, &IID_ItestDual, (void**)&iface);
1947 ok(hres == S_OK, "CoUnmarshalInterface failed: %08x\n", hres);
1948 ok(external_connections == 0, "external_connections = %d\n", external_connections);
1949 ItestDual_Release(iface);
1951 IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
1952 hres = CoReleaseMarshalData(stream);
1953 ok(hres == S_OK, "CoReleaseMarshalData failed: %08x\n", hres);
1954 ok(external_connections == 0, "external_connections = %d\n", external_connections);
1957 START_TEST(tmarshal)
1959 HRESULT hr;
1960 HANDLE hOleaut32 = GetModuleHandleA("oleaut32.dll");
1961 pVarAdd = (void*)GetProcAddress(hOleaut32, "VarAdd");
1963 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1965 hr = register_current_module_typelib();
1966 if (FAILED(hr))
1968 CoUninitialize();
1969 win_skip("Registration of the test typelib failed, skipping tests\n");
1970 return;
1973 test_typelibmarshal();
1974 test_DispCallFunc();
1975 test_StaticWidget();
1976 test_libattr();
1977 test_external_connection();
1979 hr = UnRegisterTypeLib(&LIBID_TestTypelib, 2, 5, LOCALE_NEUTRAL,
1980 sizeof(void*) == 8 ? SYS_WIN64 : SYS_WIN32);
1981 ok_ole_success(hr, UnRegisterTypeLib);
1983 CoUninitialize();