2 * Copyright (C) 2005-2006 Robert Shearman for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/test.h"
30 #include "tmarshal_dispids.h"
32 static HRESULT (WINAPI
*pVarAdd
)(LPVARIANT
,LPVARIANT
,LPVARIANT
);
35 #define ok_ole_success(hr, func) ok(hr == S_OK, #func " failed with error 0x%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
58 MSHLFLAGS marshal_flags
;
60 IMessageFilter
*filter
;
63 static DWORD CALLBACK
host_object_proc(LPVOID p
)
65 struct host_object_data
*data
= p
;
69 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
73 IMessageFilter
* prev_filter
= NULL
;
74 hr
= CoRegisterMessageFilter(data
->filter
, &prev_filter
);
75 if (prev_filter
) IMessageFilter_Release(prev_filter
);
76 ok_ole_success(hr
, CoRegisterMessageFilter
);
79 hr
= CoMarshalInterface(data
->stream
, &data
->iid
, data
->object
, MSHCTX_INPROC
, NULL
, data
->marshal_flags
);
80 ok_ole_success(hr
, CoMarshalInterface
);
82 /* force the message queue to be created before signaling parent thread */
83 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
);
96 DispatchMessageA(&msg
);
99 HeapFree(GetProcessHeap(), 0, data
);
106 static DWORD
start_host_object2(IStream
*stream
, REFIID riid
, IUnknown
*object
, MSHLFLAGS marshal_flags
, IMessageFilter
*filter
, HANDLE
*thread
)
109 HANDLE marshal_event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
110 struct host_object_data
*data
= HeapAlloc(GetProcessHeap(), 0, sizeof(*data
));
112 data
->stream
= stream
;
114 data
->object
= object
;
115 data
->marshal_flags
= marshal_flags
;
116 data
->marshal_event
= marshal_event
;
117 data
->filter
= filter
;
119 *thread
= CreateThread(NULL
, 0, host_object_proc
, data
, 0, &tid
);
121 /* wait for marshaling to complete before returning */
122 WaitForSingleObject(marshal_event
, INFINITE
);
123 CloseHandle(marshal_event
);
128 static DWORD
start_host_object(IStream
*stream
, REFIID riid
, IUnknown
*object
, MSHLFLAGS marshal_flags
, HANDLE
*thread
)
130 return start_host_object2(stream
, riid
, object
, marshal_flags
, NULL
, thread
);
134 /* asks thread to release the marshal data because it has to be done by the
135 * same thread that marshaled the interface in the first place. */
136 static void release_host_object(DWORD tid
)
138 HANDLE event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
139 PostThreadMessageA(tid
, RELEASEMARSHALDATA
, 0, (LPARAM
)event
);
140 WaitForSingleObject(event
, INFINITE
);
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
);
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");
161 return E_NOINTERFACE
;
164 static ULONG WINAPI
ExternalConnection_AddRef(IExternalConnection
*iface
)
169 static ULONG WINAPI
ExternalConnection_Release(IExternalConnection
*iface
)
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
)
218 static ULONG WINAPI
TestSecondIface_Release(ITestSecondIface
*iface
)
223 static HRESULT WINAPI
TestSecondIface_test(ITestSecondIface
*iface
)
228 static const ITestSecondIfaceVtbl TestSecondIfaceVtbl
= {
229 TestSecondIface_QueryInterface
,
230 TestSecondIface_AddRef
,
231 TestSecondIface_Release
,
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
)
247 static ULONG WINAPI
TestSecondDisp_Release(ITestSecondDisp
*iface
)
252 static HRESULT WINAPI
TestSecondDisp_GetTypeInfoCount(ITestSecondDisp
*iface
, UINT
*pctinfo
)
254 ok(0, "unexpected call\n");
258 static HRESULT WINAPI
TestSecondDisp_GetTypeInfo(ITestSecondDisp
*iface
, UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
260 ok(0, "unexpected call\n");
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");
271 static HRESULT WINAPI
TestSecondDisp_Invoke(ITestSecondDisp
*iface
, DISPID dispIdMember
, REFIID riid
, LCID lcid
,
272 WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
,
275 ok(0, "unexpected call\n");
279 static HRESULT WINAPI
TestSecondDisp_test(ITestSecondDisp
*iface
)
281 ok(0, "unexpected call\n");
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
,
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
;
303 }else if(IsEqualGUID(riid
, &IID_ItestDual
)) {
304 *ppvObject
= &TestDual
;
306 }else if(IsEqualGUID(riid
, &IID_ITestSecondIface
)) {
307 *ppvObject
= &TestSecondIface
;
309 }else if(IsEqualGUID(riid
, &IID_ITestSecondDisp
)) {
310 *ppvObject
= &TestSecondDisp
;
312 }else if (IsEqualGUID(riid
, &IID_IExternalConnection
)) {
313 trace("QI external connection\n");
314 *ppvObject
= &ExternalConnection
;
319 return E_NOINTERFACE
;
322 static ULONG WINAPI
TestDual_AddRef(ItestDual
*iface
)
327 static ULONG WINAPI
TestDual_Release(ItestDual
*iface
)
332 static HRESULT WINAPI
TestDual_GetTypeInfoCount(ItestDual
*iface
, UINT
*pctinfo
)
334 ok(0, "unexpected call\n");
338 static HRESULT WINAPI
TestDual_GetTypeInfo(ItestDual
*iface
, UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
340 ok(0, "unexpected call\n");
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");
351 static HRESULT WINAPI
TestDual_Invoke(ItestDual
*iface
, DISPID dispIdMember
, REFIID riid
, LCID lcid
,
352 WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
,
355 ok(0, "unexpected call\n");
359 static ItestDualVtbl TestDualVtbl
= {
360 TestDual_QueryInterface
,
363 TestDual_GetTypeInfoCount
,
364 TestDual_GetTypeInfo
,
365 TestDual_GetIDsOfNames
,
369 static ItestDual TestDual
= { &TestDualVtbl
};
370 static ItestDual TestDualDisp
= { &TestDualVtbl
};
372 typedef struct Widget
374 IWidget IWidget_iface
;
376 IUnknown
*pDispatchUnknown
;
379 static inline Widget
*impl_from_IWidget(IWidget
*iface
)
381 return CONTAINING_RECORD(iface
, Widget
, IWidget_iface
);
384 static HRESULT WINAPI
Widget_QueryInterface(
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
);
398 return E_NOINTERFACE
;
402 static ULONG WINAPI
Widget_AddRef(
405 Widget
*This
= impl_from_IWidget(iface
);
407 return InterlockedIncrement(&This
->refs
);
410 static ULONG WINAPI
Widget_Release(
413 Widget
*This
= impl_from_IWidget(iface
);
414 ULONG refs
= InterlockedDecrement(&This
->refs
);
417 IUnknown_Release(This
->pDispatchUnknown
);
418 memset(This
, 0xcc, sizeof(*This
));
419 HeapFree(GetProcessHeap(), 0, This
);
420 trace("Widget destroyed!\n");
426 static HRESULT WINAPI
Widget_GetTypeInfoCount(
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
);
435 hr
= IDispatch_GetTypeInfoCount(pDispatch
, pctinfo
);
436 IDispatch_Release(pDispatch
);
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
);
452 hr
= IDispatch_GetTypeInfo(pDispatch
, iTInfo
, lcid
, ppTInfo
);
453 IDispatch_Release(pDispatch
);
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
);
471 hr
= IDispatch_GetIDsOfNames(pDispatch
, riid
, rgszNames
, cNames
, lcid
, rgDispId
);
472 IDispatch_Release(pDispatch
);
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
);
493 hr
= IDispatch_Invoke(pDispatch
, dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
494 IDispatch_Release(pDispatch
);
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
));
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
);
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
);
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
;
545 static HRESULT WINAPI
Widget_put_State(
546 IWidget __RPC_FAR
* iface
,
547 /* [in] */ STATE state
)
549 trace("put_State(%d)\n", state
);
553 static HRESULT WINAPI
Widget_Map(
558 trace("Map(%s, %p)\n", wine_dbgstr_w(bstrId
), sValue
);
559 *sValue
= SysAllocString(bstrId
);
563 static HRESULT WINAPI
Widget_SetOleColor(
567 trace("SetOleColor(0x%x)\n", val
);
571 static HRESULT WINAPI
Widget_GetOleColor(
575 trace("GetOleColor() = 0x8000000f\n");
580 static HRESULT WINAPI
Widget_Clone(
585 return Widget_QueryInterface(iface
, &IID_IWidget
, (void **)ppVal
);
588 static HRESULT WINAPI
Widget_CloneDispatch(
592 trace("CloneDispatch()\n");
593 return Widget_QueryInterface(iface
, &IID_IWidget
, (void **)ppVal
);
596 static HRESULT WINAPI
Widget_CloneCoclass(
598 ApplicationObject2
**ppVal
)
600 trace("CloneCoclass()\n");
601 return Widget_QueryInterface(iface
, &IID_IWidget
, (void **)ppVal
);
604 static HRESULT WINAPI
Widget_Value(
605 IWidget __RPC_FAR
* iface
,
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
;
617 static HRESULT WINAPI
Widget_Array(
621 trace("Array(%p)\n", values
);
625 static HRESULT WINAPI
Widget_VariantArrayPtr(
629 trace("VariantArrayPtr(%p)\n", values
);
633 static HRESULT WINAPI
Widget_VariantCArray(
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
);
653 for (i
= 0; i
< count
; i
++) {
655 hr
= pVarAdd(&values
[i
], &inc
, &res
);
657 ok(0, "VarAdd failed at %u with error 0x%x\n", i
, hr
);
660 hr
= VariantCopy(&values
[i
], &res
);
662 ok(0, "VariantCopy failed at %u with error 0x%x\n", i
, hr
);
668 win_skip("VarAdd is not available\n");
673 static HRESULT WINAPI
Widget_Variant(
674 IWidget __RPC_FAR
* iface
,
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
);
684 static HRESULT WINAPI
Widget_VarArg(
689 LONG lbound
, ubound
, i
;
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
);
719 static BOOL
mystruct_uint_ordered(MYSTRUCT
*mystruct
)
722 for (i
= 0; i
< sizeof(mystruct
->uarr
)/sizeof(mystruct
->uarr
[0]); i
++)
723 if (mystruct
->uarr
[i
] != i
)
728 static HRESULT WINAPI
Widget_StructArgs(
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
]))
748 ok(diff
== 0, "Array of structs corrupted\n");
753 static HRESULT WINAPI
Widget_Error(
754 IWidget __RPC_FAR
* iface
)
760 static HRESULT WINAPI
Widget_CloneInterface(
761 IWidget __RPC_FAR
* iface
,
762 ISomethingFromDispatch
**ppVal
)
764 trace("CloneInterface()\n");
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
);
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
);
787 static HRESULT WINAPI
Widget_get_prop_int(
788 IWidget
* iface
, INT
*i
)
790 trace("get_prop_int(%p)\n", i
);
795 static HRESULT WINAPI
Widget_get_prop_uint(
796 IWidget
* iface
, UINT
*i
)
798 trace("get_prop_uint(%p)\n", i
);
803 static HRESULT WINAPI
Widget_ByRefUInt(
804 IWidget
* iface
, UINT
*i
)
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
);
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
);
828 static HRESULT WINAPI
Widget_pos_restrict(IWidget
* iface
, INT
*i
)
831 *i
= DISPID_TM_RESTRICTED
;
835 static HRESULT WINAPI
Widget_neg_restrict(IWidget
* iface
, INT
*i
)
837 trace("neg_restrict\n");
838 *i
= DISPID_TM_NEG_RESTRICTED
;
842 static HRESULT WINAPI
Widget_VarArg_Run(
843 IWidget
*iface
, BSTR name
, SAFEARRAY
*params
, VARIANT
*result
)
845 static const WCHAR catW
[] = { 'C','a','t',0 };
846 static const WCHAR supermanW
[] = { 'S','u','p','e','r','m','a','n',0 };
852 trace("VarArg_Run(%p,%p,%p)\n", name
, params
, result
);
854 ok(!lstrcmpW(name
, catW
), "got %s\n", wine_dbgstr_w(name
));
856 hr
= SafeArrayGetLBound(params
, 1, &bound
);
857 ok(hr
== S_OK
, "SafeArrayGetLBound error %#x\n", hr
);
858 ok(bound
== 0, "expected 0, got %d\n", bound
);
860 hr
= SafeArrayGetUBound(params
, 1, &bound
);
861 ok(hr
== S_OK
, "SafeArrayGetUBound error %#x\n", hr
);
862 ok(bound
== 0, "expected 0, got %d\n", bound
);
864 hr
= SafeArrayAccessData(params
, (void **)&var
);
865 ok(hr
== S_OK
, "SafeArrayAccessData failed with %x\n", hr
);
867 ok(V_VT(&var
[0]) == VT_BSTR
, "expected VT_BSTR, got %d\n", V_VT(&var
[0]));
868 bstr
= V_BSTR(&var
[0]);
869 ok(!lstrcmpW(bstr
, supermanW
), "got %s\n", wine_dbgstr_w(bstr
));
871 hr
= SafeArrayUnaccessData(params
);
872 ok(hr
== S_OK
, "SafeArrayUnaccessData error %#x\n", hr
);
877 static HRESULT WINAPI
Widget_VarArg_Ref_Run(
878 IWidget
*iface
, BSTR name
, SAFEARRAY
**params
, VARIANT
*result
)
880 static const WCHAR catW
[] = { 'C','a','t',0 };
881 static const WCHAR supermanW
[] = { 'S','u','p','e','r','m','a','n',0 };
887 trace("VarArg_Ref_Run(%p,%p,%p)\n", name
, params
, result
);
889 ok(!lstrcmpW(name
, catW
), "got %s\n", wine_dbgstr_w(name
));
891 hr
= SafeArrayGetLBound(*params
, 1, &bound
);
892 ok(hr
== S_OK
, "SafeArrayGetLBound error %#x\n", hr
);
893 ok(bound
== 0, "expected 0, got %d\n", bound
);
895 hr
= SafeArrayGetUBound(*params
, 1, &bound
);
896 ok(hr
== S_OK
, "SafeArrayGetUBound error %#x\n", hr
);
897 ok(bound
== 0, "expected 0, got %d\n", bound
);
899 hr
= SafeArrayAccessData(*params
, (void **)&var
);
900 ok(hr
== S_OK
, "SafeArrayAccessData error %#x\n", hr
);
902 ok(V_VT(&var
[0]) == VT_BSTR
, "expected VT_BSTR, got %d\n", V_VT(&var
[0]));
903 bstr
= V_BSTR(&var
[0]);
904 ok(!lstrcmpW(bstr
, supermanW
), "got %s\n", wine_dbgstr_w(bstr
));
906 hr
= SafeArrayUnaccessData(*params
);
907 ok(hr
== S_OK
, "SafeArrayUnaccessData error %#x\n", hr
);
912 static HRESULT WINAPI
Widget_Coclass(
913 IWidget
*iface
, ApplicationObject2
*param
)
915 trace("Coclass(%p)\n", param
);
916 ok(param
== (ApplicationObject2
*)iface
, "expected param == %p, got %p\n", iface
, param
);
920 static const struct IWidgetVtbl Widget_VTable
=
922 Widget_QueryInterface
,
925 Widget_GetTypeInfoCount
,
927 Widget_GetIDsOfNames
,
938 Widget_CloneDispatch
,
942 Widget_VariantArrayPtr
,
943 Widget_VariantCArray
,
948 Widget_CloneInterface
,
949 Widget_put_prop_with_lcid
,
950 Widget_get_prop_with_lcid
,
952 Widget_get_prop_uint
,
954 Widget_put_prop_opt_arg
,
955 Widget_put_prop_req_arg
,
959 Widget_VarArg_Ref_Run
,
963 static HRESULT WINAPI
StaticWidget_QueryInterface(IStaticWidget
*iface
, REFIID riid
, void **ppvObject
)
965 if (IsEqualIID(riid
, &IID_IStaticWidget
) || IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDispatch
))
967 IStaticWidget_AddRef(iface
);
973 return E_NOINTERFACE
;
976 static ULONG WINAPI
StaticWidget_AddRef(IStaticWidget
*iface
)
981 static ULONG WINAPI
StaticWidget_Release(IStaticWidget
*iface
)
986 static HRESULT WINAPI
StaticWidget_GetTypeInfoCount(IStaticWidget
*iface
, UINT
*pctinfo
)
988 ok(0, "unexpected call\n");
992 static HRESULT WINAPI
StaticWidget_GetTypeInfo(IStaticWidget
*iface
, UINT iTInfo
, LCID lcid
,
995 ok(0, "unexpected call\n");
999 static HRESULT WINAPI
StaticWidget_GetIDsOfNames(IStaticWidget
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
1000 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1002 ok(0, "unexpected call\n");
1006 static HRESULT WINAPI
StaticWidget_Invoke(IStaticWidget
*iface
, DISPID dispIdMember
, REFIID riid
,
1007 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
,
1010 ok(0, "unexpected call\n");
1014 static HRESULT WINAPI
StaticWidget_TestDual(IStaticWidget
*iface
, ItestDual
*p
)
1016 trace("TestDual()\n");
1017 ok(p
== &TestDual
, "wrong ItestDual\n");
1021 static HRESULT WINAPI
StaticWidget_TestSecondIface(IStaticWidget
*iface
, ITestSecondIface
*p
)
1023 trace("TestSecondIface()\n");
1024 ok(p
== &TestSecondIface
, "wrong ItestSecondIface\n");
1028 static const IStaticWidgetVtbl StaticWidgetVtbl
= {
1029 StaticWidget_QueryInterface
,
1030 StaticWidget_AddRef
,
1031 StaticWidget_Release
,
1032 StaticWidget_GetTypeInfoCount
,
1033 StaticWidget_GetTypeInfo
,
1034 StaticWidget_GetIDsOfNames
,
1035 StaticWidget_Invoke
,
1036 StaticWidget_TestDual
,
1037 StaticWidget_TestSecondIface
1040 static IStaticWidget StaticWidget
= { &StaticWidgetVtbl
};
1042 typedef struct KindaEnum
1044 IKindaEnumWidget IKindaEnumWidget_iface
;
1048 static inline KindaEnum
*impl_from_IKindaEnumWidget(IKindaEnumWidget
*iface
)
1050 return CONTAINING_RECORD(iface
, KindaEnum
, IKindaEnumWidget_iface
);
1053 static HRESULT
register_current_module_typelib(void)
1055 WCHAR path
[MAX_PATH
];
1056 CHAR pathA
[MAX_PATH
];
1060 GetModuleFileNameA(NULL
, pathA
, MAX_PATH
);
1061 MultiByteToWideChar(CP_ACP
, 0, pathA
, -1, path
, MAX_PATH
);
1063 hr
= LoadTypeLib(path
, &typelib
);
1066 hr
= RegisterTypeLib(typelib
, path
, NULL
);
1067 ITypeLib_Release(typelib
);
1072 static ITypeInfo
*get_type_info(REFIID riid
)
1074 ITypeInfo
*pTypeInfo
;
1078 hr
= LoadRegTypeLib(&LIBID_TestTypelib
, 2, 5, LOCALE_NEUTRAL
, &pTypeLib
);
1079 ok_ole_success(hr
, LoadRegTypeLib
);
1083 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, riid
, &pTypeInfo
);
1084 ITypeLib_Release(pTypeLib
);
1085 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
1092 static IWidget
*Widget_Create(void)
1095 ITypeInfo
*pTypeInfo
;
1096 HRESULT hr
= E_FAIL
;
1098 pTypeInfo
= get_type_info(&IID_IWidget
);
1102 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1103 This
->IWidget_iface
.lpVtbl
= &Widget_VTable
;
1105 This
->pDispatchUnknown
= NULL
;
1107 hr
= CreateStdDispatch((IUnknown
*)&This
->IWidget_iface
, This
, pTypeInfo
,
1108 &This
->pDispatchUnknown
);
1109 ok_ole_success(hr
, CreateStdDispatch
);
1110 ITypeInfo_Release(pTypeInfo
);
1113 return &This
->IWidget_iface
;
1116 HeapFree(GetProcessHeap(), 0, This
);
1121 static HRESULT WINAPI
KindaEnum_QueryInterface(
1122 IKindaEnumWidget
*iface
,
1123 /* [in] */ REFIID riid
,
1124 /* [iid_is][out] */ void __RPC_FAR
*__RPC_FAR
*ppvObject
)
1126 if (IsEqualIID(riid
, &IID_IKindaEnumWidget
) || IsEqualIID(riid
, &IID_IUnknown
))
1128 IKindaEnumWidget_AddRef(iface
);
1135 return E_NOINTERFACE
;
1139 static ULONG WINAPI
KindaEnum_AddRef(
1140 IKindaEnumWidget
*iface
)
1142 KindaEnum
*This
= impl_from_IKindaEnumWidget(iface
);
1144 return InterlockedIncrement(&This
->refs
);
1147 static ULONG WINAPI
KindaEnum_Release(
1148 IKindaEnumWidget
*iface
)
1150 KindaEnum
*This
= impl_from_IKindaEnumWidget(iface
);
1151 ULONG refs
= InterlockedDecrement(&This
->refs
);
1154 memset(This
, 0xcc, sizeof(*This
));
1155 HeapFree(GetProcessHeap(), 0, This
);
1156 trace("KindaEnumWidget destroyed!\n");
1162 static HRESULT WINAPI
KindaEnum_Next(
1163 IKindaEnumWidget
*iface
,
1164 /* [out] */ IWidget __RPC_FAR
*__RPC_FAR
*widget
)
1166 *widget
= Widget_Create();
1170 return E_OUTOFMEMORY
;
1173 static HRESULT WINAPI
KindaEnum_Count(
1174 IKindaEnumWidget
*iface
,
1175 /* [out] */ ULONG __RPC_FAR
*count
)
1180 static HRESULT WINAPI
KindaEnum_Reset(
1181 IKindaEnumWidget
*iface
)
1186 static HRESULT WINAPI
KindaEnum_Clone(
1187 IKindaEnumWidget
*iface
,
1188 /* [out] */ IKindaEnumWidget __RPC_FAR
*__RPC_FAR
*ppenum
)
1193 static const IKindaEnumWidgetVtbl KindaEnumWidget_VTable
=
1195 KindaEnum_QueryInterface
,
1204 static IKindaEnumWidget
*KindaEnumWidget_Create(void)
1208 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1209 if (!This
) return NULL
;
1210 This
->IKindaEnumWidget_iface
.lpVtbl
= &KindaEnumWidget_VTable
;
1212 return &This
->IKindaEnumWidget_iface
;
1215 static HRESULT WINAPI
NonOleAutomation_QueryInterface(INonOleAutomation
*iface
, REFIID riid
, void **ppv
)
1217 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_INonOleAutomation
))
1219 *(INonOleAutomation
**)ppv
= iface
;
1223 return E_NOINTERFACE
;
1226 static ULONG WINAPI
NonOleAutomation_AddRef(INonOleAutomation
*iface
)
1231 static ULONG WINAPI
NonOleAutomation_Release(INonOleAutomation
*iface
)
1236 static BSTR WINAPI
NonOleAutomation_BstrRet(INonOleAutomation
*iface
)
1238 static const WCHAR wszTestString
[] = {'T','h','i','s',' ','i','s',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0};
1239 return SysAllocString(wszTestString
);
1242 static HRESULT WINAPI
NonOleAutomation_Error(INonOleAutomation
*iface
)
1247 static INonOleAutomationVtbl NonOleAutomation_VTable
=
1249 NonOleAutomation_QueryInterface
,
1250 NonOleAutomation_AddRef
,
1251 NonOleAutomation_Release
,
1252 NonOleAutomation_BstrRet
,
1253 NonOleAutomation_Error
1256 static INonOleAutomation NonOleAutomation
= { &NonOleAutomation_VTable
};
1258 static ITypeInfo
*NonOleAutomation_GetTypeInfo(void)
1261 HRESULT hr
= LoadRegTypeLib(&LIBID_TestTypelib
, 2, 5, LOCALE_NEUTRAL
, &pTypeLib
);
1262 ok_ole_success(hr
, LoadRegTypeLib
);
1265 ITypeInfo
*pTypeInfo
;
1266 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, &IID_INonOleAutomation
, &pTypeInfo
);
1267 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
1268 ITypeLib_Release(pTypeLib
);
1274 static void test_typelibmarshal(void)
1276 static const WCHAR szCat
[] = { 'C','a','t',0 };
1277 static const WCHAR szTestTest
[] = { 'T','e','s','t','T','e','s','t',0 };
1278 static const WCHAR szSuperman
[] = { 'S','u','p','e','r','m','a','n',0 };
1280 IKindaEnumWidget
*pKEW
= KindaEnumWidget_Create();
1283 IDispatch
*pDispatch
;
1284 static const LARGE_INTEGER ullZero
;
1285 EXCEPINFO excepinfo
;
1287 DISPID dispidNamed
= DISPID_PROPERTYPUT
;
1288 DISPPARAMS dispparams
;
1289 VARIANTARG vararg
[4];
1294 ITypeInfo
*pTypeInfo
;
1296 MYSTRUCT mystructArray
[5];
1299 ok(pKEW
!= NULL
, "Widget creation failed\n");
1301 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
1302 ok_ole_success(hr
, CreateStreamOnHGlobal
);
1303 tid
= start_host_object(pStream
, &IID_IKindaEnumWidget
, (IUnknown
*)pKEW
, MSHLFLAGS_NORMAL
, &thread
);
1304 IKindaEnumWidget_Release(pKEW
);
1306 IStream_Seek(pStream
, ullZero
, STREAM_SEEK_SET
, NULL
);
1307 hr
= CoUnmarshalInterface(pStream
, &IID_IKindaEnumWidget
, (void **)&pKEW
);
1308 ok_ole_success(hr
, CoUnmarshalInterface
);
1309 IStream_Release(pStream
);
1311 hr
= IKindaEnumWidget_Next(pKEW
, &pWidget
);
1312 ok_ole_success(hr
, IKindaEnumWidget_Next
);
1314 IKindaEnumWidget_Release(pKEW
);
1316 /* call GetTypeInfoCount (direct) */
1317 hr
= IWidget_GetTypeInfoCount(pWidget
, &uval
);
1318 ok_ole_success(hr
, IWidget_GetTypeInfoCount
);
1319 hr
= IWidget_GetTypeInfoCount(pWidget
, &uval
);
1320 ok_ole_success(hr
, IWidget_GetTypeInfoCount
);
1322 hr
= IWidget_QueryInterface(pWidget
, &IID_IDispatch
, (void **)&pDispatch
);
1323 ok_ole_success(hr
, IWidget_QueryInterface
);
1326 VariantInit(&vararg
[0]);
1327 dispparams
.cNamedArgs
= 1;
1328 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1329 dispparams
.cArgs
= 1;
1330 dispparams
.rgvarg
= vararg
;
1331 VariantInit(&varresult
);
1332 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1333 ok_ole_success(hr
, IDispatch_Invoke
);
1334 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1335 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1336 excepinfo
.wCode
, excepinfo
.scode
);
1337 VariantClear(&varresult
);
1339 /* call put_Name (direct) */
1340 bstr
= SysAllocString(szSuperman
);
1341 hr
= IWidget_put_Name(pWidget
, bstr
);
1342 ok_ole_success(hr
, IWidget_put_Name
);
1343 SysFreeString(bstr
);
1346 dispparams
.cNamedArgs
= 0;
1347 dispparams
.rgdispidNamedArgs
= NULL
;
1348 dispparams
.cArgs
= 0;
1349 dispparams
.rgvarg
= NULL
;
1350 VariantInit(&varresult
);
1351 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1352 ok_ole_success(hr
, IDispatch_Invoke
);
1353 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1354 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1355 excepinfo
.wCode
, excepinfo
.scode
);
1356 trace("Name = %s\n", wine_dbgstr_w(V_BSTR(&varresult
)));
1357 VariantClear(&varresult
);
1359 /* call get_Name (direct) */
1360 bstr
= (void *)0xdeadbeef;
1361 hr
= IWidget_get_Name(pWidget
, &bstr
);
1362 ok_ole_success(hr
, IWidget_get_Name
);
1363 ok(!lstrcmpW(bstr
, szCat
), "IWidget_get_Name should have returned string \"Cat\" instead of %s\n", wine_dbgstr_w(bstr
));
1364 SysFreeString(bstr
);
1366 /* call DoSomething */
1367 VariantInit(&vararg
[0]);
1368 VariantInit(&vararg
[1]);
1369 V_VT(&vararg
[1]) = VT_R8
;
1370 V_R8(&vararg
[1]) = 3.141;
1371 dispparams
.cNamedArgs
= 0;
1372 dispparams
.cArgs
= 2;
1373 dispparams
.rgdispidNamedArgs
= NULL
;
1374 dispparams
.rgvarg
= vararg
;
1375 VariantInit(&varresult
);
1376 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_DOSOMETHING
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1377 ok_ole_success(hr
, IDispatch_Invoke
);
1378 ok(V_VT(&varresult
) == VT_EMPTY
, "varresult should be VT_EMPTY\n");
1379 VariantClear(&varresult
);
1381 /* call get_State */
1382 dispparams
.cNamedArgs
= 0;
1383 dispparams
.cArgs
= 0;
1384 dispparams
.rgdispidNamedArgs
= NULL
;
1385 dispparams
.rgvarg
= NULL
;
1386 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_STATE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1387 ok_ole_success(hr
, IDispatch_Invoke
);
1388 ok((V_VT(&varresult
) == VT_I4
) && (V_I4(&varresult
) == STATE_WIDGETIFIED
), "Return val mismatch\n");
1390 /* call get_State (direct) */
1391 hr
= IWidget_get_State(pWidget
, &the_state
);
1392 ok_ole_success(hr
, IWidget_get_state
);
1393 ok(the_state
== STATE_WIDGETIFIED
, "should have returned WIDGET_WIDGETIFIED instead of %d\n", the_state
);
1395 /* call put_State */
1396 the_state
= STATE_WIDGETIFIED
;
1397 VariantInit(&vararg
[0]);
1398 V_VT(&vararg
[0]) = VT_BYREF
|VT_I4
;
1399 V_I4REF(&vararg
[0]) = (int *)&the_state
;
1400 dispparams
.cNamedArgs
= 1;
1401 dispparams
.cArgs
= 1;
1402 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1403 dispparams
.rgvarg
= vararg
;
1404 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_STATE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1405 ok_ole_success(hr
, IDispatch_Invoke
);
1408 bstr
= SysAllocString(szTestTest
);
1409 VariantInit(&vararg
[0]);
1410 V_VT(&vararg
[0]) = VT_BYREF
|VT_BSTR
;
1411 V_BSTRREF(&vararg
[0]) = &bstr
;
1412 dispparams
.cNamedArgs
= 0;
1413 dispparams
.cArgs
= 1;
1414 dispparams
.rgdispidNamedArgs
= NULL
;
1415 dispparams
.rgvarg
= vararg
;
1416 VariantInit(&varresult
);
1417 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_MAP
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1418 ok_ole_success(hr
, IDispatch_Invoke
);
1419 ok(V_VT(&varresult
) == VT_BSTR
, "Return value should be of type BSTR instead of %d\n", V_VT(&varresult
));
1420 ok(!lstrcmpW(V_BSTR(&varresult
), szTestTest
), "Return value should have been \"TestTest\" instead of %s\n", wine_dbgstr_w(V_BSTR(&varresult
)));
1421 VariantClear(&varresult
);
1422 SysFreeString(bstr
);
1424 /* call SetOleColor with large negative VT_I4 param */
1425 VariantInit(&vararg
[0]);
1426 V_VT(&vararg
[0]) = VT_I4
;
1427 V_I4(&vararg
[0]) = 0x80000005;
1428 dispparams
.cNamedArgs
= 0;
1429 dispparams
.cArgs
= 1;
1430 dispparams
.rgdispidNamedArgs
= NULL
;
1431 dispparams
.rgvarg
= vararg
;
1432 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_SETOLECOLOR
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, &excepinfo
, NULL
);
1433 ok_ole_success(hr
, IDispatch_Invoke
);
1435 /* call GetOleColor */
1436 dispparams
.cNamedArgs
= 0;
1437 dispparams
.cArgs
= 0;
1438 dispparams
.rgdispidNamedArgs
= NULL
;
1439 dispparams
.rgvarg
= NULL
;
1440 VariantInit(&varresult
);
1441 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_GETOLECOLOR
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1442 ok_ole_success(hr
, IDispatch_Invoke
);
1443 VariantClear(&varresult
);
1445 /* call StructArgs (direct) */
1446 mystruct
= MYSTRUCT_BYPTR
;
1447 memcpy(mystructArray
, MYSTRUCT_ARRAY
, sizeof(mystructArray
));
1448 hr
= IWidget_StructArgs(pWidget
, MYSTRUCT_BYVAL
, &mystruct
, mystructArray
);
1449 ok_ole_success(hr
, IWidget_StructArgs
);
1452 dispparams
.cNamedArgs
= 0;
1453 dispparams
.cArgs
= 0;
1454 dispparams
.rgdispidNamedArgs
= NULL
;
1455 dispparams
.rgvarg
= NULL
;
1456 VariantInit(&varresult
);
1457 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1458 ok_ole_success(hr
, IDispatch_Invoke
);
1459 ok(V_VT(&varresult
) == VT_DISPATCH
, "vt %x\n", V_VT(&varresult
));
1460 VariantClear(&varresult
);
1462 /* call CloneInterface */
1463 dispparams
.cNamedArgs
= 0;
1464 dispparams
.cArgs
= 0;
1465 dispparams
.rgdispidNamedArgs
= NULL
;
1466 dispparams
.rgvarg
= NULL
;
1467 VariantInit(&varresult
);
1468 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONEINTERFACE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1469 ok_ole_success(hr
, IDispatch_Invoke
);
1470 ok(V_VT(&varresult
) == VT_DISPATCH
, "vt %x\n", V_VT(&varresult
));
1471 VariantClear(&varresult
);
1473 /* call CloneDispatch with automatic value getting */
1474 V_VT(&vararg
[0]) = VT_I2
;
1475 V_I2(&vararg
[0]) = 1;
1476 dispparams
.cNamedArgs
= 0;
1477 dispparams
.rgdispidNamedArgs
= NULL
;
1478 dispparams
.cArgs
= 1;
1479 dispparams
.rgvarg
= vararg
;
1480 VariantInit(&varresult
);
1481 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONEDISPATCH
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1482 ok_ole_success(hr
, IDispatch_Invoke
);
1484 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1485 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1486 excepinfo
.wCode
, excepinfo
.scode
);
1488 ok(V_VT(&varresult
) == VT_I2
, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult
));
1489 ok(V_I2(&varresult
) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult
));
1490 VariantClear(&varresult
);
1492 /* call CloneCoclass */
1493 dispparams
.cNamedArgs
= 0;
1494 dispparams
.cArgs
= 0;
1495 dispparams
.rgdispidNamedArgs
= NULL
;
1496 dispparams
.rgvarg
= NULL
;
1497 VariantInit(&varresult
);
1498 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONECOCLASS
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1499 ok_ole_success(hr
, IDispatch_Invoke
);
1501 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1502 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1503 excepinfo
.wCode
, excepinfo
.scode
);
1505 ok(V_VT(&varresult
) == VT_DISPATCH
, "V_VT(&varresult) was %d instead of VT_DISPATCH\n", V_VT(&varresult
));
1506 ok(V_DISPATCH(&varresult
) != NULL
, "expected V_DISPATCH(&varresult) != NULL\n");
1508 /* call Coclass with VT_DISPATCH type */
1509 vararg
[0] = varresult
;
1510 dispparams
.cNamedArgs
= 0;
1511 dispparams
.rgdispidNamedArgs
= NULL
;
1512 dispparams
.cArgs
= 1;
1513 dispparams
.rgvarg
= vararg
;
1514 VariantInit(&varresult
);
1515 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_COCLASS
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1516 todo_wine
ok_ole_success(hr
, IDispatch_Invoke
);
1517 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1518 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1519 excepinfo
.wCode
, excepinfo
.scode
);
1520 VariantClear(&varresult
);
1521 VariantClear(&vararg
[0]);
1523 /* call Value with a VT_VARIANT|VT_BYREF type */
1524 V_VT(&vararg
[0]) = VT_VARIANT
|VT_BYREF
;
1525 V_VARIANTREF(&vararg
[0]) = &vararg
[1];
1526 V_VT(&vararg
[1]) = VT_I2
;
1527 V_I2(&vararg
[1]) = 1;
1528 dispparams
.cNamedArgs
= 0;
1529 dispparams
.rgdispidNamedArgs
= NULL
;
1530 dispparams
.cArgs
= 1;
1531 dispparams
.rgvarg
= vararg
;
1532 VariantInit(&varresult
);
1533 hr
= IDispatch_Invoke(pDispatch
, DISPID_VALUE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1534 ok_ole_success(hr
, IDispatch_Invoke
);
1536 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1537 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1538 excepinfo
.wCode
, excepinfo
.scode
);
1540 ok(V_VT(&varresult
) == VT_I2
, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult
));
1541 ok(V_I2(&varresult
) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult
));
1542 VariantClear(&varresult
);
1544 /* call Variant - exercises variant copying in ITypeInfo::Invoke and
1545 * handling of void return types */
1546 /* use a big type to ensure that the variant was properly copied into the
1547 * destination function's args */
1548 V_VT(&vararg
[0]) = VT_CY
;
1549 S(V_CY(&vararg
[0])).Hi
= 0xdababe;
1550 S(V_CY(&vararg
[0])).Lo
= 0xdeadbeef;
1551 dispparams
.cNamedArgs
= 0;
1552 dispparams
.cArgs
= 1;
1553 dispparams
.rgdispidNamedArgs
= NULL
;
1554 dispparams
.rgvarg
= vararg
;
1555 VariantInit(&varresult
);
1556 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARIANT
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1557 ok_ole_success(hr
, IDispatch_Invoke
);
1558 VariantClear(&varresult
);
1560 /* call Array with BSTR argument - type mismatch */
1561 VariantInit(&vararg
[0]);
1562 V_VT(&vararg
[0]) = VT_BSTR
;
1563 V_BSTR(&vararg
[0]) = SysAllocString(szSuperman
);
1564 dispparams
.cNamedArgs
= 0;
1565 dispparams
.cArgs
= 1;
1566 dispparams
.rgdispidNamedArgs
= NULL
;
1567 dispparams
.rgvarg
= vararg
;
1568 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_ARRAY
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1569 ok(hr
== DISP_E_TYPEMISMATCH
|| hr
== DISP_E_BADVARTYPE
, "expected DISP_E_TYPEMISMATCH, got %#x\n", hr
);
1570 SysFreeString(V_BSTR(&vararg
[0]));
1572 /* call ArrayPtr with BSTR argument - type mismatch */
1573 VariantInit(&vararg
[0]);
1574 V_VT(&vararg
[0]) = VT_BSTR
;
1575 V_BSTR(&vararg
[0]) = SysAllocString(szSuperman
);
1576 dispparams
.cNamedArgs
= 0;
1577 dispparams
.cArgs
= 1;
1578 dispparams
.rgdispidNamedArgs
= NULL
;
1579 dispparams
.rgvarg
= vararg
;
1580 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARARRAYPTR
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1581 ok(hr
== DISP_E_TYPEMISMATCH
|| hr
== DISP_E_BADVARTYPE
, "expected DISP_E_TYPEMISMATCH, got %#x\n", hr
);
1582 SysFreeString(V_BSTR(&vararg
[0]));
1584 /* call VariantCArray - test marshaling of variant arrays */
1585 V_VT(&vararg
[0]) = VT_I4
;
1586 V_I4(&vararg
[0]) = 1;
1587 V_VT(&vararg
[1]) = VT_I4
;
1588 V_I4(&vararg
[1]) = 2;
1589 hr
= IWidget_VariantCArray(pWidget
, 2, vararg
);
1590 ok_ole_success(hr
, IWidget_VariantCArray
);
1592 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]));
1594 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]));
1597 VariantInit(&vararg
[3]);
1598 V_VT(&vararg
[3]) = VT_I4
;
1599 V_I4(&vararg
[3]) = 3;
1600 VariantInit(&vararg
[2]);
1601 V_VT(&vararg
[2]) = VT_I4
;
1602 V_I4(&vararg
[2]) = 0;
1603 VariantInit(&vararg
[1]);
1604 V_VT(&vararg
[1]) = VT_I4
;
1605 V_I4(&vararg
[1]) = 1;
1606 VariantInit(&vararg
[0]);
1607 V_VT(&vararg
[0]) = VT_I4
;
1608 V_I4(&vararg
[0]) = 2;
1609 dispparams
.cNamedArgs
= 0;
1610 dispparams
.cArgs
= 4;
1611 dispparams
.rgdispidNamedArgs
= NULL
;
1612 dispparams
.rgvarg
= vararg
;
1613 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARARG
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1614 ok_ole_success(hr
, IDispatch_Invoke
);
1616 /* call VarArg, even one (non-optional, non-safearray) named argument is not allowed */
1618 dispparams
.cNamedArgs
= 1;
1619 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1620 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARARG
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1621 ok(hr
== DISP_E_NONAMEDARGS
, "IDispatch_Invoke should have returned DISP_E_NONAMEDARGS instead of 0x%08x\n", hr
);
1622 dispidNamed
= DISPID_PROPERTYPUT
;
1624 /* call VarArg_Run */
1625 VariantInit(&vararg
[1]);
1626 V_VT(&vararg
[1]) = VT_BSTR
;
1627 V_BSTR(&vararg
[1]) = SysAllocString(szCat
);
1628 VariantInit(&vararg
[0]);
1629 V_VT(&vararg
[0]) = VT_BSTR
;
1630 V_BSTR(&vararg
[0]) = SysAllocString(szSuperman
);
1631 dispparams
.cNamedArgs
= 0;
1632 dispparams
.cArgs
= 2;
1633 dispparams
.rgdispidNamedArgs
= NULL
;
1634 dispparams
.rgvarg
= vararg
;
1635 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARARG_RUN
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1636 ok_ole_success(hr
, IDispatch_Invoke
);
1637 SysFreeString(V_BSTR(&vararg
[1]));
1638 SysFreeString(V_BSTR(&vararg
[0]));
1640 /* call VarArg_Ref_Run */
1641 VariantInit(&vararg
[1]);
1642 V_VT(&vararg
[1]) = VT_BSTR
;
1643 V_BSTR(&vararg
[1]) = SysAllocString(szCat
);
1644 VariantInit(&vararg
[0]);
1645 V_VT(&vararg
[0]) = VT_BSTR
;
1646 V_BSTR(&vararg
[0]) = SysAllocString(szSuperman
);
1647 dispparams
.cNamedArgs
= 0;
1648 dispparams
.cArgs
= 2;
1649 dispparams
.rgdispidNamedArgs
= NULL
;
1650 dispparams
.rgvarg
= vararg
;
1651 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARARG_REF_RUN
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1652 ok_ole_success(hr
, IDispatch_Invoke
);
1653 SysFreeString(V_BSTR(&vararg
[1]));
1654 SysFreeString(V_BSTR(&vararg
[0]));
1657 dispparams
.cNamedArgs
= 0;
1658 dispparams
.cArgs
= 0;
1659 dispparams
.rgdispidNamedArgs
= NULL
;
1660 dispparams
.rgvarg
= NULL
;
1661 VariantInit(&varresult
);
1662 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_ERROR
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, &excepinfo
, NULL
);
1663 ok(hr
== DISP_E_EXCEPTION
, "IDispatch_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr
);
1664 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== E_NOTIMPL
,
1665 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1666 excepinfo
.wCode
, excepinfo
.scode
);
1667 VariantClear(&varresult
);
1670 pTypeInfo
= NonOleAutomation_GetTypeInfo();
1671 dispparams
.cNamedArgs
= 0;
1672 dispparams
.cArgs
= 0;
1673 dispparams
.rgdispidNamedArgs
= NULL
;
1674 dispparams
.rgvarg
= NULL
;
1675 VariantInit(&varresult
);
1676 hr
= ITypeInfo_Invoke(pTypeInfo
, &NonOleAutomation
, DISPID_NOA_BSTRRET
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1677 ok_ole_success(hr
, ITypeInfo_Invoke
);
1678 ok(V_VT(&varresult
) == VT_BSTR
, "V_VT(&varresult) should be VT_BSTR instead of %d\n", V_VT(&varresult
));
1679 ok(V_BSTR(&varresult
) != NULL
, "V_BSTR(&varresult) should not be NULL\n");
1681 VariantClear(&varresult
);
1683 dispparams
.cNamedArgs
= 0;
1684 dispparams
.cArgs
= 0;
1685 dispparams
.rgdispidNamedArgs
= NULL
;
1686 dispparams
.rgvarg
= NULL
;
1687 hr
= ITypeInfo_Invoke(pTypeInfo
, &NonOleAutomation
, DISPID_NOA_ERROR
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1688 ok(hr
== DISP_E_EXCEPTION
, "ITypeInfo_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr
);
1689 ok(V_VT(&varresult
) == VT_EMPTY
, "V_VT(&varresult) should be VT_EMPTY instead of %d\n", V_VT(&varresult
));
1690 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== E_NOTIMPL
,
1691 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1692 excepinfo
.wCode
, excepinfo
.scode
);
1693 VariantClear(&varresult
);
1695 ITypeInfo_Release(pTypeInfo
);
1697 /* tests call put_Name without named arg */
1698 VariantInit(&vararg
[0]);
1699 dispparams
.cNamedArgs
= 0;
1700 dispparams
.rgdispidNamedArgs
= NULL
;
1701 dispparams
.cArgs
= 1;
1702 dispparams
.rgvarg
= vararg
;
1703 VariantInit(&varresult
);
1704 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1705 ok(hr
== DISP_E_PARAMNOTFOUND
, "IDispatch_Invoke should have returned DISP_E_PARAMNOTFOUND instead of 0x%08x\n", hr
);
1706 VariantClear(&varresult
);
1708 /* tests param type that cannot be coerced */
1709 VariantInit(&vararg
[0]);
1710 V_VT(&vararg
[0]) = VT_UNKNOWN
;
1711 V_UNKNOWN(&vararg
[0]) = NULL
;
1712 dispparams
.cNamedArgs
= 1;
1713 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1714 dispparams
.cArgs
= 1;
1715 dispparams
.rgvarg
= vararg
;
1716 VariantInit(&varresult
);
1717 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1718 ok(hr
== DISP_E_TYPEMISMATCH
, "IDispatch_Invoke should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hr
);
1719 VariantClear(&varresult
);
1721 /* tests bad param type */
1722 VariantInit(&vararg
[0]);
1723 V_VT(&vararg
[0]) = VT_CLSID
;
1724 V_BYREF(&vararg
[0]) = NULL
;
1725 dispparams
.cNamedArgs
= 1;
1726 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1727 dispparams
.cArgs
= 1;
1728 dispparams
.rgvarg
= vararg
;
1729 VariantInit(&varresult
);
1730 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1731 ok(hr
== DISP_E_BADVARTYPE
, "IDispatch_Invoke should have returned DISP_E_BADVARTYPE instead of 0x%08x\n", hr
);
1732 VariantClear(&varresult
);
1734 /* tests too small param count */
1735 dispparams
.cNamedArgs
= 0;
1736 dispparams
.rgdispidNamedArgs
= NULL
;
1737 dispparams
.cArgs
= 0;
1738 dispparams
.rgvarg
= NULL
;
1739 VariantInit(&varresult
);
1740 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_DOSOMETHING
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1741 ok(hr
== DISP_E_BADPARAMCOUNT
, "IDispatch_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr
);
1742 VariantClear(&varresult
);
1744 /* tests propget function with large param count */
1745 VariantInit(&vararg
[0]);
1746 V_VT(&vararg
[0]) = VT_BSTR
;
1747 V_BSTR(&vararg
[0]) = NULL
;
1748 V_VT(&vararg
[1]) = VT_I4
;
1749 V_I4(&vararg
[1]) = 1;
1750 dispparams
.cNamedArgs
= 0;
1751 dispparams
.cArgs
= 2;
1752 dispparams
.rgdispidNamedArgs
= NULL
;
1753 dispparams
.rgvarg
= vararg
;
1754 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_STATE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1755 ok(hr
== DISP_E_NOTACOLLECTION
, "IDispatch_Invoke should have returned DISP_E_NOTACOLLECTION instead of 0x%08x\n", hr
);
1757 /* test propput with lcid */
1759 /* the lcid passed to the function is the first lcid in the typelib header.
1760 Since we don't explicitly set an lcid in the idl, it'll default to US English. */
1761 VariantInit(&vararg
[0]);
1762 V_VT(&vararg
[0]) = VT_I4
;
1763 V_I4(&vararg
[0]) = 0xcafe;
1764 dispparams
.cNamedArgs
= 1;
1765 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1766 dispparams
.cArgs
= 1;
1767 dispparams
.rgvarg
= vararg
;
1768 VariantInit(&varresult
);
1769 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_WITH_LCID
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1770 ok_ole_success(hr
, ITypeInfo_Invoke
);
1771 VariantClear(&varresult
);
1773 /* test propget with lcid */
1774 dispparams
.cNamedArgs
= 0;
1775 dispparams
.cArgs
= 0;
1776 dispparams
.rgvarg
= NULL
;
1777 dispparams
.rgdispidNamedArgs
= NULL
;
1778 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_WITH_LCID
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1779 ok_ole_success(hr
, ITypeInfo_Invoke
);
1780 ok(V_VT(&varresult
) == VT_I4
, "got %x\n", V_VT(&varresult
));
1781 ok(V_I4(&varresult
) == 0x409, "got %x\n", V_I4(&varresult
));
1782 VariantClear(&varresult
);
1784 /* test propget of INT value */
1785 dispparams
.cNamedArgs
= 0;
1786 dispparams
.cArgs
= 0;
1787 dispparams
.rgvarg
= NULL
;
1788 dispparams
.rgdispidNamedArgs
= NULL
;
1789 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_INT
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1790 ok_ole_success(hr
, ITypeInfo_Invoke
);
1791 ok(V_VT(&varresult
) == VT_I4
, "got %x\n", V_VT(&varresult
));
1792 ok(V_I4(&varresult
) == -13, "got %x\n", V_I4(&varresult
));
1793 VariantClear(&varresult
);
1795 /* test propget of INT value */
1796 dispparams
.cNamedArgs
= 0;
1797 dispparams
.cArgs
= 0;
1798 dispparams
.rgvarg
= NULL
;
1799 dispparams
.rgdispidNamedArgs
= NULL
;
1800 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_UINT
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1801 ok_ole_success(hr
, ITypeInfo_Invoke
);
1802 ok(V_VT(&varresult
) == VT_UI4
, "got %x\n", V_VT(&varresult
));
1803 ok(V_UI4(&varresult
) == 42, "got %x\n", V_UI4(&varresult
));
1804 VariantClear(&varresult
);
1806 /* test byref marshalling */
1808 VariantInit(&vararg
[0]);
1809 V_VT(&vararg
[0]) = VT_UI4
|VT_BYREF
;
1810 V_UI4REF(&vararg
[0]) = &uval
;
1811 dispparams
.cNamedArgs
= 0;
1812 dispparams
.cArgs
= 1;
1813 dispparams
.rgvarg
= vararg
;
1814 dispparams
.rgdispidNamedArgs
= NULL
;
1815 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_BYREF_UINT
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1816 ok_ole_success(hr
, ITypeInfo_Invoke
);
1817 ok(V_VT(&varresult
) == VT_EMPTY
, "varresult should be VT_EMPTY\n");
1818 ok(V_VT(&vararg
[0]) == (VT_UI4
|VT_BYREF
), "arg VT not unmarshalled correctly: %x\n", V_VT(&vararg
[0]));
1819 ok(V_UI4REF(&vararg
[0]) == &uval
, "Byref pointer not preserved: %p/%p\n", &uval
, V_UI4REF(&vararg
[0]));
1820 ok(*V_UI4REF(&vararg
[0]) == 42, "Expected 42 to be returned instead of %u\n", *V_UI4REF(&vararg
[0]));
1821 VariantClear(&varresult
);
1822 VariantClear(&vararg
[0]);
1824 /* test propput with optional argument. */
1825 VariantInit(&vararg
[0]);
1826 V_VT(&vararg
[0]) = VT_I4
;
1827 V_I4(&vararg
[0]) = 0xcafe;
1828 dispparams
.cNamedArgs
= 1;
1829 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1830 dispparams
.cArgs
= 1;
1831 dispparams
.rgvarg
= vararg
;
1832 VariantInit(&varresult
);
1833 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_OPT_ARG
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1834 ok_ole_success(hr
, ITypeInfo_Invoke
);
1835 VariantClear(&varresult
);
1837 /* test propput with required argument. */
1838 VariantInit(&vararg
[0]);
1839 VariantInit(&vararg
[1]);
1840 V_VT(&vararg
[0]) = VT_I4
;
1841 V_I4(&vararg
[0]) = 0x1234;
1842 V_VT(&vararg
[1]) = VT_I4
;
1843 V_I4(&vararg
[1]) = 0x5678;
1844 dispparams
.cNamedArgs
= 1;
1845 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1846 dispparams
.cArgs
= 2;
1847 dispparams
.rgvarg
= vararg
;
1848 VariantInit(&varresult
);
1849 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_REQ_ARG
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1850 ok_ole_success(hr
, ITypeInfo_Invoke
);
1851 VariantClear(&varresult
);
1853 /* restricted member */
1854 dispparams
.cNamedArgs
= 0;
1855 dispparams
.rgdispidNamedArgs
= NULL
;
1856 dispparams
.cArgs
= 0;
1857 dispparams
.rgvarg
= NULL
;
1858 VariantInit(&varresult
);
1859 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_RESTRICTED
, &IID_NULL
, 0x40c, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1860 ok( hr
== DISP_E_MEMBERNOTFOUND
, "got %08x\n", hr
);
1861 VariantClear(&varresult
);
1863 /* restricted member with -ve memid (not restricted) */
1864 dispparams
.cNamedArgs
= 0;
1865 dispparams
.rgdispidNamedArgs
= NULL
;
1866 dispparams
.cArgs
= 0;
1867 dispparams
.rgvarg
= NULL
;
1868 VariantInit(&varresult
);
1869 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NEG_RESTRICTED
, &IID_NULL
, 0x40c, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1870 ok( hr
== S_OK
, "got %08x\n", hr
);
1871 ok(V_VT(&varresult
) == VT_I4
, "got %x\n", V_VT(&varresult
));
1872 ok(V_I4(&varresult
) == DISPID_TM_NEG_RESTRICTED
, "got %x\n", V_I4(&varresult
));
1873 VariantClear(&varresult
);
1875 IDispatch_Release(pDispatch
);
1876 IWidget_Release(pWidget
);
1878 trace("calling end_host_object\n");
1879 end_host_object(tid
, thread
);
1882 static void test_DispCallFunc(void)
1884 static const WCHAR szEmpty
[] = { 0 };
1885 VARTYPE rgvt
[] = { VT_R8
, VT_BSTR
, VT_BSTR
, VT_VARIANT
|VT_BYREF
};
1886 VARIANTARG vararg
[4];
1888 VARIANTARG
*rgpvarg
[4] = { &vararg
[0], &vararg
[1], &vararg
[2], &vararg
[3] };
1889 VARIANTARG varresult
;
1891 IWidget
*pWidget
= Widget_Create();
1892 V_VT(&vararg
[0]) = VT_R8
;
1893 V_R8(&vararg
[0]) = 3.141;
1894 V_VT(&vararg
[1]) = VT_BSTR
;
1895 V_BSTRREF(&vararg
[1]) = CoTaskMemAlloc(sizeof(BSTR
));
1896 V_VT(&vararg
[2]) = VT_BSTR
;
1897 V_BSTR(&vararg
[2]) = SysAllocString(szEmpty
);
1898 V_VT(&vararg
[3]) = VT_VARIANT
|VT_BYREF
;
1899 V_VARIANTREF(&vararg
[3]) = &varref
;
1900 V_VT(&varref
) = VT_ERROR
;
1901 V_ERROR(&varref
) = DISP_E_PARAMNOTFOUND
;
1902 VariantInit(&varresult
);
1903 hr
= DispCallFunc(pWidget
, 9*sizeof(void*), CC_STDCALL
, VT_UI4
, 4, rgvt
, rgpvarg
, &varresult
);
1904 ok_ole_success(hr
, DispCallFunc
);
1905 VariantClear(&varresult
);
1906 SysFreeString(*V_BSTRREF(&vararg
[1]));
1907 CoTaskMemFree(V_BSTRREF(&vararg
[1]));
1908 VariantClear(&vararg
[2]);
1909 IWidget_Release(pWidget
);
1912 static void test_StaticWidget(void)
1914 ITypeInfo
*type_info
;
1915 DISPPARAMS dispparams
;
1916 VARIANTARG vararg
[4];
1917 EXCEPINFO excepinfo
;
1921 type_info
= get_type_info(&IID_IStaticWidget
);
1924 dispparams
.cNamedArgs
= 0;
1925 dispparams
.cArgs
= 1;
1926 dispparams
.rgdispidNamedArgs
= NULL
;
1927 dispparams
.rgvarg
= vararg
;
1928 V_VT(vararg
) = VT_DISPATCH
;
1929 V_DISPATCH(vararg
) = (IDispatch
*)&TestDualDisp
;
1930 VariantInit(&varresult
);
1931 hr
= ITypeInfo_Invoke(type_info
, &StaticWidget
, DISPID_TM_TESTDUAL
, DISPATCH_METHOD
,
1932 &dispparams
, &varresult
, &excepinfo
, NULL
);
1933 ok_ole_success(hr
, IDispatch_Invoke
);
1934 ok(V_VT(&varresult
) == VT_EMPTY
, "vt %x\n", V_VT(&varresult
));
1935 VariantClear(&varresult
);
1937 /* call TestSecondIface */
1938 dispparams
.cNamedArgs
= 0;
1939 dispparams
.cArgs
= 1;
1940 dispparams
.rgdispidNamedArgs
= NULL
;
1941 dispparams
.rgvarg
= vararg
;
1942 V_VT(vararg
) = VT_DISPATCH
;
1943 V_DISPATCH(vararg
) = (IDispatch
*)&TestDualDisp
;
1944 VariantInit(&varresult
);
1945 hr
= ITypeInfo_Invoke(type_info
, &StaticWidget
, DISPID_TM_TESTSECONDIFACE
, DISPATCH_METHOD
,
1946 &dispparams
, &varresult
, &excepinfo
, NULL
);
1947 ok_ole_success(hr
, IDispatch_Invoke
);
1948 ok(V_VT(&varresult
) == VT_EMPTY
, "vt %x\n", V_VT(&varresult
));
1949 VariantClear(&varresult
);
1951 ITypeInfo_Release(type_info
);
1954 static void test_libattr(void)
1960 hr
= LoadRegTypeLib(&LIBID_TestTypelib
, 2, 5, LOCALE_NEUTRAL
, &pTypeLib
);
1961 ok_ole_success(hr
, LoadRegTypeLib
);
1965 hr
= ITypeLib_GetLibAttr(pTypeLib
, &pattr
);
1966 ok_ole_success(hr
, GetLibAttr
);
1969 ok(pattr
->lcid
== MAKELANGID(LANG_NEUTRAL
, SUBLANG_NEUTRAL
), "lcid %x\n", pattr
->lcid
);
1971 ITypeLib_ReleaseTLibAttr(pTypeLib
, pattr
);
1974 ITypeLib_Release(pTypeLib
);
1977 static void test_external_connection(void)
1979 IStream
*stream
, *stream2
;
1980 ITestSecondDisp
*second
;
1986 static const LARGE_INTEGER zero
;
1988 trace("Testing IExternalConnection...\n");
1990 external_connections
= 0;
1992 /* Marshaling an interface increases external connection count. */
1993 expect_last_release_closes
= FALSE
;
1994 hres
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
1995 ok(hres
== S_OK
, "CreateStreamOnHGlobal failed: %08x\n", hres
);
1996 tid
= start_host_object(stream
, &IID_ItestDual
, (IUnknown
*)&TestDual
, MSHLFLAGS_NORMAL
, &thread
);
1997 ok(external_connections
== 1, "external_connections = %d\n", external_connections
);
1999 IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
2000 hres
= CoUnmarshalInterface(stream
, &IID_ItestDual
, (void**)&iface
);
2001 ok(hres
== S_OK
, "CoUnmarshalInterface failed: %08x\n", hres
);
2002 ok(external_connections
== 1, "external_connections = %d\n", external_connections
);
2004 IStream_Release(stream
);
2005 ok(external_connections
== 1, "external_connections = %d\n", external_connections
);
2007 /* Creating a stub for new iface causes new external connection. */
2008 hres
= ItestDual_QueryInterface(iface
, &IID_ITestSecondDisp
, (void**)&second
);
2009 ok(hres
== S_OK
, "Could not get ITestSecondDisp iface: %08x\n", hres
);
2011 ok(external_connections
== 2, "external_connections = %d\n", external_connections
);
2013 ITestSecondDisp_Release(second
);
2015 ok(external_connections
== 2, "external_connections = %d\n", external_connections
);
2017 expect_last_release_closes
= TRUE
;
2018 ItestDual_Release(iface
);
2019 ok(external_connections
== 0, "external_connections = %d\n", external_connections
);
2021 end_host_object(tid
, thread
);
2023 /* A test with direct CoMarshalInterface call. */
2024 hres
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
2025 ok(hres
== S_OK
, "CreateStreamOnHGlobal failed: %08x\n", hres
);
2027 expect_last_release_closes
= FALSE
;
2028 hres
= CoMarshalInterface(stream
, &IID_ItestDual
, (IUnknown
*)&TestDual
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
2029 ok(hres
== S_OK
, "CoMarshalInterface failed: %08x\n", hres
);
2030 ok(external_connections
== 1, "external_connections = %d\n", external_connections
);
2032 expect_last_release_closes
= TRUE
;
2033 IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
2034 hres
= CoReleaseMarshalData(stream
);
2035 ok(hres
== S_OK
, "CoReleaseMarshalData failed: %08x\n", hres
);
2036 ok(external_connections
== 0, "external_connections = %d\n", external_connections
);
2038 /* Two separated marshal data are still one external connection. */
2039 hres
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream2
);
2040 ok(hres
== S_OK
, "CreateStreamOnHGlobal failed: %08x\n", hres
);
2042 expect_last_release_closes
= FALSE
;
2043 IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
2044 hres
= CoMarshalInterface(stream
, &IID_ItestDual
, (IUnknown
*)&TestDual
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
2045 ok(hres
== S_OK
, "CoMarshalInterface failed: %08x\n", hres
);
2046 ok(external_connections
== 1, "external_connections = %d\n", external_connections
);
2048 hres
= CoMarshalInterface(stream2
, &IID_ItestDual
, (IUnknown
*)&TestDual
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
2049 ok(hres
== S_OK
, "CoMarshalInterface failed: %08x\n", hres
);
2050 ok(external_connections
== 1, "external_connections = %d\n", external_connections
);
2052 IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
2053 hres
= CoReleaseMarshalData(stream
);
2054 ok(hres
== S_OK
, "CoReleaseMarshalData failed: %08x\n", hres
);
2055 ok(external_connections
== 1, "external_connections = %d\n", external_connections
);
2057 expect_last_release_closes
= TRUE
;
2058 IStream_Seek(stream2
, zero
, STREAM_SEEK_SET
, NULL
);
2059 hres
= CoReleaseMarshalData(stream2
);
2060 ok(hres
== S_OK
, "CoReleaseMarshalData failed: %08x\n", hres
);
2061 ok(external_connections
== 0, "external_connections = %d\n", external_connections
);
2063 IStream_Release(stream
);
2064 IStream_Release(stream2
);
2066 /* Weak table marshaling does not increment external connections */
2067 hres
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
2068 ok(hres
== S_OK
, "CreateStreamOnHGlobal failed: %08x\n", hres
);
2070 hres
= CoMarshalInterface(stream
, &IID_ItestDual
, (IUnknown
*)&TestDual
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_TABLEWEAK
);
2071 ok(hres
== S_OK
, "CoMarshalInterface failed: %08x\n", hres
);
2072 ok(external_connections
== 0, "external_connections = %d\n", external_connections
);
2074 IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
2075 hres
= CoUnmarshalInterface(stream
, &IID_ItestDual
, (void**)&iface
);
2076 ok(hres
== S_OK
, "CoUnmarshalInterface failed: %08x\n", hres
);
2077 ok(external_connections
== 0, "external_connections = %d\n", external_connections
);
2078 ItestDual_Release(iface
);
2080 IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
2081 hres
= CoReleaseMarshalData(stream
);
2082 ok(hres
== S_OK
, "CoReleaseMarshalData failed: %08x\n", hres
);
2083 ok(external_connections
== 0, "external_connections = %d\n", external_connections
);
2085 IStream_Release(stream
);
2088 START_TEST(tmarshal
)
2091 HANDLE hOleaut32
= GetModuleHandleA("oleaut32.dll");
2092 pVarAdd
= (void*)GetProcAddress(hOleaut32
, "VarAdd");
2094 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2096 hr
= register_current_module_typelib();
2100 win_skip("Registration of the test typelib failed, skipping tests\n");
2104 test_typelibmarshal();
2105 test_DispCallFunc();
2106 test_StaticWidget();
2108 test_external_connection();
2110 hr
= UnRegisterTypeLib(&LIBID_TestTypelib
, 2, 5, LOCALE_NEUTRAL
,
2111 sizeof(void*) == 8 ? SYS_WIN64
: SYS_WIN32
);
2112 ok_ole_success(hr
, UnRegisterTypeLib
);