Release 1.6-rc2.
[wine/testsucceed.git] / dlls / oleaut32 / tests / tmarshal.c
blob3572bbb32141a01e88174d680e06e15a7d5382b0
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%08lx\n", (unsigned long int)hr)
37 /* ULL suffix is not portable */
38 #define ULL_CONST(dw1, dw2) ((((ULONGLONG)dw1) << 32) | (ULONGLONG)dw2)
40 const MYSTRUCT MYSTRUCT_BYVAL = {0x12345678, ULL_CONST(0xdeadbeef, 0x98765432), {0,1,2,3,4,5,6,7}};
41 const MYSTRUCT MYSTRUCT_BYPTR = {0x91827364, ULL_CONST(0x88776655, 0x44332211), {0,1,2,3,4,5,6,7}};
42 const MYSTRUCT MYSTRUCT_ARRAY[5] = {
43 {0x1a1b1c1d, ULL_CONST(0x1e1f1011, 0x12131415), {0,1,2,3,4,5,6,7}},
44 {0x2a2b2c2d, ULL_CONST(0x2e2f2021, 0x22232425), {0,1,2,3,4,5,6,7}},
45 {0x3a3b3c3d, ULL_CONST(0x3e3f3031, 0x32333435), {0,1,2,3,4,5,6,7}},
46 {0x4a4b4c4d, ULL_CONST(0x4e4f4041, 0x42434445), {0,1,2,3,4,5,6,7}},
47 {0x5a5b5c5d, ULL_CONST(0x5e5f5051, 0x52535455), {0,1,2,3,4,5,6,7}},
51 #define RELEASEMARSHALDATA WM_USER
53 struct host_object_data
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 PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
85 SetEvent(data->marshal_event);
87 while (GetMessage(&msg, NULL, 0, 0))
89 if (msg.hwnd == NULL && msg.message == RELEASEMARSHALDATA)
91 trace("releasing marshal data\n");
92 CoReleaseMarshalData(data->stream);
93 SetEvent((HANDLE)msg.lParam);
95 else
96 DispatchMessage(&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 = CreateEvent(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 = CreateEvent(NULL, FALSE, FALSE, NULL);
139 PostThreadMessage(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 = PostThreadMessage(tid, WM_QUIT, 0, 0);
148 ok(ret, "PostThreadMessage failed with error %d\n", GetLastError());
149 /* be careful of races - don't return until hosting thread has terminated */
150 WaitForSingleObject(thread, INFINITE);
151 CloseHandle(thread);
154 static int external_connections;
156 static HRESULT WINAPI ExternalConnection_QueryInterface(IExternalConnection *iface, REFIID riid, void **ppv)
158 ok(0, "unxpected call\n");
159 *ppv = NULL;
160 return E_NOINTERFACE;
163 static ULONG WINAPI ExternalConnection_AddRef(IExternalConnection *iface)
165 return 2;
168 static ULONG WINAPI ExternalConnection_Release(IExternalConnection *iface)
170 return 1;
173 static DWORD WINAPI ExternalConnection_AddConnection(IExternalConnection *iface, DWORD extconn, DWORD reserved)
175 trace("add connection\n");
177 ok(extconn == EXTCONN_STRONG, "extconn = %d\n", extconn);
178 ok(!reserved, "reserved = %x\n", reserved);
179 return ++external_connections;
182 static DWORD WINAPI ExternalConnection_ReleaseConnection(IExternalConnection *iface, DWORD extconn,
183 DWORD reserved, BOOL fLastReleaseCloses)
185 trace("release connection\n");
187 ok(extconn == EXTCONN_STRONG, "extconn = %d\n", extconn);
188 ok(!reserved, "reserved = %x\n", reserved);
190 /* This may need to be adjusted if we'll add more complex tests. */
191 if(--external_connections)
192 ok(!fLastReleaseCloses, "fLastReleaseCloses = %x\n", fLastReleaseCloses);
193 else
194 ok(fLastReleaseCloses, "fLastReleaseCloses = %x\n", fLastReleaseCloses);
195 return external_connections;
198 static const IExternalConnectionVtbl ExternalConnectionVtbl = {
199 ExternalConnection_QueryInterface,
200 ExternalConnection_AddRef,
201 ExternalConnection_Release,
202 ExternalConnection_AddConnection,
203 ExternalConnection_ReleaseConnection
206 static IExternalConnection ExternalConnection = { &ExternalConnectionVtbl };
208 static ItestDual TestDual, TestDualDisp;
210 static HRESULT WINAPI TestSecondIface_QueryInterface(ITestSecondIface *iface, REFIID riid, void **ppv)
212 return ItestDual_QueryInterface(&TestDual, riid, ppv);
215 static ULONG WINAPI TestSecondIface_AddRef(ITestSecondIface *iface)
217 return 2;
220 static ULONG WINAPI TestSecondIface_Release(ITestSecondIface *iface)
222 return 1;
225 static HRESULT WINAPI TestSecondIface_test(ITestSecondIface *iface)
227 return 1;
230 static const ITestSecondIfaceVtbl TestSecondIfaceVtbl = {
231 TestSecondIface_QueryInterface,
232 TestSecondIface_AddRef,
233 TestSecondIface_Release,
234 TestSecondIface_test
237 static ITestSecondIface TestSecondIface = { &TestSecondIfaceVtbl };
239 static HRESULT WINAPI TestSecondDisp_QueryInterface(ITestSecondDisp *iface, REFIID riid, void **ppv)
241 return ItestDual_QueryInterface(&TestDual, riid, ppv);
244 static ULONG WINAPI TestSecondDisp_AddRef(ITestSecondDisp *iface)
246 return 2;
249 static ULONG WINAPI TestSecondDisp_Release(ITestSecondDisp *iface)
251 return 1;
254 static HRESULT WINAPI TestSecondDisp_GetTypeInfoCount(ITestSecondDisp *iface, UINT *pctinfo)
256 ok(0, "unexpected call\n");
257 return E_NOTIMPL;
260 static HRESULT WINAPI TestSecondDisp_GetTypeInfo(ITestSecondDisp *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
262 ok(0, "unexpected call\n");
263 return E_NOTIMPL;
266 static HRESULT WINAPI TestSecondDisp_GetIDsOfNames(ITestSecondDisp *iface, REFIID riid, LPOLESTR *rgszNames,
267 UINT cNames, LCID lcid, DISPID *rgDispId)
269 ok(0, "unexpected call\n");
270 return E_NOTIMPL;
273 static HRESULT WINAPI TestSecondDisp_Invoke(ITestSecondDisp *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
274 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
275 UINT *puArgErr)
277 ok(0, "unexpected call\n");
278 return E_NOTIMPL;
281 static HRESULT WINAPI TestSecondDisp_test(ITestSecondDisp *iface)
283 ok(0, "unexpected call\n");
284 return E_NOTIMPL;
287 static ITestSecondDispVtbl TestSecondDispVtbl = {
288 TestSecondDisp_QueryInterface,
289 TestSecondDisp_AddRef,
290 TestSecondDisp_Release,
291 TestSecondDisp_GetTypeInfoCount,
292 TestSecondDisp_GetTypeInfo,
293 TestSecondDisp_GetIDsOfNames,
294 TestSecondDisp_Invoke,
295 TestSecondDisp_test
298 static ITestSecondDisp TestSecondDisp = { &TestSecondDispVtbl };
300 static HRESULT WINAPI TestDual_QueryInterface(ItestDual *iface, REFIID riid, void **ppvObject)
302 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch)) {
303 *ppvObject = &TestDualDisp;
304 return S_OK;
305 }else if(IsEqualGUID(riid, &IID_ItestDual)) {
306 *ppvObject = &TestDual;
307 return S_OK;
308 }else if(IsEqualGUID(riid, &IID_ITestSecondIface)) {
309 *ppvObject = &TestSecondIface;
310 return S_OK;
311 }else if(IsEqualGUID(riid, &IID_ITestSecondDisp)) {
312 *ppvObject = &TestSecondDisp;
313 return S_OK;
314 }else if (IsEqualGUID(riid, &IID_IExternalConnection)) {
315 trace("QI external connection\n");
316 *ppvObject = &ExternalConnection;
317 return S_OK;
320 *ppvObject = NULL;
321 return E_NOINTERFACE;
324 static ULONG WINAPI TestDual_AddRef(ItestDual *iface)
326 return 2;
329 static ULONG WINAPI TestDual_Release(ItestDual *iface)
331 return 1;
334 static HRESULT WINAPI TestDual_GetTypeInfoCount(ItestDual *iface, UINT *pctinfo)
336 ok(0, "unexpected call\n");
337 return E_NOTIMPL;
340 static HRESULT WINAPI TestDual_GetTypeInfo(ItestDual *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
342 ok(0, "unexpected call\n");
343 return E_NOTIMPL;
346 static HRESULT WINAPI TestDual_GetIDsOfNames(ItestDual *iface, REFIID riid, LPOLESTR *rgszNames,
347 UINT cNames, LCID lcid, DISPID *rgDispId)
349 ok(0, "unexpected call\n");
350 return E_NOTIMPL;
353 static HRESULT WINAPI TestDual_Invoke(ItestDual *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
354 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
355 UINT *puArgErr)
357 ok(0, "unexpected call\n");
358 return E_NOTIMPL;
361 static ItestDualVtbl TestDualVtbl = {
362 TestDual_QueryInterface,
363 TestDual_AddRef,
364 TestDual_Release,
365 TestDual_GetTypeInfoCount,
366 TestDual_GetTypeInfo,
367 TestDual_GetIDsOfNames,
368 TestDual_Invoke
371 static ItestDual TestDual = { &TestDualVtbl };
372 static ItestDual TestDualDisp = { &TestDualVtbl };
374 typedef struct Widget
376 IWidget IWidget_iface;
377 LONG refs;
378 IUnknown *pDispatchUnknown;
379 } Widget;
381 static inline Widget *impl_from_IWidget(IWidget *iface)
383 return CONTAINING_RECORD(iface, Widget, IWidget_iface);
386 static HRESULT WINAPI Widget_QueryInterface(
387 IWidget *iface,
388 /* [in] */ REFIID riid,
389 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
391 if (IsEqualIID(riid, &IID_IWidget) || IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch))
393 IWidget_AddRef(iface);
394 *ppvObject = iface;
395 return S_OK;
397 else
399 *ppvObject = NULL;
400 return E_NOINTERFACE;
404 static ULONG WINAPI Widget_AddRef(
405 IWidget *iface)
407 Widget *This = impl_from_IWidget(iface);
409 return InterlockedIncrement(&This->refs);
412 static ULONG WINAPI Widget_Release(
413 IWidget *iface)
415 Widget *This = impl_from_IWidget(iface);
416 ULONG refs = InterlockedDecrement(&This->refs);
417 if (!refs)
419 IUnknown_Release(This->pDispatchUnknown);
420 memset(This, 0xcc, sizeof(*This));
421 HeapFree(GetProcessHeap(), 0, This);
422 trace("Widget destroyed!\n");
425 return refs;
428 static HRESULT WINAPI Widget_GetTypeInfoCount(
429 IWidget *iface,
430 /* [out] */ UINT __RPC_FAR *pctinfo)
432 Widget *This = impl_from_IWidget(iface);
433 IDispatch *pDispatch;
434 HRESULT hr = IUnknown_QueryInterface(This->pDispatchUnknown, &IID_IDispatch, (void **)&pDispatch);
435 if (SUCCEEDED(hr))
437 hr = IDispatch_GetTypeInfoCount(pDispatch, pctinfo);
438 IDispatch_Release(pDispatch);
440 return hr;
443 static HRESULT WINAPI Widget_GetTypeInfo(
444 IWidget __RPC_FAR * iface,
445 /* [in] */ UINT iTInfo,
446 /* [in] */ LCID lcid,
447 /* [out] */ ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo)
449 Widget *This = impl_from_IWidget(iface);
450 IDispatch *pDispatch;
451 HRESULT hr = IUnknown_QueryInterface(This->pDispatchUnknown, &IID_IDispatch, (void **)&pDispatch);
452 if (SUCCEEDED(hr))
454 hr = IDispatch_GetTypeInfo(pDispatch, iTInfo, lcid, ppTInfo);
455 IDispatch_Release(pDispatch);
457 return hr;
460 static HRESULT WINAPI Widget_GetIDsOfNames(
461 IWidget __RPC_FAR * iface,
462 /* [in] */ REFIID riid,
463 /* [size_is][in] */ LPOLESTR __RPC_FAR *rgszNames,
464 /* [in] */ UINT cNames,
465 /* [in] */ LCID lcid,
466 /* [size_is][out] */ DISPID __RPC_FAR *rgDispId)
468 Widget *This = impl_from_IWidget(iface);
469 IDispatch *pDispatch;
470 HRESULT hr = IUnknown_QueryInterface(This->pDispatchUnknown, &IID_IDispatch, (void **)&pDispatch);
471 if (SUCCEEDED(hr))
473 hr = IDispatch_GetIDsOfNames(pDispatch, riid, rgszNames, cNames, lcid, rgDispId);
474 IDispatch_Release(pDispatch);
476 return hr;
479 static HRESULT WINAPI Widget_Invoke(
480 IWidget __RPC_FAR * iface,
481 /* [in] */ DISPID dispIdMember,
482 /* [in] */ REFIID riid,
483 /* [in] */ LCID lcid,
484 /* [in] */ WORD wFlags,
485 /* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams,
486 /* [out] */ VARIANT __RPC_FAR *pVarResult,
487 /* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo,
488 /* [out] */ UINT __RPC_FAR *puArgErr)
490 Widget *This = impl_from_IWidget(iface);
491 IDispatch *pDispatch;
492 HRESULT hr = IUnknown_QueryInterface(This->pDispatchUnknown, &IID_IDispatch, (void **)&pDispatch);
493 if (SUCCEEDED(hr))
495 hr = IDispatch_Invoke(pDispatch, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
496 IDispatch_Release(pDispatch);
498 return hr;
501 static HRESULT WINAPI Widget_put_Name(
502 IWidget __RPC_FAR * iface,
503 /* [in] */ BSTR name)
505 trace("put_Name(%s)\n", wine_dbgstr_w(name));
506 return S_OK;
509 static HRESULT WINAPI Widget_get_Name(
510 IWidget __RPC_FAR * iface,
511 /* [out] */ BSTR __RPC_FAR *name)
513 static const WCHAR szCat[] = { 'C','a','t',0 };
514 trace("get_Name()\n");
515 *name = SysAllocString(szCat);
516 return S_OK;
519 static HRESULT WINAPI Widget_DoSomething(
520 IWidget __RPC_FAR * iface,
521 /* [in] */ double number,
522 /* [out] */ BSTR *str1,
523 /* [defaultvalue][in] */ BSTR str2,
524 /* [optional][in] */ VARIANT __RPC_FAR *opt)
526 static const WCHAR szString[] = { 'S','t','r','i','n','g',0 };
527 trace("DoSomething()\n");
529 ok(number == 3.141, "number(%f) != 3.141\n", number);
530 ok(*str2 == '\0', "str2(%s) != \"\"\n", wine_dbgstr_w(str2));
531 ok(V_VT(opt) == VT_ERROR, "V_VT(opt) should be VT_ERROR instead of 0x%x\n", V_VT(opt));
532 ok(V_ERROR(opt) == DISP_E_PARAMNOTFOUND, "V_ERROR(opt) should be DISP_E_PARAMNOTFOUND instead of 0x%08x\n", V_ERROR(opt));
533 *str1 = SysAllocString(szString);
535 return S_FALSE;
538 static HRESULT WINAPI Widget_get_State(
539 IWidget __RPC_FAR * iface,
540 /* [retval][out] */ STATE __RPC_FAR *state)
542 trace("get_State() = STATE_WIDGETIFIED\n");
543 *state = STATE_WIDGETIFIED;
544 return S_OK;
547 static HRESULT WINAPI Widget_put_State(
548 IWidget __RPC_FAR * iface,
549 /* [in] */ STATE state)
551 trace("put_State(%d)\n", state);
552 return S_OK;
555 static HRESULT WINAPI Widget_Map(
556 IWidget * iface,
557 BSTR bstrId,
558 BSTR *sValue)
560 trace("Map(%s, %p)\n", wine_dbgstr_w(bstrId), sValue);
561 *sValue = SysAllocString(bstrId);
562 return S_OK;
565 static HRESULT WINAPI Widget_SetOleColor(
566 IWidget * iface,
567 OLE_COLOR val)
569 trace("SetOleColor(0x%x)\n", val);
570 return S_OK;
573 static HRESULT WINAPI Widget_GetOleColor(
574 IWidget * iface,
575 OLE_COLOR *pVal)
577 trace("GetOleColor() = 0x8000000f\n");
578 *pVal = 0x8000000f;
579 return S_FALSE;
582 static HRESULT WINAPI Widget_Clone(
583 IWidget *iface,
584 IWidget **ppVal)
586 trace("Clone()\n");
587 return Widget_QueryInterface(iface, &IID_IWidget, (void **)ppVal);
590 static HRESULT WINAPI Widget_CloneDispatch(
591 IWidget *iface,
592 IDispatch **ppVal)
594 trace("CloneDispatch()\n");
595 return Widget_QueryInterface(iface, &IID_IWidget, (void **)ppVal);
598 static HRESULT WINAPI Widget_CloneCoclass(
599 IWidget *iface,
600 ApplicationObject2 **ppVal)
602 trace("CloneCoclass()\n");
603 return S_OK;
606 static HRESULT WINAPI Widget_Value(
607 IWidget __RPC_FAR * iface,
608 VARIANT *value,
609 VARIANT *retval)
611 trace("Value(%p, %p)\n", value, retval);
612 ok(V_VT(value) == VT_I2, "V_VT(value) was %d instead of VT_I2\n", V_VT(value));
613 ok(V_I2(value) == 1, "V_I2(value) was %d instead of 1\n", V_I2(value));
614 V_VT(retval) = VT_I2;
615 V_I2(retval) = 1234;
616 return S_OK;
619 static HRESULT WINAPI Widget_Array(
620 IWidget * iface,
621 SAFEARRAY * values)
623 trace("Array(%p)\n", values);
624 return S_OK;
627 static HRESULT WINAPI Widget_VariantArrayPtr(
628 IWidget * iface,
629 SAFEARRAY ** values)
631 trace("VariantArrayPtr(%p)\n", values);
632 return S_OK;
635 static HRESULT WINAPI Widget_VariantCArray(
636 IWidget * iface,
637 ULONG count,
638 VARIANT values[])
640 ULONG i;
642 trace("VariantCArray(%u,%p)\n", count, values);
644 ok(count == 2, "count is %d\n", count);
645 for (i = 0; i < count; i++)
646 ok(V_VT(&values[i]) == VT_I4, "values[%d] is not VT_I4\n", i);
648 if (pVarAdd)
650 VARIANT inc, res;
651 HRESULT hr;
653 V_VT(&inc) = VT_I4;
654 V_I4(&inc) = 1;
655 for (i = 0; i < count; i++) {
656 VariantInit(&res);
657 hr = pVarAdd(&values[i], &inc, &res);
658 if (FAILED(hr)) {
659 ok(0, "VarAdd failed at %u with error 0x%x\n", i, hr);
660 return hr;
662 hr = VariantCopy(&values[i], &res);
663 if (FAILED(hr)) {
664 ok(0, "VariantCopy failed at %u with error 0x%x\n", i, hr);
665 return hr;
669 else
670 win_skip("VarAdd is not available\n");
672 return S_OK;
675 static HRESULT WINAPI Widget_Variant(
676 IWidget __RPC_FAR * iface,
677 VARIANT var)
679 trace("Variant()\n");
680 ok(V_VT(&var) == VT_CY, "V_VT(&var) was %d\n", V_VT(&var));
681 ok(S(V_CY(&var)).Hi == 0xdababe, "V_CY(&var).Hi was 0x%x\n", S(V_CY(&var)).Hi);
682 ok(S(V_CY(&var)).Lo == 0xdeadbeef, "V_CY(&var).Lo was 0x%x\n", S(V_CY(&var)).Lo);
683 return S_OK;
686 static HRESULT WINAPI Widget_VarArg(
687 IWidget * iface,
688 int numexpect,
689 SAFEARRAY * values)
691 LONG lbound, ubound, i;
692 VARIANT * data;
693 HRESULT hr;
695 trace("VarArg(%p)\n", values);
697 hr = SafeArrayGetLBound(values, 1, &lbound);
698 ok(hr == S_OK, "SafeArrayGetLBound failed with %x\n", hr);
699 ok(lbound == 0, "SafeArrayGetLBound returned %d\n", lbound);
701 hr = SafeArrayGetUBound(values, 1, &ubound);
702 ok(hr == S_OK, "SafeArrayGetUBound failed with %x\n", hr);
703 ok(ubound == numexpect-1, "SafeArrayGetUBound returned %d, but expected %d\n", ubound, numexpect-1);
705 hr = SafeArrayAccessData(values, (LPVOID)&data);
706 ok(hr == S_OK, "SafeArrayAccessData failed with %x\n", hr);
708 for (i=0; i<=ubound-lbound; i++)
710 ok(V_VT(&data[i]) == VT_I4, "V_VT(&data[%d]) was %d\n", i, V_VT(&data[i]));
711 ok(V_I4(&data[i]) == i, "V_I4(&data[%d]) was %d\n", i, V_I4(&data[i]));
714 hr = SafeArrayUnaccessData(values);
715 ok(hr == S_OK, "SafeArrayUnaccessData failed with %x\n", hr);
717 return S_OK;
721 static BOOL mystruct_uint_ordered(MYSTRUCT *mystruct)
723 int i;
724 for (i = 0; i < sizeof(mystruct->uarr)/sizeof(mystruct->uarr[0]); i++)
725 if (mystruct->uarr[i] != i)
726 return 0;
728 return 1;
731 static HRESULT WINAPI Widget_StructArgs(
732 IWidget * iface,
733 MYSTRUCT byval,
734 MYSTRUCT *byptr,
735 MYSTRUCT arr[5])
737 int i, diff = 0;
738 ok(byval.field1 == MYSTRUCT_BYVAL.field1 &&
739 byval.field2 == MYSTRUCT_BYVAL.field2 &&
740 mystruct_uint_ordered(&byval),
741 "Struct parameter passed by value corrupted\n");
742 ok(byptr->field1 == MYSTRUCT_BYPTR.field1 &&
743 byptr->field2 == MYSTRUCT_BYPTR.field2 &&
744 mystruct_uint_ordered(byptr),
745 "Struct parameter passed by pointer corrupted\n");
746 for (i = 0; i < 5; i++)
747 if (arr[i].field1 != MYSTRUCT_ARRAY[i].field1 ||
748 arr[i].field2 != MYSTRUCT_ARRAY[i].field2 ||
749 ! mystruct_uint_ordered(&arr[i]))
750 diff++;
751 ok(diff == 0, "Array of structs corrupted\n");
752 return S_OK;
756 static HRESULT WINAPI Widget_Error(
757 IWidget __RPC_FAR * iface)
759 trace("Error()\n");
760 return E_NOTIMPL;
763 static HRESULT WINAPI Widget_CloneInterface(
764 IWidget __RPC_FAR * iface,
765 ISomethingFromDispatch **ppVal)
767 trace("CloneInterface()\n");
768 *ppVal = 0;
769 return S_OK;
772 static HRESULT WINAPI Widget_put_prop_with_lcid(
773 IWidget* iface, LONG lcid, INT i)
775 trace("put_prop_with_lcid(%08x, %x)\n", lcid, i);
776 ok(lcid == MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), "got lcid %08x\n", lcid);
777 ok(i == 0xcafe, "got %08x\n", i);
778 return S_OK;
781 static HRESULT WINAPI Widget_get_prop_with_lcid(
782 IWidget* iface, LONG lcid, INT *i)
784 trace("get_prop_with_lcid(%08x, %p)\n", lcid, i);
785 ok(lcid == MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), "got lcid %08x\n", lcid);
786 *i = lcid;
787 return S_OK;
790 static HRESULT WINAPI Widget_get_prop_int(
791 IWidget* iface, INT *i)
793 trace("get_prop_int(%p)\n", i);
794 *i = -13;
795 return S_OK;
798 static HRESULT WINAPI Widget_get_prop_uint(
799 IWidget* iface, UINT *i)
801 trace("get_prop_uint(%p)\n", i);
802 *i = 42;
803 return S_OK;
806 static HRESULT WINAPI Widget_ByRefUInt(
807 IWidget* iface, UINT *i)
809 *i = 42;
810 return S_OK;
813 static HRESULT WINAPI Widget_put_prop_opt_arg(
814 IWidget* iface, INT opt, INT i)
816 trace("put_prop_opt_arg(%08x, %08x)\n", opt, i);
817 todo_wine ok(opt == 0, "got opt=%08x\n", opt);
818 ok(i == 0xcafe, "got i=%08x\n", i);
819 return S_OK;
822 static HRESULT WINAPI Widget_put_prop_req_arg(
823 IWidget* iface, INT req, INT i)
825 trace("put_prop_req_arg(%08x, %08x)\n", req, i);
826 ok(req == 0x5678, "got req=%08x\n", req);
827 ok(i == 0x1234, "got i=%08x\n", i);
828 return S_OK;
831 static HRESULT WINAPI Widget__restrict(IWidget* iface, INT *i)
833 trace("restrict\n");
834 *i = DISPID_TM_RESTRICTED;
835 return S_OK;
838 static HRESULT WINAPI Widget_neg_restrict(IWidget* iface, INT *i)
840 trace("neg_restrict\n");
841 *i = DISPID_TM_NEG_RESTRICTED;
842 return S_OK;
845 static const struct IWidgetVtbl Widget_VTable =
847 Widget_QueryInterface,
848 Widget_AddRef,
849 Widget_Release,
850 Widget_GetTypeInfoCount,
851 Widget_GetTypeInfo,
852 Widget_GetIDsOfNames,
853 Widget_Invoke,
854 Widget_put_Name,
855 Widget_get_Name,
856 Widget_DoSomething,
857 Widget_get_State,
858 Widget_put_State,
859 Widget_Map,
860 Widget_SetOleColor,
861 Widget_GetOleColor,
862 Widget_Clone,
863 Widget_CloneDispatch,
864 Widget_CloneCoclass,
865 Widget_Value,
866 Widget_Array,
867 Widget_VariantArrayPtr,
868 Widget_VariantCArray,
869 Widget_Variant,
870 Widget_VarArg,
871 Widget_StructArgs,
872 Widget_Error,
873 Widget_CloneInterface,
874 Widget_put_prop_with_lcid,
875 Widget_get_prop_with_lcid,
876 Widget_get_prop_int,
877 Widget_get_prop_uint,
878 Widget_ByRefUInt,
879 Widget_put_prop_opt_arg,
880 Widget_put_prop_req_arg,
881 Widget__restrict,
882 Widget_neg_restrict
885 static HRESULT WINAPI StaticWidget_QueryInterface(IStaticWidget *iface, REFIID riid, void **ppvObject)
887 if (IsEqualIID(riid, &IID_IStaticWidget) || IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDispatch))
889 IStaticWidget_AddRef(iface);
890 *ppvObject = iface;
891 return S_OK;
894 *ppvObject = NULL;
895 return E_NOINTERFACE;
898 static ULONG WINAPI StaticWidget_AddRef(IStaticWidget *iface)
900 return 2;
903 static ULONG WINAPI StaticWidget_Release(IStaticWidget *iface)
905 return 1;
908 static HRESULT WINAPI StaticWidget_GetTypeInfoCount(IStaticWidget *iface, UINT *pctinfo)
910 ok(0, "unexpected call\n");
911 return E_NOTIMPL;
914 static HRESULT WINAPI StaticWidget_GetTypeInfo(IStaticWidget *iface, UINT iTInfo, LCID lcid,
915 ITypeInfo **ppTInfo)
917 ok(0, "unexpected call\n");
918 return E_NOTIMPL;
921 static HRESULT WINAPI StaticWidget_GetIDsOfNames(IStaticWidget *iface, REFIID riid, LPOLESTR *rgszNames,
922 UINT cNames, LCID lcid, DISPID *rgDispId)
924 ok(0, "unexpected call\n");
925 return E_NOTIMPL;
928 static HRESULT WINAPI StaticWidget_Invoke(IStaticWidget *iface, DISPID dispIdMember, REFIID riid,
929 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
930 UINT *puArgErr)
932 ok(0, "unexpected call\n");
933 return E_NOTIMPL;
936 static HRESULT WINAPI StaticWidget_TestDual(IStaticWidget *iface, ItestDual *p)
938 trace("TestDual()\n");
939 ok(p == &TestDual, "wrong ItestDual\n");
940 return S_OK;
943 static HRESULT WINAPI StaticWidget_TestSecondIface(IStaticWidget *iface, ITestSecondIface *p)
945 trace("TestSecondIface()\n");
946 ok(p == &TestSecondIface, "wrong ItestSecondIface\n");
947 return S_OK;
950 static const IStaticWidgetVtbl StaticWidgetVtbl = {
951 StaticWidget_QueryInterface,
952 StaticWidget_AddRef,
953 StaticWidget_Release,
954 StaticWidget_GetTypeInfoCount,
955 StaticWidget_GetTypeInfo,
956 StaticWidget_GetIDsOfNames,
957 StaticWidget_Invoke,
958 StaticWidget_TestDual,
959 StaticWidget_TestSecondIface
962 static IStaticWidget StaticWidget = { &StaticWidgetVtbl };
964 typedef struct KindaEnum
966 IKindaEnumWidget IKindaEnumWidget_iface;
967 LONG refs;
968 } KindaEnum;
970 static inline KindaEnum *impl_from_IKindaEnumWidget(IKindaEnumWidget *iface)
972 return CONTAINING_RECORD(iface, KindaEnum, IKindaEnumWidget_iface);
975 static HRESULT register_current_module_typelib(void)
977 WCHAR path[MAX_PATH];
978 CHAR pathA[MAX_PATH];
979 HRESULT hr;
980 ITypeLib *typelib;
982 GetModuleFileNameA(NULL, pathA, MAX_PATH);
983 MultiByteToWideChar(CP_ACP, 0, pathA, -1, path, MAX_PATH);
985 hr = LoadTypeLib(path, &typelib);
986 if (SUCCEEDED(hr))
988 hr = RegisterTypeLib(typelib, path, NULL);
989 ITypeLib_Release(typelib);
991 return hr;
994 static ITypeInfo *get_type_info(REFIID riid)
996 ITypeInfo *pTypeInfo;
997 ITypeLib *pTypeLib;
998 HRESULT hr;
1000 hr = LoadRegTypeLib(&LIBID_TestTypelib, 1, 0, LOCALE_NEUTRAL, &pTypeLib);
1001 ok_ole_success(hr, LoadRegTypeLib);
1002 if (FAILED(hr))
1003 return NULL;
1005 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, riid, &pTypeInfo);
1006 ITypeLib_Release(pTypeLib);
1007 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
1008 if (FAILED(hr))
1009 return NULL;
1011 return pTypeInfo;
1014 static IWidget *Widget_Create(void)
1016 Widget *This;
1017 ITypeInfo *pTypeInfo;
1018 HRESULT hr = E_FAIL;
1020 pTypeInfo = get_type_info(&IID_IWidget);
1021 if(!pTypeInfo)
1022 return NULL;
1024 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1025 This->IWidget_iface.lpVtbl = &Widget_VTable;
1026 This->refs = 1;
1027 This->pDispatchUnknown = NULL;
1029 hr = CreateStdDispatch((IUnknown *)&This->IWidget_iface, This, pTypeInfo,
1030 &This->pDispatchUnknown);
1031 ok_ole_success(hr, CreateStdDispatch);
1032 ITypeInfo_Release(pTypeInfo);
1034 if (SUCCEEDED(hr))
1035 return &This->IWidget_iface;
1036 else
1038 HeapFree(GetProcessHeap(), 0, This);
1039 return NULL;
1043 static HRESULT WINAPI KindaEnum_QueryInterface(
1044 IKindaEnumWidget *iface,
1045 /* [in] */ REFIID riid,
1046 /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject)
1048 if (IsEqualIID(riid, &IID_IKindaEnumWidget) || IsEqualIID(riid, &IID_IUnknown))
1050 IKindaEnumWidget_AddRef(iface);
1051 *ppvObject = iface;
1052 return S_OK;
1054 else
1056 *ppvObject = NULL;
1057 return E_NOINTERFACE;
1061 static ULONG WINAPI KindaEnum_AddRef(
1062 IKindaEnumWidget *iface)
1064 KindaEnum *This = impl_from_IKindaEnumWidget(iface);
1066 return InterlockedIncrement(&This->refs);
1069 static ULONG WINAPI KindaEnum_Release(
1070 IKindaEnumWidget *iface)
1072 KindaEnum *This = impl_from_IKindaEnumWidget(iface);
1073 ULONG refs = InterlockedDecrement(&This->refs);
1074 if (!refs)
1076 memset(This, 0xcc, sizeof(*This));
1077 HeapFree(GetProcessHeap(), 0, This);
1078 trace("KindaEnumWidget destroyed!\n");
1081 return refs;
1084 static HRESULT WINAPI KindaEnum_Next(
1085 IKindaEnumWidget *iface,
1086 /* [out] */ IWidget __RPC_FAR *__RPC_FAR *widget)
1088 *widget = Widget_Create();
1089 if (*widget)
1090 return S_OK;
1091 else
1092 return E_OUTOFMEMORY;
1095 static HRESULT WINAPI KindaEnum_Count(
1096 IKindaEnumWidget *iface,
1097 /* [out] */ ULONG __RPC_FAR *count)
1099 return E_NOTIMPL;
1102 static HRESULT WINAPI KindaEnum_Reset(
1103 IKindaEnumWidget *iface)
1105 return E_NOTIMPL;
1108 static HRESULT WINAPI KindaEnum_Clone(
1109 IKindaEnumWidget *iface,
1110 /* [out] */ IKindaEnumWidget __RPC_FAR *__RPC_FAR *ppenum)
1112 return E_NOTIMPL;
1115 static const IKindaEnumWidgetVtbl KindaEnumWidget_VTable =
1117 KindaEnum_QueryInterface,
1118 KindaEnum_AddRef,
1119 KindaEnum_Release,
1120 KindaEnum_Next,
1121 KindaEnum_Count,
1122 KindaEnum_Reset,
1123 KindaEnum_Clone
1126 static IKindaEnumWidget *KindaEnumWidget_Create(void)
1128 KindaEnum *This;
1130 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1131 if (!This) return NULL;
1132 This->IKindaEnumWidget_iface.lpVtbl = &KindaEnumWidget_VTable;
1133 This->refs = 1;
1134 return &This->IKindaEnumWidget_iface;
1137 static HRESULT WINAPI NonOleAutomation_QueryInterface(INonOleAutomation *iface, REFIID riid, void **ppv)
1139 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_INonOleAutomation))
1141 *(INonOleAutomation **)ppv = iface;
1142 return S_OK;
1144 *ppv = NULL;
1145 return E_NOINTERFACE;
1148 static ULONG WINAPI NonOleAutomation_AddRef(INonOleAutomation *iface)
1150 return 2;
1153 static ULONG WINAPI NonOleAutomation_Release(INonOleAutomation *iface)
1155 return 1;
1158 static BSTR WINAPI NonOleAutomation_BstrRet(INonOleAutomation *iface)
1160 static const WCHAR wszTestString[] = {'T','h','i','s',' ','i','s',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0};
1161 return SysAllocString(wszTestString);
1164 static HRESULT WINAPI NonOleAutomation_Error(INonOleAutomation *iface)
1166 return E_NOTIMPL;
1169 static INonOleAutomationVtbl NonOleAutomation_VTable =
1171 NonOleAutomation_QueryInterface,
1172 NonOleAutomation_AddRef,
1173 NonOleAutomation_Release,
1174 NonOleAutomation_BstrRet,
1175 NonOleAutomation_Error
1178 static INonOleAutomation NonOleAutomation = { &NonOleAutomation_VTable };
1180 static ITypeInfo *NonOleAutomation_GetTypeInfo(void)
1182 ITypeLib *pTypeLib;
1183 HRESULT hr = LoadRegTypeLib(&LIBID_TestTypelib, 1, 0, LOCALE_NEUTRAL, &pTypeLib);
1184 ok_ole_success(hr, LoadRegTypeLib);
1185 if (SUCCEEDED(hr))
1187 ITypeInfo *pTypeInfo;
1188 hr = ITypeLib_GetTypeInfoOfGuid(pTypeLib, &IID_INonOleAutomation, &pTypeInfo);
1189 ok_ole_success(hr, ITypeLib_GetTypeInfoOfGuid);
1190 ITypeLib_Release(pTypeLib);
1191 return pTypeInfo;
1193 return NULL;
1196 static void test_typelibmarshal(void)
1198 static const WCHAR szCat[] = { 'C','a','t',0 };
1199 static const WCHAR szTestTest[] = { 'T','e','s','t','T','e','s','t',0 };
1200 static WCHAR szSuperman[] = { 'S','u','p','e','r','m','a','n',0 };
1201 HRESULT hr;
1202 IKindaEnumWidget *pKEW = KindaEnumWidget_Create();
1203 IWidget *pWidget;
1204 IStream *pStream;
1205 IDispatch *pDispatch;
1206 static const LARGE_INTEGER ullZero;
1207 EXCEPINFO excepinfo;
1208 VARIANT varresult;
1209 DISPID dispidNamed = DISPID_PROPERTYPUT;
1210 DISPPARAMS dispparams;
1211 VARIANTARG vararg[4];
1212 STATE the_state;
1213 HANDLE thread;
1214 DWORD tid;
1215 BSTR bstr;
1216 ITypeInfo *pTypeInfo;
1217 MYSTRUCT mystruct;
1218 MYSTRUCT mystructArray[5];
1219 UINT uval;
1221 ok(pKEW != NULL, "Widget creation failed\n");
1223 hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
1224 ok_ole_success(hr, CreateStreamOnHGlobal);
1225 tid = start_host_object(pStream, &IID_IKindaEnumWidget, (IUnknown *)pKEW, MSHLFLAGS_NORMAL, &thread);
1226 IKindaEnumWidget_Release(pKEW);
1228 IStream_Seek(pStream, ullZero, STREAM_SEEK_SET, NULL);
1229 hr = CoUnmarshalInterface(pStream, &IID_IKindaEnumWidget, (void **)&pKEW);
1230 ok_ole_success(hr, CoUnmarshalInterface);
1231 IStream_Release(pStream);
1233 hr = IKindaEnumWidget_Next(pKEW, &pWidget);
1234 ok_ole_success(hr, IKindaEnumWidget_Next);
1236 IKindaEnumWidget_Release(pKEW);
1238 /* call GetTypeInfoCount (direct) */
1239 hr = IWidget_GetTypeInfoCount(pWidget, &uval);
1240 ok_ole_success(hr, IWidget_GetTypeInfoCount);
1241 hr = IWidget_GetTypeInfoCount(pWidget, &uval);
1242 ok_ole_success(hr, IWidget_GetTypeInfoCount);
1244 hr = IWidget_QueryInterface(pWidget, &IID_IDispatch, (void **)&pDispatch);
1245 ok_ole_success(hr, IWidget_QueryInterface);
1247 /* call put_Name */
1248 VariantInit(&vararg[0]);
1249 dispparams.cNamedArgs = 1;
1250 dispparams.rgdispidNamedArgs = &dispidNamed;
1251 dispparams.cArgs = 1;
1252 dispparams.rgvarg = vararg;
1253 VariantInit(&varresult);
1254 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1255 ok_ole_success(hr, IDispatch_Invoke);
1256 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1257 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1258 excepinfo.wCode, excepinfo.scode);
1259 VariantClear(&varresult);
1261 /* call put_Name (direct) */
1262 bstr = SysAllocString(szSuperman);
1263 hr = IWidget_put_Name(pWidget, bstr);
1264 ok_ole_success(hr, IWidget_put_Name);
1265 SysFreeString(bstr);
1267 /* call get_Name */
1268 dispparams.cNamedArgs = 0;
1269 dispparams.rgdispidNamedArgs = NULL;
1270 dispparams.cArgs = 0;
1271 dispparams.rgvarg = NULL;
1272 VariantInit(&varresult);
1273 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1274 ok_ole_success(hr, IDispatch_Invoke);
1275 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1276 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1277 excepinfo.wCode, excepinfo.scode);
1278 trace("Name = %s\n", wine_dbgstr_w(V_BSTR(&varresult)));
1279 VariantClear(&varresult);
1281 /* call get_Name (direct) */
1282 bstr = (void *)0xdeadbeef;
1283 hr = IWidget_get_Name(pWidget, &bstr);
1284 ok_ole_success(hr, IWidget_get_Name);
1285 ok(!lstrcmpW(bstr, szCat), "IWidget_get_Name should have returned string \"Cat\" instead of %s\n", wine_dbgstr_w(bstr));
1286 SysFreeString(bstr);
1288 /* call DoSomething */
1289 VariantInit(&vararg[0]);
1290 VariantInit(&vararg[1]);
1291 V_VT(&vararg[1]) = VT_R8;
1292 V_R8(&vararg[1]) = 3.141;
1293 dispparams.cNamedArgs = 0;
1294 dispparams.cArgs = 2;
1295 dispparams.rgdispidNamedArgs = NULL;
1296 dispparams.rgvarg = vararg;
1297 VariantInit(&varresult);
1298 hr = IDispatch_Invoke(pDispatch, DISPID_TM_DOSOMETHING, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1299 ok_ole_success(hr, IDispatch_Invoke);
1300 ok(V_VT(&varresult) == VT_EMPTY, "varresult should be VT_EMPTY\n");
1301 VariantClear(&varresult);
1303 /* call get_State */
1304 dispparams.cNamedArgs = 0;
1305 dispparams.cArgs = 0;
1306 dispparams.rgdispidNamedArgs = NULL;
1307 dispparams.rgvarg = NULL;
1308 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1309 ok_ole_success(hr, IDispatch_Invoke);
1310 ok((V_VT(&varresult) == VT_I4) && (V_I4(&varresult) == STATE_WIDGETIFIED), "Return val mismatch\n");
1312 /* call get_State (direct) */
1313 hr = IWidget_get_State(pWidget, &the_state);
1314 ok_ole_success(hr, IWidget_get_state);
1315 ok(the_state == STATE_WIDGETIFIED, "should have returned WIDGET_WIDGETIFIED instead of %d\n", the_state);
1317 /* call put_State */
1318 the_state = STATE_WIDGETIFIED;
1319 VariantInit(&vararg[0]);
1320 V_VT(&vararg[0]) = VT_BYREF|VT_I4;
1321 V_I4REF(&vararg[0]) = (int *)&the_state;
1322 dispparams.cNamedArgs = 1;
1323 dispparams.cArgs = 1;
1324 dispparams.rgdispidNamedArgs = &dispidNamed;
1325 dispparams.rgvarg = vararg;
1326 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1327 ok_ole_success(hr, IDispatch_Invoke);
1329 /* call Map */
1330 bstr = SysAllocString(szTestTest);
1331 VariantInit(&vararg[0]);
1332 V_VT(&vararg[0]) = VT_BYREF|VT_BSTR;
1333 V_BSTRREF(&vararg[0]) = &bstr;
1334 dispparams.cNamedArgs = 0;
1335 dispparams.cArgs = 1;
1336 dispparams.rgdispidNamedArgs = NULL;
1337 dispparams.rgvarg = vararg;
1338 VariantInit(&varresult);
1339 hr = IDispatch_Invoke(pDispatch, DISPID_TM_MAP, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1340 ok_ole_success(hr, IDispatch_Invoke);
1341 ok(V_VT(&varresult) == VT_BSTR, "Return value should be of type BSTR instead of %d\n", V_VT(&varresult));
1342 ok(!lstrcmpW(V_BSTR(&varresult), szTestTest), "Return value should have been \"TestTest\" instead of %s\n", wine_dbgstr_w(V_BSTR(&varresult)));
1343 VariantClear(&varresult);
1344 SysFreeString(bstr);
1346 /* call SetOleColor with large negative VT_I4 param */
1347 VariantInit(&vararg[0]);
1348 V_VT(&vararg[0]) = VT_I4;
1349 V_I4(&vararg[0]) = 0x80000005;
1350 dispparams.cNamedArgs = 0;
1351 dispparams.cArgs = 1;
1352 dispparams.rgdispidNamedArgs = NULL;
1353 dispparams.rgvarg = vararg;
1354 hr = IDispatch_Invoke(pDispatch, DISPID_TM_SETOLECOLOR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, &excepinfo, NULL);
1355 ok_ole_success(hr, IDispatch_Invoke);
1357 /* call GetOleColor */
1358 dispparams.cNamedArgs = 0;
1359 dispparams.cArgs = 0;
1360 dispparams.rgdispidNamedArgs = NULL;
1361 dispparams.rgvarg = NULL;
1362 VariantInit(&varresult);
1363 hr = IDispatch_Invoke(pDispatch, DISPID_TM_GETOLECOLOR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1364 ok_ole_success(hr, IDispatch_Invoke);
1365 VariantClear(&varresult);
1367 /* call StructArgs (direct) */
1368 mystruct = MYSTRUCT_BYPTR;
1369 memcpy(mystructArray, MYSTRUCT_ARRAY, sizeof(mystructArray));
1370 hr = IWidget_StructArgs(pWidget, MYSTRUCT_BYVAL, &mystruct, mystructArray);
1371 ok_ole_success(hr, IWidget_StructArgs);
1373 /* call Clone */
1374 dispparams.cNamedArgs = 0;
1375 dispparams.cArgs = 0;
1376 dispparams.rgdispidNamedArgs = NULL;
1377 dispparams.rgvarg = NULL;
1378 VariantInit(&varresult);
1379 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1380 ok_ole_success(hr, IDispatch_Invoke);
1381 ok(V_VT(&varresult) == VT_DISPATCH, "vt %x\n", V_VT(&varresult));
1382 VariantClear(&varresult);
1384 /* call CloneInterface */
1385 dispparams.cNamedArgs = 0;
1386 dispparams.cArgs = 0;
1387 dispparams.rgdispidNamedArgs = NULL;
1388 dispparams.rgvarg = NULL;
1389 VariantInit(&varresult);
1390 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONEINTERFACE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1391 ok_ole_success(hr, IDispatch_Invoke);
1392 ok(V_VT(&varresult) == VT_DISPATCH, "vt %x\n", V_VT(&varresult));
1393 VariantClear(&varresult);
1395 /* call CloneDispatch with automatic value getting */
1396 V_VT(&vararg[0]) = VT_I2;
1397 V_I2(&vararg[0]) = 1;
1398 dispparams.cNamedArgs = 0;
1399 dispparams.rgdispidNamedArgs = NULL;
1400 dispparams.cArgs = 1;
1401 dispparams.rgvarg = vararg;
1402 VariantInit(&varresult);
1403 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONEDISPATCH, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1404 ok_ole_success(hr, IDispatch_Invoke);
1406 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1407 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1408 excepinfo.wCode, excepinfo.scode);
1410 ok(V_VT(&varresult) == VT_I2, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult));
1411 ok(V_I2(&varresult) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult));
1412 VariantClear(&varresult);
1414 /* call CloneCoclass */
1415 dispparams.cNamedArgs = 0;
1416 dispparams.cArgs = 0;
1417 dispparams.rgdispidNamedArgs = NULL;
1418 dispparams.rgvarg = NULL;
1419 VariantInit(&varresult);
1420 hr = IDispatch_Invoke(pDispatch, DISPID_TM_CLONECOCLASS, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1421 ok_ole_success(hr, IDispatch_Invoke);
1423 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1424 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1425 excepinfo.wCode, excepinfo.scode);
1427 ok(V_VT(&varresult) == VT_DISPATCH, "V_VT(&varresult) was %d instead of VT_DISPATCH\n", V_VT(&varresult));
1428 ok(!V_DISPATCH(&varresult), "V_DISPATCH(&varresult) should be NULL instead of %p\n", V_DISPATCH(&varresult));
1429 VariantClear(&varresult);
1431 /* call Value with a VT_VARIANT|VT_BYREF type */
1432 V_VT(&vararg[0]) = VT_VARIANT|VT_BYREF;
1433 V_VARIANTREF(&vararg[0]) = &vararg[1];
1434 V_VT(&vararg[1]) = VT_I2;
1435 V_I2(&vararg[1]) = 1;
1436 dispparams.cNamedArgs = 0;
1437 dispparams.rgdispidNamedArgs = NULL;
1438 dispparams.cArgs = 1;
1439 dispparams.rgvarg = vararg;
1440 VariantInit(&varresult);
1441 hr = IDispatch_Invoke(pDispatch, DISPID_VALUE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1442 ok_ole_success(hr, IDispatch_Invoke);
1444 ok(excepinfo.wCode == 0x0 && excepinfo.scode == S_OK,
1445 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1446 excepinfo.wCode, excepinfo.scode);
1448 ok(V_VT(&varresult) == VT_I2, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult));
1449 ok(V_I2(&varresult) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult));
1450 VariantClear(&varresult);
1452 /* call Variant - exercises variant copying in ITypeInfo::Invoke and
1453 * handling of void return types */
1454 /* use a big type to ensure that the variant was properly copied into the
1455 * destination function's args */
1456 V_VT(&vararg[0]) = VT_CY;
1457 S(V_CY(&vararg[0])).Hi = 0xdababe;
1458 S(V_CY(&vararg[0])).Lo = 0xdeadbeef;
1459 dispparams.cNamedArgs = 0;
1460 dispparams.cArgs = 1;
1461 dispparams.rgdispidNamedArgs = NULL;
1462 dispparams.rgvarg = vararg;
1463 VariantInit(&varresult);
1464 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARIANT, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1465 ok_ole_success(hr, IDispatch_Invoke);
1466 VariantClear(&varresult);
1468 /* call VariantCArray - test marshaling of variant arrays */
1469 V_VT(&vararg[0]) = VT_I4;
1470 V_I4(&vararg[0]) = 1;
1471 V_VT(&vararg[1]) = VT_I4;
1472 V_I4(&vararg[1]) = 2;
1473 hr = IWidget_VariantCArray(pWidget, 2, vararg);
1474 ok_ole_success(hr, IWidget_VariantCArray);
1475 todo_wine
1476 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]));
1477 todo_wine
1478 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]));
1480 /* call VarArg */
1481 VariantInit(&vararg[3]);
1482 V_VT(&vararg[3]) = VT_I4;
1483 V_I4(&vararg[3]) = 3;
1484 VariantInit(&vararg[2]);
1485 V_VT(&vararg[2]) = VT_I4;
1486 V_I4(&vararg[2]) = 0;
1487 VariantInit(&vararg[1]);
1488 V_VT(&vararg[1]) = VT_I4;
1489 V_I4(&vararg[1]) = 1;
1490 VariantInit(&vararg[0]);
1491 V_VT(&vararg[0]) = VT_I4;
1492 V_I4(&vararg[0]) = 2;
1493 dispparams.cNamedArgs = 0;
1494 dispparams.cArgs = 4;
1495 dispparams.rgdispidNamedArgs = NULL;
1496 dispparams.rgvarg = vararg;
1497 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARARG, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1498 ok_ole_success(hr, ITypeInfo_Invoke);
1500 /* call VarArg, even one (non-optional, non-safearray) named argument is not allowed */
1501 dispidNamed = 0;
1502 dispparams.cNamedArgs = 1;
1503 dispparams.rgdispidNamedArgs = &dispidNamed;
1504 hr = IDispatch_Invoke(pDispatch, DISPID_TM_VARARG, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
1505 ok(hr == DISP_E_NONAMEDARGS, "IDispatch_Invoke should have returned DISP_E_NONAMEDARGS instead of 0x%08x\n", hr);
1506 dispidNamed = DISPID_PROPERTYPUT;
1508 /* call Error */
1509 dispparams.cNamedArgs = 0;
1510 dispparams.cArgs = 0;
1511 dispparams.rgdispidNamedArgs = NULL;
1512 dispparams.rgvarg = NULL;
1513 VariantInit(&varresult);
1514 hr = IDispatch_Invoke(pDispatch, DISPID_TM_ERROR, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, NULL, &excepinfo, NULL);
1515 ok(hr == DISP_E_EXCEPTION, "IDispatch_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr);
1516 ok(excepinfo.wCode == 0x0 && excepinfo.scode == E_NOTIMPL,
1517 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1518 excepinfo.wCode, excepinfo.scode);
1519 VariantClear(&varresult);
1521 /* call BstrRet */
1522 pTypeInfo = NonOleAutomation_GetTypeInfo();
1523 dispparams.cNamedArgs = 0;
1524 dispparams.cArgs = 0;
1525 dispparams.rgdispidNamedArgs = NULL;
1526 dispparams.rgvarg = NULL;
1527 VariantInit(&varresult);
1528 hr = ITypeInfo_Invoke(pTypeInfo, &NonOleAutomation, DISPID_NOA_BSTRRET, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1529 ok_ole_success(hr, ITypeInfo_Invoke);
1530 ok(V_VT(&varresult) == VT_BSTR, "V_VT(&varresult) should be VT_BSTR instead of %d\n", V_VT(&varresult));
1531 ok(V_BSTR(&varresult) != NULL, "V_BSTR(&varresult) should not be NULL\n");
1533 VariantClear(&varresult);
1535 dispparams.cNamedArgs = 0;
1536 dispparams.cArgs = 0;
1537 dispparams.rgdispidNamedArgs = NULL;
1538 dispparams.rgvarg = NULL;
1539 hr = ITypeInfo_Invoke(pTypeInfo, &NonOleAutomation, DISPID_NOA_ERROR, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1540 ok(hr == DISP_E_EXCEPTION, "ITypeInfo_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr);
1541 ok(V_VT(&varresult) == VT_EMPTY, "V_VT(&varresult) should be VT_EMPTY instead of %d\n", V_VT(&varresult));
1542 ok(excepinfo.wCode == 0x0 && excepinfo.scode == E_NOTIMPL,
1543 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1544 excepinfo.wCode, excepinfo.scode);
1545 VariantClear(&varresult);
1547 ITypeInfo_Release(pTypeInfo);
1549 /* tests call put_Name without named arg */
1550 VariantInit(&vararg[0]);
1551 dispparams.cNamedArgs = 0;
1552 dispparams.rgdispidNamedArgs = NULL;
1553 dispparams.cArgs = 1;
1554 dispparams.rgvarg = vararg;
1555 VariantInit(&varresult);
1556 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1557 ok(hr == DISP_E_PARAMNOTFOUND, "IDispatch_Invoke should have returned DISP_E_PARAMNOTFOUND instead of 0x%08x\n", hr);
1558 VariantClear(&varresult);
1560 /* tests param type that cannot be coerced */
1561 VariantInit(&vararg[0]);
1562 V_VT(&vararg[0]) = VT_UNKNOWN;
1563 V_UNKNOWN(&vararg[0]) = NULL;
1564 dispparams.cNamedArgs = 1;
1565 dispparams.rgdispidNamedArgs = &dispidNamed;
1566 dispparams.cArgs = 1;
1567 dispparams.rgvarg = vararg;
1568 VariantInit(&varresult);
1569 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1570 ok(hr == DISP_E_TYPEMISMATCH, "IDispatch_Invoke should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hr);
1571 VariantClear(&varresult);
1573 /* tests bad param type */
1574 VariantInit(&vararg[0]);
1575 V_VT(&vararg[0]) = VT_CLSID;
1576 V_BYREF(&vararg[0]) = NULL;
1577 dispparams.cNamedArgs = 1;
1578 dispparams.rgdispidNamedArgs = &dispidNamed;
1579 dispparams.cArgs = 1;
1580 dispparams.rgvarg = vararg;
1581 VariantInit(&varresult);
1582 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NAME, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1583 ok(hr == DISP_E_BADVARTYPE, "IDispatch_Invoke should have returned DISP_E_BADVARTYPE instead of 0x%08x\n", hr);
1584 VariantClear(&varresult);
1586 /* tests too small param count */
1587 dispparams.cNamedArgs = 0;
1588 dispparams.rgdispidNamedArgs = NULL;
1589 dispparams.cArgs = 0;
1590 dispparams.rgvarg = NULL;
1591 VariantInit(&varresult);
1592 hr = IDispatch_Invoke(pDispatch, DISPID_TM_DOSOMETHING, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1593 ok(hr == DISP_E_BADPARAMCOUNT, "IDispatch_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr);
1594 VariantClear(&varresult);
1596 /* tests propget function with large param count */
1597 VariantInit(&vararg[0]);
1598 V_VT(&vararg[0]) = VT_BSTR;
1599 V_BSTR(&vararg[0]) = NULL;
1600 V_VT(&vararg[1]) = VT_I4;
1601 V_I4(&vararg[1]) = 1;
1602 dispparams.cNamedArgs = 0;
1603 dispparams.cArgs = 2;
1604 dispparams.rgdispidNamedArgs = NULL;
1605 dispparams.rgvarg = vararg;
1606 hr = IDispatch_Invoke(pDispatch, DISPID_TM_STATE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1607 ok(hr == DISP_E_NOTACOLLECTION, "IDispatch_Invoke should have returned DISP_E_NOTACOLLECTION instead of 0x%08x\n", hr);
1609 /* test propput with lcid */
1611 /* the lcid passed to the function is the first lcid in the typelib header.
1612 Since we don't explicitly set an lcid in the idl, it'll default to US English. */
1613 VariantInit(&vararg[0]);
1614 V_VT(&vararg[0]) = VT_I4;
1615 V_I4(&vararg[0]) = 0xcafe;
1616 dispparams.cNamedArgs = 1;
1617 dispparams.rgdispidNamedArgs = &dispidNamed;
1618 dispparams.cArgs = 1;
1619 dispparams.rgvarg = vararg;
1620 VariantInit(&varresult);
1621 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_WITH_LCID, &IID_NULL, 0x40c, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1622 ok_ole_success(hr, ITypeInfo_Invoke);
1623 VariantClear(&varresult);
1625 /* test propget with lcid */
1626 dispparams.cNamedArgs = 0;
1627 dispparams.cArgs = 0;
1628 dispparams.rgvarg = NULL;
1629 dispparams.rgdispidNamedArgs = NULL;
1630 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_WITH_LCID, &IID_NULL, 0x40c, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1631 ok_ole_success(hr, ITypeInfo_Invoke);
1632 ok(V_VT(&varresult) == VT_I4, "got %x\n", V_VT(&varresult));
1633 ok(V_I4(&varresult) == 0x409, "got %x\n", V_I4(&varresult));
1634 VariantClear(&varresult);
1636 /* test propget of INT value */
1637 dispparams.cNamedArgs = 0;
1638 dispparams.cArgs = 0;
1639 dispparams.rgvarg = NULL;
1640 dispparams.rgdispidNamedArgs = NULL;
1641 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_INT, &IID_NULL, 0x40c, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1642 ok_ole_success(hr, ITypeInfo_Invoke);
1643 ok(V_VT(&varresult) == VT_I4, "got %x\n", V_VT(&varresult));
1644 ok(V_I4(&varresult) == -13, "got %x\n", V_I4(&varresult));
1645 VariantClear(&varresult);
1647 /* test propget of INT value */
1648 dispparams.cNamedArgs = 0;
1649 dispparams.cArgs = 0;
1650 dispparams.rgvarg = NULL;
1651 dispparams.rgdispidNamedArgs = NULL;
1652 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_UINT, &IID_NULL, 0x40c, DISPATCH_PROPERTYGET, &dispparams, &varresult, &excepinfo, NULL);
1653 ok_ole_success(hr, ITypeInfo_Invoke);
1654 ok(V_VT(&varresult) == VT_UI4, "got %x\n", V_VT(&varresult));
1655 ok(V_UI4(&varresult) == 42, "got %x\n", V_UI4(&varresult));
1656 VariantClear(&varresult);
1658 /* test byref marshalling */
1659 uval = 666;
1660 VariantInit(&vararg[0]);
1661 V_VT(&vararg[0]) = VT_UI4|VT_BYREF;
1662 V_UI4REF(&vararg[0]) = &uval;
1663 dispparams.cNamedArgs = 0;
1664 dispparams.cArgs = 1;
1665 dispparams.rgvarg = vararg;
1666 dispparams.rgdispidNamedArgs = NULL;
1667 hr = IDispatch_Invoke(pDispatch, DISPID_TM_BYREF_UINT, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1668 ok_ole_success(hr, ITypeInfo_Invoke);
1669 ok(V_VT(&varresult) == VT_EMPTY, "varresult should be VT_EMPTY\n");
1670 ok(V_VT(&vararg[0]) == (VT_UI4|VT_BYREF), "arg VT not unmarshalled correctly: %x\n", V_VT(&vararg[0]));
1671 ok(V_UI4REF(&vararg[0]) == &uval, "Byref pointer not preserved: %p/%p\n", &uval, V_UI4REF(&vararg[0]));
1672 ok(*V_UI4REF(&vararg[0]) == 42, "Expected 42 to be returned instead of %u\n", *V_UI4REF(&vararg[0]));
1673 VariantClear(&varresult);
1674 VariantClear(&vararg[0]);
1676 /* test propput with optional argument. */
1677 VariantInit(&vararg[0]);
1678 V_VT(&vararg[0]) = VT_I4;
1679 V_I4(&vararg[0]) = 0xcafe;
1680 dispparams.cNamedArgs = 1;
1681 dispparams.rgdispidNamedArgs = &dispidNamed;
1682 dispparams.cArgs = 1;
1683 dispparams.rgvarg = vararg;
1684 VariantInit(&varresult);
1685 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_OPT_ARG, &IID_NULL, 0x40c, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1686 ok_ole_success(hr, ITypeInfo_Invoke);
1687 VariantClear(&varresult);
1689 /* test propput with required argument. */
1690 VariantInit(&vararg[0]);
1691 VariantInit(&vararg[1]);
1692 V_VT(&vararg[0]) = VT_I4;
1693 V_I4(&vararg[0]) = 0x1234;
1694 V_VT(&vararg[1]) = VT_I4;
1695 V_I4(&vararg[1]) = 0x5678;
1696 dispparams.cNamedArgs = 1;
1697 dispparams.rgdispidNamedArgs = &dispidNamed;
1698 dispparams.cArgs = 2;
1699 dispparams.rgvarg = vararg;
1700 VariantInit(&varresult);
1701 hr = IDispatch_Invoke(pDispatch, DISPID_TM_PROP_REQ_ARG, &IID_NULL, 0x40c, DISPATCH_PROPERTYPUT, &dispparams, &varresult, &excepinfo, NULL);
1702 ok_ole_success(hr, ITypeInfo_Invoke);
1703 VariantClear(&varresult);
1705 /* restricted member */
1706 dispparams.cNamedArgs = 0;
1707 dispparams.rgdispidNamedArgs = NULL;
1708 dispparams.cArgs = 0;
1709 dispparams.rgvarg = NULL;
1710 VariantInit(&varresult);
1711 hr = IDispatch_Invoke(pDispatch, DISPID_TM_RESTRICTED, &IID_NULL, 0x40c, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1712 ok( hr == DISP_E_MEMBERNOTFOUND, "got %08x\n", hr );
1713 VariantClear(&varresult);
1715 /* restricted member with -ve memid (not restricted) */
1716 dispparams.cNamedArgs = 0;
1717 dispparams.rgdispidNamedArgs = NULL;
1718 dispparams.cArgs = 0;
1719 dispparams.rgvarg = NULL;
1720 VariantInit(&varresult);
1721 hr = IDispatch_Invoke(pDispatch, DISPID_TM_NEG_RESTRICTED, &IID_NULL, 0x40c, DISPATCH_METHOD, &dispparams, &varresult, &excepinfo, NULL);
1722 ok( hr == S_OK, "got %08x\n", hr );
1723 ok(V_VT(&varresult) == VT_I4, "got %x\n", V_VT(&varresult));
1724 ok(V_I4(&varresult) == DISPID_TM_NEG_RESTRICTED, "got %x\n", V_I4(&varresult));
1725 VariantClear(&varresult);
1727 IDispatch_Release(pDispatch);
1728 IWidget_Release(pWidget);
1730 trace("calling end_host_object\n");
1731 end_host_object(tid, thread);
1734 static void test_DispCallFunc(void)
1736 static const WCHAR szEmpty[] = { 0 };
1737 VARTYPE rgvt[] = { VT_R8, VT_BSTR, VT_BSTR, VT_VARIANT|VT_BYREF };
1738 VARIANTARG vararg[4];
1739 VARIANTARG varref;
1740 VARIANTARG *rgpvarg[4] = { &vararg[0], &vararg[1], &vararg[2], &vararg[3] };
1741 VARIANTARG varresult;
1742 HRESULT hr;
1743 IWidget *pWidget = Widget_Create();
1744 V_VT(&vararg[0]) = VT_R8;
1745 V_R8(&vararg[0]) = 3.141;
1746 V_VT(&vararg[1]) = VT_BSTR;
1747 V_BSTRREF(&vararg[1]) = CoTaskMemAlloc(sizeof(BSTR));
1748 V_VT(&vararg[2]) = VT_BSTR;
1749 V_BSTR(&vararg[2]) = SysAllocString(szEmpty);
1750 V_VT(&vararg[3]) = VT_VARIANT|VT_BYREF;
1751 V_VARIANTREF(&vararg[3]) = &varref;
1752 V_VT(&varref) = VT_ERROR;
1753 V_ERROR(&varref) = DISP_E_PARAMNOTFOUND;
1754 VariantInit(&varresult);
1755 hr = DispCallFunc(pWidget, 9*sizeof(void*), CC_STDCALL, VT_UI4, 4, rgvt, rgpvarg, &varresult);
1756 ok_ole_success(hr, DispCallFunc);
1757 VariantClear(&varresult);
1758 SysFreeString(*V_BSTRREF(&vararg[1]));
1759 CoTaskMemFree(V_BSTRREF(&vararg[1]));
1760 VariantClear(&vararg[2]);
1761 IWidget_Release(pWidget);
1764 static void test_StaticWidget(void)
1766 ITypeInfo *type_info;
1767 DISPPARAMS dispparams;
1768 VARIANTARG vararg[4];
1769 EXCEPINFO excepinfo;
1770 VARIANT varresult;
1771 HRESULT hr;
1773 type_info = get_type_info(&IID_IStaticWidget);
1775 /* call TestDual */
1776 dispparams.cNamedArgs = 0;
1777 dispparams.cArgs = 1;
1778 dispparams.rgdispidNamedArgs = NULL;
1779 dispparams.rgvarg = vararg;
1780 V_VT(vararg) = VT_DISPATCH;
1781 V_DISPATCH(vararg) = (IDispatch*)&TestDualDisp;
1782 VariantInit(&varresult);
1783 hr = ITypeInfo_Invoke(type_info, &StaticWidget, DISPID_TM_TESTDUAL, DISPATCH_METHOD,
1784 &dispparams, &varresult, &excepinfo, NULL);
1785 ok_ole_success(hr, IDispatch_Invoke);
1786 ok(V_VT(&varresult) == VT_EMPTY, "vt %x\n", V_VT(&varresult));
1787 VariantClear(&varresult);
1789 /* call TestSecondIface */
1790 dispparams.cNamedArgs = 0;
1791 dispparams.cArgs = 1;
1792 dispparams.rgdispidNamedArgs = NULL;
1793 dispparams.rgvarg = vararg;
1794 V_VT(vararg) = VT_DISPATCH;
1795 V_DISPATCH(vararg) = (IDispatch*)&TestDualDisp;
1796 VariantInit(&varresult);
1797 hr = ITypeInfo_Invoke(type_info, &StaticWidget, DISPID_TM_TESTSECONDIFACE, DISPATCH_METHOD,
1798 &dispparams, &varresult, &excepinfo, NULL);
1799 ok_ole_success(hr, IDispatch_Invoke);
1800 ok(V_VT(&varresult) == VT_EMPTY, "vt %x\n", V_VT(&varresult));
1801 VariantClear(&varresult);
1803 ITypeInfo_Release(type_info);
1806 static void test_libattr(void)
1808 ITypeLib *pTypeLib;
1809 HRESULT hr;
1810 TLIBATTR *pattr;
1812 hr = LoadRegTypeLib(&LIBID_TestTypelib, 1, 0, LOCALE_NEUTRAL, &pTypeLib);
1813 ok_ole_success(hr, LoadRegTypeLib);
1814 if (FAILED(hr))
1815 return;
1817 hr = ITypeLib_GetLibAttr(pTypeLib, &pattr);
1818 ok_ole_success(hr, GetLibAttr);
1819 if (SUCCEEDED(hr))
1821 ok(pattr->lcid == MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), "lcid %x\n", pattr->lcid);
1823 ITypeLib_ReleaseTLibAttr(pTypeLib, pattr);
1826 ITypeLib_Release(pTypeLib);
1829 static void test_external_connection(void)
1831 IStream *stream, *stream2;
1832 ITestSecondDisp *second;
1833 ItestDual *iface;
1834 HANDLE thread;
1835 DWORD tid;
1836 HRESULT hres;
1838 static const LARGE_INTEGER zero;
1840 trace("Testing IExternalConnection...\n");
1842 external_connections = 0;
1844 /* Marshaling an interface increases external connection count. */
1845 hres = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1846 ok(hres == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hres);
1847 tid = start_host_object(stream, &IID_ItestDual, (IUnknown*)&TestDual, MSHLFLAGS_NORMAL, &thread);
1848 ok(external_connections == 1, "external_connections = %d\n", external_connections);
1850 IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
1851 hres = CoUnmarshalInterface(stream, &IID_ItestDual, (void**)&iface);
1852 ok(hres == S_OK, "CoUnmarshalInterface failed: %08x\n", hres);
1853 ok(external_connections == 1, "external_connections = %d\n", external_connections);
1855 IStream_Release(stream);
1856 ok(external_connections == 1, "external_connections = %d\n", external_connections);
1858 /* Creating a stub for new iface does not cause new external connection. */
1859 hres = ItestDual_QueryInterface(iface, &IID_ITestSecondDisp, (void**)&second);
1860 ok(hres == S_OK, "Could not get ITestSecondDisp iface: %08x\n", hres);
1861 ok(external_connections == 1, "external_connections = %d\n", external_connections);
1863 ITestSecondDisp_Release(second);
1864 ok(external_connections == 1, "external_connections = %d\n", external_connections);
1866 ItestDual_Release(iface);
1867 ok(external_connections == 0, "external_connections = %d\n", external_connections);
1869 end_host_object(tid, thread);
1871 /* A test with direct CoMarshalInterface call. */
1872 hres = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1873 ok(hres == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hres);
1875 hres = CoMarshalInterface(stream, &IID_ItestDual, (IUnknown*)&TestDual, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
1876 ok(hres == S_OK, "CoMarshalInterface failed: %08x\n", hres);
1877 ok(external_connections == 1, "external_connections = %d\n", external_connections);
1879 IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
1880 hres = CoReleaseMarshalData(stream);
1881 ok(hres == S_OK, "CoReleaseMarshalData failed: %08x\n", hres);
1882 ok(external_connections == 0, "external_connections = %d\n", external_connections);
1884 /* Two separated marshal data are still one external connection. */
1885 hres = CreateStreamOnHGlobal(NULL, TRUE, &stream2);
1886 ok(hres == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hres);
1888 IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
1889 hres = CoMarshalInterface(stream, &IID_ItestDual, (IUnknown*)&TestDual, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
1890 ok(hres == S_OK, "CoMarshalInterface failed: %08x\n", hres);
1891 ok(external_connections == 1, "external_connections = %d\n", external_connections);
1893 hres = CoMarshalInterface(stream2, &IID_ItestDual, (IUnknown*)&TestDual, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
1894 ok(hres == S_OK, "CoMarshalInterface failed: %08x\n", hres);
1895 ok(external_connections == 1, "external_connections = %d\n", external_connections);
1897 IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
1898 hres = CoReleaseMarshalData(stream);
1899 ok(hres == S_OK, "CoReleaseMarshalData failed: %08x\n", hres);
1900 ok(external_connections == 1, "external_connections = %d\n", external_connections);
1902 IStream_Seek(stream2, zero, STREAM_SEEK_SET, NULL);
1903 hres = CoReleaseMarshalData(stream2);
1904 ok(hres == S_OK, "CoReleaseMarshalData failed: %08x\n", hres);
1905 ok(external_connections == 0, "external_connections = %d\n", external_connections);
1909 START_TEST(tmarshal)
1911 HRESULT hr;
1912 HANDLE hOleaut32 = GetModuleHandleA("oleaut32.dll");
1913 pVarAdd = (void*)GetProcAddress(hOleaut32, "VarAdd");
1915 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1917 hr = register_current_module_typelib();
1918 if (FAILED(hr))
1920 CoUninitialize();
1921 win_skip("Registration of the test typelib failed, skipping tests\n");
1922 return;
1925 test_typelibmarshal();
1926 test_DispCallFunc();
1927 test_StaticWidget();
1928 test_libattr();
1929 test_external_connection();
1931 hr = UnRegisterTypeLib(&LIBID_TestTypelib, 1, 0, LOCALE_NEUTRAL,
1932 sizeof(void*) == 8 ? SYS_WIN64 : SYS_WIN32);
1933 ok_ole_success(hr, UnRegisterTypeLib);
1935 CoUninitialize();