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%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
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 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
);
96 DispatchMessage(&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
= CreateEvent(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
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
139 PostThreadMessage(tid
, RELEASEMARSHALDATA
, 0, (LPARAM
)event
);
140 WaitForSingleObject(event
, INFINITE
);
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
);
154 static ItestDual TestDual
, TestDualDisp
;
156 static HRESULT WINAPI
TestDual_QueryInterface(ItestDual
*iface
, REFIID riid
, void **ppvObject
)
158 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDispatch
)) {
159 *ppvObject
= &TestDualDisp
;
161 }else if(IsEqualGUID(riid
, &IID_ItestDual
)) {
162 *ppvObject
= &TestDual
;
167 return E_NOINTERFACE
;
170 static ULONG WINAPI
TestDual_AddRef(ItestDual
*iface
)
175 static ULONG WINAPI
TestDual_Release(ItestDual
*iface
)
180 static HRESULT WINAPI
TestDual_GetTypeInfoCount(ItestDual
*iface
, UINT
*pctinfo
)
182 ok(0, "unexpected call\n");
186 static HRESULT WINAPI
TestDual_GetTypeInfo(ItestDual
*iface
, UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
188 ok(0, "unexpected call\n");
192 static HRESULT WINAPI
TestDual_GetIDsOfNames(ItestDual
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
193 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
195 ok(0, "unexpected call\n");
199 static HRESULT WINAPI
TestDual_Invoke(ItestDual
*iface
, DISPID dispIdMember
, REFIID riid
, LCID lcid
,
200 WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
,
203 ok(0, "unexpected call\n");
207 static ItestDualVtbl TestDualVtbl
= {
208 TestDual_QueryInterface
,
211 TestDual_GetTypeInfoCount
,
212 TestDual_GetTypeInfo
,
213 TestDual_GetIDsOfNames
,
217 static ItestDual TestDual
= { &TestDualVtbl
};
218 static ItestDual TestDualDisp
= { &TestDualVtbl
};
220 typedef struct Widget
222 IWidget IWidget_iface
;
224 IUnknown
*pDispatchUnknown
;
227 static inline Widget
*impl_from_IWidget(IWidget
*iface
)
229 return CONTAINING_RECORD(iface
, Widget
, IWidget_iface
);
232 static HRESULT WINAPI
Widget_QueryInterface(
234 /* [in] */ REFIID riid
,
235 /* [iid_is][out] */ void __RPC_FAR
*__RPC_FAR
*ppvObject
)
237 if (IsEqualIID(riid
, &IID_IWidget
) || IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDispatch
))
239 IWidget_AddRef(iface
);
246 return E_NOINTERFACE
;
250 static ULONG WINAPI
Widget_AddRef(
253 Widget
*This
= impl_from_IWidget(iface
);
255 return InterlockedIncrement(&This
->refs
);
258 static ULONG WINAPI
Widget_Release(
261 Widget
*This
= impl_from_IWidget(iface
);
262 ULONG refs
= InterlockedDecrement(&This
->refs
);
265 IUnknown_Release(This
->pDispatchUnknown
);
266 memset(This
, 0xcc, sizeof(*This
));
267 HeapFree(GetProcessHeap(), 0, This
);
268 trace("Widget destroyed!\n");
274 static HRESULT WINAPI
Widget_GetTypeInfoCount(
276 /* [out] */ UINT __RPC_FAR
*pctinfo
)
278 Widget
*This
= impl_from_IWidget(iface
);
279 IDispatch
*pDispatch
;
280 HRESULT hr
= IUnknown_QueryInterface(This
->pDispatchUnknown
, &IID_IDispatch
, (void **)&pDispatch
);
283 hr
= IDispatch_GetTypeInfoCount(pDispatch
, pctinfo
);
284 IDispatch_Release(pDispatch
);
289 static HRESULT WINAPI
Widget_GetTypeInfo(
290 IWidget __RPC_FAR
* iface
,
291 /* [in] */ UINT iTInfo
,
292 /* [in] */ LCID lcid
,
293 /* [out] */ ITypeInfo __RPC_FAR
*__RPC_FAR
*ppTInfo
)
295 Widget
*This
= impl_from_IWidget(iface
);
296 IDispatch
*pDispatch
;
297 HRESULT hr
= IUnknown_QueryInterface(This
->pDispatchUnknown
, &IID_IDispatch
, (void **)&pDispatch
);
300 hr
= IDispatch_GetTypeInfo(pDispatch
, iTInfo
, lcid
, ppTInfo
);
301 IDispatch_Release(pDispatch
);
306 static HRESULT WINAPI
Widget_GetIDsOfNames(
307 IWidget __RPC_FAR
* iface
,
308 /* [in] */ REFIID riid
,
309 /* [size_is][in] */ LPOLESTR __RPC_FAR
*rgszNames
,
310 /* [in] */ UINT cNames
,
311 /* [in] */ LCID lcid
,
312 /* [size_is][out] */ DISPID __RPC_FAR
*rgDispId
)
314 Widget
*This
= impl_from_IWidget(iface
);
315 IDispatch
*pDispatch
;
316 HRESULT hr
= IUnknown_QueryInterface(This
->pDispatchUnknown
, &IID_IDispatch
, (void **)&pDispatch
);
319 hr
= IDispatch_GetIDsOfNames(pDispatch
, riid
, rgszNames
, cNames
, lcid
, rgDispId
);
320 IDispatch_Release(pDispatch
);
325 static HRESULT WINAPI
Widget_Invoke(
326 IWidget __RPC_FAR
* iface
,
327 /* [in] */ DISPID dispIdMember
,
328 /* [in] */ REFIID riid
,
329 /* [in] */ LCID lcid
,
330 /* [in] */ WORD wFlags
,
331 /* [out][in] */ DISPPARAMS __RPC_FAR
*pDispParams
,
332 /* [out] */ VARIANT __RPC_FAR
*pVarResult
,
333 /* [out] */ EXCEPINFO __RPC_FAR
*pExcepInfo
,
334 /* [out] */ UINT __RPC_FAR
*puArgErr
)
336 Widget
*This
= impl_from_IWidget(iface
);
337 IDispatch
*pDispatch
;
338 HRESULT hr
= IUnknown_QueryInterface(This
->pDispatchUnknown
, &IID_IDispatch
, (void **)&pDispatch
);
341 hr
= IDispatch_Invoke(pDispatch
, dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
342 IDispatch_Release(pDispatch
);
347 static HRESULT WINAPI
Widget_put_Name(
348 IWidget __RPC_FAR
* iface
,
349 /* [in] */ BSTR name
)
351 trace("put_Name(%s)\n", wine_dbgstr_w(name
));
355 static HRESULT WINAPI
Widget_get_Name(
356 IWidget __RPC_FAR
* iface
,
357 /* [out] */ BSTR __RPC_FAR
*name
)
359 static const WCHAR szCat
[] = { 'C','a','t',0 };
360 trace("get_Name()\n");
361 *name
= SysAllocString(szCat
);
365 static HRESULT WINAPI
Widget_DoSomething(
366 IWidget __RPC_FAR
* iface
,
367 /* [in] */ double number
,
368 /* [out] */ BSTR
*str1
,
369 /* [defaultvalue][in] */ BSTR str2
,
370 /* [optional][in] */ VARIANT __RPC_FAR
*opt
)
372 static const WCHAR szString
[] = { 'S','t','r','i','n','g',0 };
373 trace("DoSomething()\n");
375 ok(number
== 3.141, "number(%f) != 3.141\n", number
);
376 ok(*str2
== '\0', "str2(%s) != \"\"\n", wine_dbgstr_w(str2
));
377 ok(V_VT(opt
) == VT_ERROR
, "V_VT(opt) should be VT_ERROR instead of 0x%x\n", V_VT(opt
));
378 ok(V_ERROR(opt
) == DISP_E_PARAMNOTFOUND
, "V_ERROR(opt) should be DISP_E_PARAMNOTFOUND instead of 0x%08x\n", V_ERROR(opt
));
379 *str1
= SysAllocString(szString
);
384 static HRESULT WINAPI
Widget_get_State(
385 IWidget __RPC_FAR
* iface
,
386 /* [retval][out] */ STATE __RPC_FAR
*state
)
388 trace("get_State() = STATE_WIDGETIFIED\n");
389 *state
= STATE_WIDGETIFIED
;
393 static HRESULT WINAPI
Widget_put_State(
394 IWidget __RPC_FAR
* iface
,
395 /* [in] */ STATE state
)
397 trace("put_State(%d)\n", state
);
401 static HRESULT WINAPI
Widget_Map(
406 trace("Map(%s, %p)\n", wine_dbgstr_w(bstrId
), sValue
);
407 *sValue
= SysAllocString(bstrId
);
411 static HRESULT WINAPI
Widget_SetOleColor(
415 trace("SetOleColor(0x%x)\n", val
);
419 static HRESULT WINAPI
Widget_GetOleColor(
423 trace("GetOleColor() = 0x8000000f\n");
428 static HRESULT WINAPI
Widget_Clone(
433 return Widget_QueryInterface(iface
, &IID_IWidget
, (void **)ppVal
);
436 static HRESULT WINAPI
Widget_CloneDispatch(
440 trace("CloneDispatch()\n");
441 return Widget_QueryInterface(iface
, &IID_IWidget
, (void **)ppVal
);
444 static HRESULT WINAPI
Widget_CloneCoclass(
446 ApplicationObject2
**ppVal
)
448 trace("CloneCoclass()\n");
452 static HRESULT WINAPI
Widget_Value(
453 IWidget __RPC_FAR
* iface
,
457 trace("Value(%p, %p)\n", value
, retval
);
458 ok(V_VT(value
) == VT_I2
, "V_VT(value) was %d instead of VT_I2\n", V_VT(value
));
459 ok(V_I2(value
) == 1, "V_I2(value) was %d instead of 1\n", V_I2(value
));
460 V_VT(retval
) = VT_I2
;
465 static HRESULT WINAPI
Widget_Array(
469 trace("Array(%p)\n", values
);
473 static HRESULT WINAPI
Widget_VariantArrayPtr(
477 trace("VariantArrayPtr(%p)\n", values
);
481 static HRESULT WINAPI
Widget_VariantCArray(
488 trace("VariantCArray(%u,%p)\n", count
, values
);
490 ok(count
== 2, "count is %d\n", count
);
491 for (i
= 0; i
< count
; i
++)
492 ok(V_VT(&values
[i
]) == VT_I4
, "values[%d] is not VT_I4\n", i
);
501 for (i
= 0; i
< count
; i
++) {
503 hr
= pVarAdd(&values
[i
], &inc
, &res
);
505 ok(0, "VarAdd failed at %u with error 0x%x\n", i
, hr
);
508 hr
= VariantCopy(&values
[i
], &res
);
510 ok(0, "VariantCopy failed at %u with error 0x%x\n", i
, hr
);
516 win_skip("VarAdd is not available\n");
521 static HRESULT WINAPI
Widget_Variant(
522 IWidget __RPC_FAR
* iface
,
525 trace("Variant()\n");
526 ok(V_VT(&var
) == VT_CY
, "V_VT(&var) was %d\n", V_VT(&var
));
527 ok(S(V_CY(&var
)).Hi
== 0xdababe, "V_CY(&var).Hi was 0x%x\n", S(V_CY(&var
)).Hi
);
528 ok(S(V_CY(&var
)).Lo
== 0xdeadbeef, "V_CY(&var).Lo was 0x%x\n", S(V_CY(&var
)).Lo
);
532 static HRESULT WINAPI
Widget_VarArg(
537 LONG lbound
, ubound
, i
;
541 trace("VarArg(%p)\n", values
);
543 hr
= SafeArrayGetLBound(values
, 1, &lbound
);
544 ok(hr
== S_OK
, "SafeArrayGetLBound failed with %x\n", hr
);
545 ok(lbound
== 0, "SafeArrayGetLBound returned %d\n", lbound
);
547 hr
= SafeArrayGetUBound(values
, 1, &ubound
);
548 ok(hr
== S_OK
, "SafeArrayGetUBound failed with %x\n", hr
);
549 ok(ubound
== numexpect
-1, "SafeArrayGetUBound returned %d, but expected %d\n", ubound
, numexpect
-1);
551 hr
= SafeArrayAccessData(values
, (LPVOID
)&data
);
552 ok(hr
== S_OK
, "SafeArrayAccessData failed with %x\n", hr
);
554 for (i
=0; i
<=ubound
-lbound
; i
++)
556 ok(V_VT(&data
[i
]) == VT_I4
, "V_VT(&data[%d]) was %d\n", i
, V_VT(&data
[i
]));
557 ok(V_I4(&data
[i
]) == i
, "V_I4(&data[%d]) was %d\n", i
, V_I4(&data
[i
]));
560 hr
= SafeArrayUnaccessData(values
);
561 ok(hr
== S_OK
, "SafeArrayUnaccessData failed with %x\n", hr
);
567 static BOOL
mystruct_uint_ordered(UINT uarr
[8])
570 for (i
= 0; i
< sizeof(uarr
) / sizeof(uarr
[0]); i
++)
577 static HRESULT WINAPI
Widget_StructArgs(
584 ok(byval
.field1
== MYSTRUCT_BYVAL
.field1
&&
585 byval
.field2
== MYSTRUCT_BYVAL
.field2
&&
586 mystruct_uint_ordered(byval
.uarr
),
587 "Struct parameter passed by value corrupted\n");
588 ok(byptr
->field1
== MYSTRUCT_BYPTR
.field1
&&
589 byptr
->field2
== MYSTRUCT_BYPTR
.field2
&&
590 mystruct_uint_ordered(byptr
->uarr
),
591 "Struct parameter passed by pointer corrupted\n");
592 for (i
= 0; i
< 5; i
++)
593 if (arr
[i
].field1
!= MYSTRUCT_ARRAY
[i
].field1
||
594 arr
[i
].field2
!= MYSTRUCT_ARRAY
[i
].field2
||
595 ! mystruct_uint_ordered(arr
[i
].uarr
))
597 ok(diff
== 0, "Array of structs corrupted\n");
602 static HRESULT WINAPI
Widget_Error(
603 IWidget __RPC_FAR
* iface
)
609 static HRESULT WINAPI
Widget_CloneInterface(
610 IWidget __RPC_FAR
* iface
,
611 ISomethingFromDispatch
**ppVal
)
613 trace("CloneInterface()\n");
618 static HRESULT WINAPI
Widget_put_prop_with_lcid(
619 IWidget
* iface
, LONG lcid
, INT i
)
621 trace("put_prop_with_lcid(%08x, %x)\n", lcid
, i
);
622 ok(lcid
== MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), "got lcid %08x\n", lcid
);
623 ok(i
== 0xcafe, "got %08x\n", i
);
627 static HRESULT WINAPI
Widget_get_prop_with_lcid(
628 IWidget
* iface
, LONG lcid
, INT
*i
)
630 trace("get_prop_with_lcid(%08x, %p)\n", lcid
, i
);
631 ok(lcid
== MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), "got lcid %08x\n", lcid
);
636 static HRESULT WINAPI
Widget_get_prop_int(
637 IWidget
* iface
, INT
*i
)
639 trace("get_prop_int(%p)\n", i
);
644 static HRESULT WINAPI
Widget_get_prop_uint(
645 IWidget
* iface
, UINT
*i
)
647 trace("get_prop_uint(%p)\n", i
);
652 static HRESULT WINAPI
Widget_ByRefUInt(
653 IWidget
* iface
, UINT
*i
)
659 static HRESULT WINAPI
Widget_put_prop_opt_arg(
660 IWidget
* iface
, INT opt
, INT i
)
662 trace("put_prop_opt_arg(%08x, %08x)\n", opt
, i
);
663 todo_wine
ok(opt
== 0, "got opt=%08x\n", opt
);
664 ok(i
== 0xcafe, "got i=%08x\n", i
);
668 static HRESULT WINAPI
Widget_put_prop_req_arg(
669 IWidget
* iface
, INT req
, INT i
)
671 trace("put_prop_req_arg(%08x, %08x)\n", req
, i
);
672 ok(req
== 0x5678, "got req=%08x\n", req
);
673 ok(i
== 0x1234, "got i=%08x\n", i
);
677 static HRESULT WINAPI
Widget_restrict(IWidget
* iface
, INT
*i
)
680 *i
= DISPID_TM_RESTRICTED
;
684 static HRESULT WINAPI
Widget_neg_restrict(IWidget
* iface
, INT
*i
)
686 trace("neg_restrict\n");
687 *i
= DISPID_TM_NEG_RESTRICTED
;
691 static const struct IWidgetVtbl Widget_VTable
=
693 Widget_QueryInterface
,
696 Widget_GetTypeInfoCount
,
698 Widget_GetIDsOfNames
,
709 Widget_CloneDispatch
,
713 Widget_VariantArrayPtr
,
714 Widget_VariantCArray
,
719 Widget_CloneInterface
,
720 Widget_put_prop_with_lcid
,
721 Widget_get_prop_with_lcid
,
723 Widget_get_prop_uint
,
725 Widget_put_prop_opt_arg
,
726 Widget_put_prop_req_arg
,
731 static HRESULT WINAPI
StaticWidget_QueryInterface(IStaticWidget
*iface
, REFIID riid
, void **ppvObject
)
733 if (IsEqualIID(riid
, &IID_IStaticWidget
) || IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IDispatch
))
735 IStaticWidget_AddRef(iface
);
741 return E_NOINTERFACE
;
744 static ULONG WINAPI
StaticWidget_AddRef(IStaticWidget
*iface
)
749 static ULONG WINAPI
StaticWidget_Release(IStaticWidget
*iface
)
754 static HRESULT WINAPI
StaticWidget_GetTypeInfoCount(IStaticWidget
*iface
, UINT
*pctinfo
)
756 ok(0, "unexpected call\n");
760 static HRESULT WINAPI
StaticWidget_GetTypeInfo(IStaticWidget
*iface
, UINT iTInfo
, LCID lcid
,
763 ok(0, "unexpected call\n");
767 static HRESULT WINAPI
StaticWidget_GetIDsOfNames(IStaticWidget
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
768 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
770 ok(0, "unexpected call\n");
774 static HRESULT WINAPI
StaticWidget_Invoke(IStaticWidget
*iface
, DISPID dispIdMember
, REFIID riid
,
775 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
,
778 ok(0, "unexpected call\n");
782 static HRESULT WINAPI
StaticWidget_TestDual(IStaticWidget
*iface
, ItestDual
*p
)
784 trace("TestDual()\n");
786 ok(p
== &TestDual
, "wrong ItestDual\n");
790 static const IStaticWidgetVtbl StaticWidgetVtbl
= {
791 StaticWidget_QueryInterface
,
793 StaticWidget_Release
,
794 StaticWidget_GetTypeInfoCount
,
795 StaticWidget_GetTypeInfo
,
796 StaticWidget_GetIDsOfNames
,
798 StaticWidget_TestDual
801 static IStaticWidget StaticWidget
= { &StaticWidgetVtbl
};
803 typedef struct KindaEnum
805 IKindaEnumWidget IKindaEnumWidget_iface
;
809 static inline KindaEnum
*impl_from_IKindaEnumWidget(IKindaEnumWidget
*iface
)
811 return CONTAINING_RECORD(iface
, KindaEnum
, IKindaEnumWidget_iface
);
814 static HRESULT
register_current_module_typelib(void)
816 WCHAR path
[MAX_PATH
];
817 CHAR pathA
[MAX_PATH
];
821 GetModuleFileNameA(NULL
, pathA
, MAX_PATH
);
822 MultiByteToWideChar(CP_ACP
, 0, pathA
, -1, path
, MAX_PATH
);
824 hr
= LoadTypeLib(path
, &typelib
);
827 hr
= RegisterTypeLib(typelib
, path
, NULL
);
828 ITypeLib_Release(typelib
);
833 static ITypeInfo
*get_type_info(REFIID riid
)
835 ITypeInfo
*pTypeInfo
;
839 hr
= LoadRegTypeLib(&LIBID_TestTypelib
, 1, 0, LOCALE_NEUTRAL
, &pTypeLib
);
840 ok_ole_success(hr
, LoadRegTypeLib
);
844 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, riid
, &pTypeInfo
);
845 ITypeLib_Release(pTypeLib
);
846 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
853 static IWidget
*Widget_Create(void)
856 ITypeInfo
*pTypeInfo
;
859 pTypeInfo
= get_type_info(&IID_IWidget
);
863 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
864 This
->IWidget_iface
.lpVtbl
= &Widget_VTable
;
866 This
->pDispatchUnknown
= NULL
;
868 hr
= CreateStdDispatch((IUnknown
*)&This
->IWidget_iface
, This
, pTypeInfo
,
869 &This
->pDispatchUnknown
);
870 ok_ole_success(hr
, CreateStdDispatch
);
871 ITypeInfo_Release(pTypeInfo
);
874 return &This
->IWidget_iface
;
877 HeapFree(GetProcessHeap(), 0, This
);
882 static HRESULT WINAPI
KindaEnum_QueryInterface(
883 IKindaEnumWidget
*iface
,
884 /* [in] */ REFIID riid
,
885 /* [iid_is][out] */ void __RPC_FAR
*__RPC_FAR
*ppvObject
)
887 if (IsEqualIID(riid
, &IID_IKindaEnumWidget
) || IsEqualIID(riid
, &IID_IUnknown
))
889 IKindaEnumWidget_AddRef(iface
);
896 return E_NOINTERFACE
;
900 static ULONG WINAPI
KindaEnum_AddRef(
901 IKindaEnumWidget
*iface
)
903 KindaEnum
*This
= impl_from_IKindaEnumWidget(iface
);
905 return InterlockedIncrement(&This
->refs
);
908 static ULONG WINAPI
KindaEnum_Release(
909 IKindaEnumWidget
*iface
)
911 KindaEnum
*This
= impl_from_IKindaEnumWidget(iface
);
912 ULONG refs
= InterlockedDecrement(&This
->refs
);
915 memset(This
, 0xcc, sizeof(*This
));
916 HeapFree(GetProcessHeap(), 0, This
);
917 trace("KindaEnumWidget destroyed!\n");
923 static HRESULT WINAPI
KindaEnum_Next(
924 IKindaEnumWidget
*iface
,
925 /* [out] */ IWidget __RPC_FAR
*__RPC_FAR
*widget
)
927 *widget
= Widget_Create();
931 return E_OUTOFMEMORY
;
934 static HRESULT WINAPI
KindaEnum_Count(
935 IKindaEnumWidget
*iface
,
936 /* [out] */ ULONG __RPC_FAR
*count
)
941 static HRESULT WINAPI
KindaEnum_Reset(
942 IKindaEnumWidget
*iface
)
947 static HRESULT WINAPI
KindaEnum_Clone(
948 IKindaEnumWidget
*iface
,
949 /* [out] */ IKindaEnumWidget __RPC_FAR
*__RPC_FAR
*ppenum
)
954 static const IKindaEnumWidgetVtbl KindaEnumWidget_VTable
=
956 KindaEnum_QueryInterface
,
965 static IKindaEnumWidget
*KindaEnumWidget_Create(void)
969 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
970 if (!This
) return NULL
;
971 This
->IKindaEnumWidget_iface
.lpVtbl
= &KindaEnumWidget_VTable
;
973 return &This
->IKindaEnumWidget_iface
;
976 static HRESULT WINAPI
NonOleAutomation_QueryInterface(INonOleAutomation
*iface
, REFIID riid
, void **ppv
)
978 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_INonOleAutomation
))
980 *(INonOleAutomation
**)ppv
= iface
;
984 return E_NOINTERFACE
;
987 static ULONG WINAPI
NonOleAutomation_AddRef(INonOleAutomation
*iface
)
992 static ULONG WINAPI
NonOleAutomation_Release(INonOleAutomation
*iface
)
997 static BSTR WINAPI
NonOleAutomation_BstrRet(INonOleAutomation
*iface
)
999 static const WCHAR wszTestString
[] = {'T','h','i','s',' ','i','s',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0};
1000 return SysAllocString(wszTestString
);
1003 static HRESULT WINAPI
NonOleAutomation_Error(INonOleAutomation
*iface
)
1008 static INonOleAutomationVtbl NonOleAutomation_VTable
=
1010 NonOleAutomation_QueryInterface
,
1011 NonOleAutomation_AddRef
,
1012 NonOleAutomation_Release
,
1013 NonOleAutomation_BstrRet
,
1014 NonOleAutomation_Error
1017 static INonOleAutomation NonOleAutomation
= { &NonOleAutomation_VTable
};
1019 static ITypeInfo
*NonOleAutomation_GetTypeInfo(void)
1022 HRESULT hr
= LoadRegTypeLib(&LIBID_TestTypelib
, 1, 0, LOCALE_NEUTRAL
, &pTypeLib
);
1023 ok_ole_success(hr
, LoadRegTypeLib
);
1026 ITypeInfo
*pTypeInfo
;
1027 hr
= ITypeLib_GetTypeInfoOfGuid(pTypeLib
, &IID_INonOleAutomation
, &pTypeInfo
);
1028 ok_ole_success(hr
, ITypeLib_GetTypeInfoOfGuid
);
1029 ITypeLib_Release(pTypeLib
);
1035 static void test_typelibmarshal(void)
1037 static const WCHAR szCat
[] = { 'C','a','t',0 };
1038 static const WCHAR szTestTest
[] = { 'T','e','s','t','T','e','s','t',0 };
1039 static WCHAR szSuperman
[] = { 'S','u','p','e','r','m','a','n',0 };
1041 IKindaEnumWidget
*pKEW
= KindaEnumWidget_Create();
1044 IDispatch
*pDispatch
;
1045 static const LARGE_INTEGER ullZero
;
1046 EXCEPINFO excepinfo
;
1048 DISPID dispidNamed
= DISPID_PROPERTYPUT
;
1049 DISPPARAMS dispparams
;
1050 VARIANTARG vararg
[4];
1055 ITypeInfo
*pTypeInfo
;
1057 MYSTRUCT mystructArray
[5];
1060 ok(pKEW
!= NULL
, "Widget creation failed\n");
1062 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
1063 ok_ole_success(hr
, CreateStreamOnHGlobal
);
1064 tid
= start_host_object(pStream
, &IID_IKindaEnumWidget
, (IUnknown
*)pKEW
, MSHLFLAGS_NORMAL
, &thread
);
1065 IKindaEnumWidget_Release(pKEW
);
1067 IStream_Seek(pStream
, ullZero
, STREAM_SEEK_SET
, NULL
);
1068 hr
= CoUnmarshalInterface(pStream
, &IID_IKindaEnumWidget
, (void **)&pKEW
);
1069 ok_ole_success(hr
, CoUnmarshalInterface
);
1070 IStream_Release(pStream
);
1072 hr
= IKindaEnumWidget_Next(pKEW
, &pWidget
);
1073 ok_ole_success(hr
, IKindaEnumWidget_Next
);
1075 IKindaEnumWidget_Release(pKEW
);
1077 /* call GetTypeInfoCount (direct) */
1078 hr
= IWidget_GetTypeInfoCount(pWidget
, &uval
);
1079 ok_ole_success(hr
, IWidget_GetTypeInfoCount
);
1080 hr
= IWidget_GetTypeInfoCount(pWidget
, &uval
);
1081 ok_ole_success(hr
, IWidget_GetTypeInfoCount
);
1083 hr
= IWidget_QueryInterface(pWidget
, &IID_IDispatch
, (void **)&pDispatch
);
1084 ok_ole_success(hr
, IWidget_QueryInterface
);
1087 VariantInit(&vararg
[0]);
1088 dispparams
.cNamedArgs
= 1;
1089 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1090 dispparams
.cArgs
= 1;
1091 dispparams
.rgvarg
= vararg
;
1092 VariantInit(&varresult
);
1093 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1094 ok_ole_success(hr
, IDispatch_Invoke
);
1095 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1096 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1097 excepinfo
.wCode
, excepinfo
.scode
);
1098 VariantClear(&varresult
);
1100 /* call put_Name (direct) */
1101 bstr
= SysAllocString(szSuperman
);
1102 hr
= IWidget_put_Name(pWidget
, bstr
);
1103 ok_ole_success(hr
, IWidget_put_Name
);
1104 SysFreeString(bstr
);
1107 dispparams
.cNamedArgs
= 0;
1108 dispparams
.rgdispidNamedArgs
= NULL
;
1109 dispparams
.cArgs
= 0;
1110 dispparams
.rgvarg
= NULL
;
1111 VariantInit(&varresult
);
1112 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1113 ok_ole_success(hr
, IDispatch_Invoke
);
1114 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1115 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1116 excepinfo
.wCode
, excepinfo
.scode
);
1117 trace("Name = %s\n", wine_dbgstr_w(V_BSTR(&varresult
)));
1118 VariantClear(&varresult
);
1120 /* call get_Name (direct) */
1121 bstr
= (void *)0xdeadbeef;
1122 hr
= IWidget_get_Name(pWidget
, &bstr
);
1123 ok_ole_success(hr
, IWidget_get_Name
);
1124 ok(!lstrcmpW(bstr
, szCat
), "IWidget_get_Name should have returned string \"Cat\" instead of %s\n", wine_dbgstr_w(bstr
));
1125 SysFreeString(bstr
);
1127 /* call DoSomething */
1128 VariantInit(&vararg
[0]);
1129 VariantInit(&vararg
[1]);
1130 V_VT(&vararg
[1]) = VT_R8
;
1131 V_R8(&vararg
[1]) = 3.141;
1132 dispparams
.cNamedArgs
= 0;
1133 dispparams
.cArgs
= 2;
1134 dispparams
.rgdispidNamedArgs
= NULL
;
1135 dispparams
.rgvarg
= vararg
;
1136 VariantInit(&varresult
);
1137 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_DOSOMETHING
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1138 ok_ole_success(hr
, IDispatch_Invoke
);
1139 ok(V_VT(&varresult
) == VT_EMPTY
, "varresult should be VT_EMPTY\n");
1140 VariantClear(&varresult
);
1142 /* call get_State */
1143 dispparams
.cNamedArgs
= 0;
1144 dispparams
.cArgs
= 0;
1145 dispparams
.rgdispidNamedArgs
= NULL
;
1146 dispparams
.rgvarg
= NULL
;
1147 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_STATE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1148 ok_ole_success(hr
, IDispatch_Invoke
);
1149 ok((V_VT(&varresult
) == VT_I4
) && (V_I4(&varresult
) == STATE_WIDGETIFIED
), "Return val mismatch\n");
1151 /* call get_State (direct) */
1152 hr
= IWidget_get_State(pWidget
, &the_state
);
1153 ok_ole_success(hr
, IWidget_get_state
);
1154 ok(the_state
== STATE_WIDGETIFIED
, "should have returned WIDGET_WIDGETIFIED instead of %d\n", the_state
);
1156 /* call put_State */
1157 the_state
= STATE_WIDGETIFIED
;
1158 VariantInit(&vararg
[0]);
1159 V_VT(&vararg
[0]) = VT_BYREF
|VT_I4
;
1160 V_I4REF(&vararg
[0]) = (int *)&the_state
;
1161 dispparams
.cNamedArgs
= 1;
1162 dispparams
.cArgs
= 1;
1163 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1164 dispparams
.rgvarg
= vararg
;
1165 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_STATE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1166 ok_ole_success(hr
, IDispatch_Invoke
);
1169 bstr
= SysAllocString(szTestTest
);
1170 VariantInit(&vararg
[0]);
1171 V_VT(&vararg
[0]) = VT_BYREF
|VT_BSTR
;
1172 V_BSTRREF(&vararg
[0]) = &bstr
;
1173 dispparams
.cNamedArgs
= 0;
1174 dispparams
.cArgs
= 1;
1175 dispparams
.rgdispidNamedArgs
= NULL
;
1176 dispparams
.rgvarg
= vararg
;
1177 VariantInit(&varresult
);
1178 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_MAP
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1179 ok_ole_success(hr
, IDispatch_Invoke
);
1180 ok(V_VT(&varresult
) == VT_BSTR
, "Return value should be of type BSTR instead of %d\n", V_VT(&varresult
));
1181 ok(!lstrcmpW(V_BSTR(&varresult
), szTestTest
), "Return value should have been \"TestTest\" instead of %s\n", wine_dbgstr_w(V_BSTR(&varresult
)));
1182 VariantClear(&varresult
);
1183 SysFreeString(bstr
);
1185 /* call SetOleColor with large negative VT_I4 param */
1186 VariantInit(&vararg
[0]);
1187 V_VT(&vararg
[0]) = VT_I4
;
1188 V_I4(&vararg
[0]) = 0x80000005;
1189 dispparams
.cNamedArgs
= 0;
1190 dispparams
.cArgs
= 1;
1191 dispparams
.rgdispidNamedArgs
= NULL
;
1192 dispparams
.rgvarg
= vararg
;
1193 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_SETOLECOLOR
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, &excepinfo
, NULL
);
1194 ok_ole_success(hr
, IDispatch_Invoke
);
1196 /* call GetOleColor */
1197 dispparams
.cNamedArgs
= 0;
1198 dispparams
.cArgs
= 0;
1199 dispparams
.rgdispidNamedArgs
= NULL
;
1200 dispparams
.rgvarg
= NULL
;
1201 VariantInit(&varresult
);
1202 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_GETOLECOLOR
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1203 ok_ole_success(hr
, IDispatch_Invoke
);
1204 VariantClear(&varresult
);
1206 /* call StructArgs (direct) */
1207 mystruct
= MYSTRUCT_BYPTR
;
1208 memcpy(mystructArray
, MYSTRUCT_ARRAY
, sizeof(mystructArray
));
1209 hr
= IWidget_StructArgs(pWidget
, MYSTRUCT_BYVAL
, &mystruct
, mystructArray
);
1210 ok_ole_success(hr
, IWidget_StructArgs
);
1213 dispparams
.cNamedArgs
= 0;
1214 dispparams
.cArgs
= 0;
1215 dispparams
.rgdispidNamedArgs
= NULL
;
1216 dispparams
.rgvarg
= NULL
;
1217 VariantInit(&varresult
);
1218 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1219 ok_ole_success(hr
, IDispatch_Invoke
);
1220 ok(V_VT(&varresult
) == VT_DISPATCH
, "vt %x\n", V_VT(&varresult
));
1221 VariantClear(&varresult
);
1223 /* call CloneInterface */
1224 dispparams
.cNamedArgs
= 0;
1225 dispparams
.cArgs
= 0;
1226 dispparams
.rgdispidNamedArgs
= NULL
;
1227 dispparams
.rgvarg
= NULL
;
1228 VariantInit(&varresult
);
1229 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONEINTERFACE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1230 ok_ole_success(hr
, IDispatch_Invoke
);
1231 ok(V_VT(&varresult
) == VT_DISPATCH
, "vt %x\n", V_VT(&varresult
));
1232 VariantClear(&varresult
);
1234 /* call CloneDispatch with automatic value getting */
1235 V_VT(&vararg
[0]) = VT_I2
;
1236 V_I2(&vararg
[0]) = 1;
1237 dispparams
.cNamedArgs
= 0;
1238 dispparams
.rgdispidNamedArgs
= NULL
;
1239 dispparams
.cArgs
= 1;
1240 dispparams
.rgvarg
= vararg
;
1241 VariantInit(&varresult
);
1242 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONEDISPATCH
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1243 ok_ole_success(hr
, IDispatch_Invoke
);
1245 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1246 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1247 excepinfo
.wCode
, excepinfo
.scode
);
1249 ok(V_VT(&varresult
) == VT_I2
, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult
));
1250 ok(V_I2(&varresult
) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult
));
1251 VariantClear(&varresult
);
1253 /* call CloneCoclass */
1254 dispparams
.cNamedArgs
= 0;
1255 dispparams
.cArgs
= 0;
1256 dispparams
.rgdispidNamedArgs
= NULL
;
1257 dispparams
.rgvarg
= NULL
;
1258 VariantInit(&varresult
);
1259 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_CLONECOCLASS
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1260 ok_ole_success(hr
, IDispatch_Invoke
);
1262 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1263 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1264 excepinfo
.wCode
, excepinfo
.scode
);
1266 ok(V_VT(&varresult
) == VT_DISPATCH
, "V_VT(&varresult) was %d instead of VT_DISPATCH\n", V_VT(&varresult
));
1267 ok(!V_DISPATCH(&varresult
), "V_DISPATCH(&varresult) should be NULL instead of %p\n", V_DISPATCH(&varresult
));
1268 VariantClear(&varresult
);
1270 /* call Value with a VT_VARIANT|VT_BYREF type */
1271 V_VT(&vararg
[0]) = VT_VARIANT
|VT_BYREF
;
1272 V_VARIANTREF(&vararg
[0]) = &vararg
[1];
1273 V_VT(&vararg
[1]) = VT_I2
;
1274 V_I2(&vararg
[1]) = 1;
1275 dispparams
.cNamedArgs
= 0;
1276 dispparams
.rgdispidNamedArgs
= NULL
;
1277 dispparams
.cArgs
= 1;
1278 dispparams
.rgvarg
= vararg
;
1279 VariantInit(&varresult
);
1280 hr
= IDispatch_Invoke(pDispatch
, DISPID_VALUE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1281 ok_ole_success(hr
, IDispatch_Invoke
);
1283 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== S_OK
,
1284 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1285 excepinfo
.wCode
, excepinfo
.scode
);
1287 ok(V_VT(&varresult
) == VT_I2
, "V_VT(&varresult) was %d instead of VT_I2\n", V_VT(&varresult
));
1288 ok(V_I2(&varresult
) == 1234, "V_I2(&varresult) was %d instead of 1234\n", V_I2(&varresult
));
1289 VariantClear(&varresult
);
1291 /* call Variant - exercises variant copying in ITypeInfo::Invoke and
1292 * handling of void return types */
1293 /* use a big type to ensure that the variant was properly copied into the
1294 * destination function's args */
1295 V_VT(&vararg
[0]) = VT_CY
;
1296 S(V_CY(&vararg
[0])).Hi
= 0xdababe;
1297 S(V_CY(&vararg
[0])).Lo
= 0xdeadbeef;
1298 dispparams
.cNamedArgs
= 0;
1299 dispparams
.cArgs
= 1;
1300 dispparams
.rgdispidNamedArgs
= NULL
;
1301 dispparams
.rgvarg
= vararg
;
1302 VariantInit(&varresult
);
1303 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARIANT
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1304 ok_ole_success(hr
, IDispatch_Invoke
);
1305 VariantClear(&varresult
);
1307 /* call VariantCArray - test marshaling of variant arrays */
1308 V_VT(&vararg
[0]) = VT_I4
;
1309 V_I4(&vararg
[0]) = 1;
1310 V_VT(&vararg
[1]) = VT_I4
;
1311 V_I4(&vararg
[1]) = 2;
1312 hr
= IWidget_VariantCArray(pWidget
, 2, vararg
);
1313 ok_ole_success(hr
, IWidget_VariantCArray
);
1315 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]));
1317 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]));
1320 VariantInit(&vararg
[3]);
1321 V_VT(&vararg
[3]) = VT_I4
;
1322 V_I4(&vararg
[3]) = 3;
1323 VariantInit(&vararg
[2]);
1324 V_VT(&vararg
[2]) = VT_I4
;
1325 V_I4(&vararg
[2]) = 0;
1326 VariantInit(&vararg
[1]);
1327 V_VT(&vararg
[1]) = VT_I4
;
1328 V_I4(&vararg
[1]) = 1;
1329 VariantInit(&vararg
[0]);
1330 V_VT(&vararg
[0]) = VT_I4
;
1331 V_I4(&vararg
[0]) = 2;
1332 dispparams
.cNamedArgs
= 0;
1333 dispparams
.cArgs
= 4;
1334 dispparams
.rgdispidNamedArgs
= NULL
;
1335 dispparams
.rgvarg
= vararg
;
1336 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARARG
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1337 ok_ole_success(hr
, ITypeInfo_Invoke
);
1339 /* call VarArg, even one (non-optional, non-safearray) named argument is not allowed */
1341 dispparams
.cNamedArgs
= 1;
1342 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1343 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_VARARG
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, NULL
, NULL
);
1344 ok(hr
== DISP_E_NONAMEDARGS
, "IDispatch_Invoke should have returned DISP_E_NONAMEDARGS instead of 0x%08x\n", hr
);
1345 dispidNamed
= DISPID_PROPERTYPUT
;
1348 dispparams
.cNamedArgs
= 0;
1349 dispparams
.cArgs
= 0;
1350 dispparams
.rgdispidNamedArgs
= NULL
;
1351 dispparams
.rgvarg
= NULL
;
1352 VariantInit(&varresult
);
1353 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_ERROR
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, NULL
, &excepinfo
, NULL
);
1354 ok(hr
== DISP_E_EXCEPTION
, "IDispatch_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr
);
1355 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== E_NOTIMPL
,
1356 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1357 excepinfo
.wCode
, excepinfo
.scode
);
1358 VariantClear(&varresult
);
1361 pTypeInfo
= NonOleAutomation_GetTypeInfo();
1362 dispparams
.cNamedArgs
= 0;
1363 dispparams
.cArgs
= 0;
1364 dispparams
.rgdispidNamedArgs
= NULL
;
1365 dispparams
.rgvarg
= NULL
;
1366 VariantInit(&varresult
);
1367 hr
= ITypeInfo_Invoke(pTypeInfo
, &NonOleAutomation
, DISPID_NOA_BSTRRET
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1368 ok_ole_success(hr
, ITypeInfo_Invoke
);
1369 ok(V_VT(&varresult
) == VT_BSTR
, "V_VT(&varresult) should be VT_BSTR instead of %d\n", V_VT(&varresult
));
1370 ok(V_BSTR(&varresult
) != NULL
, "V_BSTR(&varresult) should not be NULL\n");
1372 VariantClear(&varresult
);
1374 dispparams
.cNamedArgs
= 0;
1375 dispparams
.cArgs
= 0;
1376 dispparams
.rgdispidNamedArgs
= NULL
;
1377 dispparams
.rgvarg
= NULL
;
1378 hr
= ITypeInfo_Invoke(pTypeInfo
, &NonOleAutomation
, DISPID_NOA_ERROR
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1379 ok(hr
== DISP_E_EXCEPTION
, "ITypeInfo_Invoke should have returned DISP_E_EXCEPTION instead of 0x%08x\n", hr
);
1380 ok(V_VT(&varresult
) == VT_EMPTY
, "V_VT(&varresult) should be VT_EMPTY instead of %d\n", V_VT(&varresult
));
1381 ok(excepinfo
.wCode
== 0x0 && excepinfo
.scode
== E_NOTIMPL
,
1382 "EXCEPINFO differs from expected: wCode = 0x%x, scode = 0x%08x\n",
1383 excepinfo
.wCode
, excepinfo
.scode
);
1384 VariantClear(&varresult
);
1386 ITypeInfo_Release(pTypeInfo
);
1388 /* tests call put_Name without named arg */
1389 VariantInit(&vararg
[0]);
1390 dispparams
.cNamedArgs
= 0;
1391 dispparams
.rgdispidNamedArgs
= NULL
;
1392 dispparams
.cArgs
= 1;
1393 dispparams
.rgvarg
= vararg
;
1394 VariantInit(&varresult
);
1395 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1396 ok(hr
== DISP_E_PARAMNOTFOUND
, "IDispatch_Invoke should have returned DISP_E_PARAMNOTFOUND instead of 0x%08x\n", hr
);
1397 VariantClear(&varresult
);
1399 /* tests param type that cannot be coerced */
1400 VariantInit(&vararg
[0]);
1401 V_VT(&vararg
[0]) = VT_UNKNOWN
;
1402 V_UNKNOWN(&vararg
[0]) = NULL
;
1403 dispparams
.cNamedArgs
= 1;
1404 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1405 dispparams
.cArgs
= 1;
1406 dispparams
.rgvarg
= vararg
;
1407 VariantInit(&varresult
);
1408 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1409 ok(hr
== DISP_E_TYPEMISMATCH
, "IDispatch_Invoke should have returned DISP_E_TYPEMISMATCH instead of 0x%08x\n", hr
);
1410 VariantClear(&varresult
);
1412 /* tests bad param type */
1413 VariantInit(&vararg
[0]);
1414 V_VT(&vararg
[0]) = VT_CLSID
;
1415 V_BYREF(&vararg
[0]) = NULL
;
1416 dispparams
.cNamedArgs
= 1;
1417 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1418 dispparams
.cArgs
= 1;
1419 dispparams
.rgvarg
= vararg
;
1420 VariantInit(&varresult
);
1421 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NAME
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1422 ok(hr
== DISP_E_BADVARTYPE
, "IDispatch_Invoke should have returned DISP_E_BADVARTYPE instead of 0x%08x\n", hr
);
1423 VariantClear(&varresult
);
1425 /* tests too small param count */
1426 dispparams
.cNamedArgs
= 0;
1427 dispparams
.rgdispidNamedArgs
= NULL
;
1428 dispparams
.cArgs
= 0;
1429 dispparams
.rgvarg
= NULL
;
1430 VariantInit(&varresult
);
1431 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_DOSOMETHING
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1432 ok(hr
== DISP_E_BADPARAMCOUNT
, "IDispatch_Invoke should have returned DISP_E_BADPARAMCOUNT instead of 0x%08x\n", hr
);
1433 VariantClear(&varresult
);
1435 /* tests propget function with large param count */
1436 VariantInit(&vararg
[0]);
1437 V_VT(&vararg
[0]) = VT_BSTR
;
1438 V_BSTR(&vararg
[0]) = NULL
;
1439 V_VT(&vararg
[1]) = VT_I4
;
1440 V_I4(&vararg
[1]) = 1;
1441 dispparams
.cNamedArgs
= 0;
1442 dispparams
.cArgs
= 2;
1443 dispparams
.rgdispidNamedArgs
= NULL
;
1444 dispparams
.rgvarg
= vararg
;
1445 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_STATE
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1446 ok(hr
== DISP_E_NOTACOLLECTION
, "IDispatch_Invoke should have returned DISP_E_NOTACOLLECTION instead of 0x%08x\n", hr
);
1448 /* test propput with lcid */
1450 /* the lcid passed to the function is the first lcid in the typelib header.
1451 Since we don't explicitly set an lcid in the idl, it'll default to US English. */
1452 VariantInit(&vararg
[0]);
1453 V_VT(&vararg
[0]) = VT_I4
;
1454 V_I4(&vararg
[0]) = 0xcafe;
1455 dispparams
.cNamedArgs
= 1;
1456 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1457 dispparams
.cArgs
= 1;
1458 dispparams
.rgvarg
= vararg
;
1459 VariantInit(&varresult
);
1460 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_WITH_LCID
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1461 ok_ole_success(hr
, ITypeInfo_Invoke
);
1462 VariantClear(&varresult
);
1464 /* test propget with lcid */
1465 dispparams
.cNamedArgs
= 0;
1466 dispparams
.cArgs
= 0;
1467 dispparams
.rgvarg
= NULL
;
1468 dispparams
.rgdispidNamedArgs
= NULL
;
1469 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_WITH_LCID
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1470 ok_ole_success(hr
, ITypeInfo_Invoke
);
1471 ok(V_VT(&varresult
) == VT_I4
, "got %x\n", V_VT(&varresult
));
1472 ok(V_I4(&varresult
) == 0x409, "got %x\n", V_I4(&varresult
));
1473 VariantClear(&varresult
);
1475 /* test propget of INT value */
1476 dispparams
.cNamedArgs
= 0;
1477 dispparams
.cArgs
= 0;
1478 dispparams
.rgvarg
= NULL
;
1479 dispparams
.rgdispidNamedArgs
= NULL
;
1480 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_INT
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1481 ok_ole_success(hr
, ITypeInfo_Invoke
);
1482 ok(V_VT(&varresult
) == VT_I4
, "got %x\n", V_VT(&varresult
));
1483 ok(V_I4(&varresult
) == -13, "got %x\n", V_I4(&varresult
));
1484 VariantClear(&varresult
);
1486 /* test propget of INT value */
1487 dispparams
.cNamedArgs
= 0;
1488 dispparams
.cArgs
= 0;
1489 dispparams
.rgvarg
= NULL
;
1490 dispparams
.rgdispidNamedArgs
= NULL
;
1491 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_UINT
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYGET
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1492 ok_ole_success(hr
, ITypeInfo_Invoke
);
1493 ok(V_VT(&varresult
) == VT_UI4
, "got %x\n", V_VT(&varresult
));
1494 ok(V_UI4(&varresult
) == 42, "got %x\n", V_UI4(&varresult
));
1495 VariantClear(&varresult
);
1497 /* test byref marshalling */
1499 VariantInit(&vararg
[0]);
1500 V_VT(&vararg
[0]) = VT_UI4
|VT_BYREF
;
1501 V_UI4REF(&vararg
[0]) = &uval
;
1502 dispparams
.cNamedArgs
= 0;
1503 dispparams
.cArgs
= 1;
1504 dispparams
.rgvarg
= vararg
;
1505 dispparams
.rgdispidNamedArgs
= NULL
;
1506 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_BYREF_UINT
, &IID_NULL
, LOCALE_NEUTRAL
, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1507 ok_ole_success(hr
, ITypeInfo_Invoke
);
1508 ok(V_VT(&varresult
) == VT_EMPTY
, "varresult should be VT_EMPTY\n");
1509 ok(V_VT(&vararg
[0]) == (VT_UI4
|VT_BYREF
), "arg VT not unmarshalled correctly: %x\n", V_VT(&vararg
[0]));
1510 ok(V_UI4REF(&vararg
[0]) == &uval
, "Byref pointer not preserved: %p/%p\n", &uval
, V_UI4REF(&vararg
[0]));
1511 ok(*V_UI4REF(&vararg
[0]) == 42, "Expected 42 to be returned instead of %u\n", *V_UI4REF(&vararg
[0]));
1512 VariantClear(&varresult
);
1513 VariantClear(&vararg
[0]);
1515 /* test propput with optional argument. */
1516 VariantInit(&vararg
[0]);
1517 V_VT(&vararg
[0]) = VT_I4
;
1518 V_I4(&vararg
[0]) = 0xcafe;
1519 dispparams
.cNamedArgs
= 1;
1520 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1521 dispparams
.cArgs
= 1;
1522 dispparams
.rgvarg
= vararg
;
1523 VariantInit(&varresult
);
1524 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_OPT_ARG
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1525 ok_ole_success(hr
, ITypeInfo_Invoke
);
1526 VariantClear(&varresult
);
1528 /* test propput with required argument. */
1529 VariantInit(&vararg
[0]);
1530 VariantInit(&vararg
[1]);
1531 V_VT(&vararg
[0]) = VT_I4
;
1532 V_I4(&vararg
[0]) = 0x1234;
1533 V_VT(&vararg
[1]) = VT_I4
;
1534 V_I4(&vararg
[1]) = 0x5678;
1535 dispparams
.cNamedArgs
= 1;
1536 dispparams
.rgdispidNamedArgs
= &dispidNamed
;
1537 dispparams
.cArgs
= 2;
1538 dispparams
.rgvarg
= vararg
;
1539 VariantInit(&varresult
);
1540 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_PROP_REQ_ARG
, &IID_NULL
, 0x40c, DISPATCH_PROPERTYPUT
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1541 ok_ole_success(hr
, ITypeInfo_Invoke
);
1542 VariantClear(&varresult
);
1544 /* restricted member */
1545 dispparams
.cNamedArgs
= 0;
1546 dispparams
.rgdispidNamedArgs
= NULL
;
1547 dispparams
.cArgs
= 0;
1548 dispparams
.rgvarg
= NULL
;
1549 VariantInit(&varresult
);
1550 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_RESTRICTED
, &IID_NULL
, 0x40c, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1551 ok( hr
== DISP_E_MEMBERNOTFOUND
, "got %08x\n", hr
);
1552 VariantClear(&varresult
);
1554 /* restricted member with -ve memid (not restricted) */
1555 dispparams
.cNamedArgs
= 0;
1556 dispparams
.rgdispidNamedArgs
= NULL
;
1557 dispparams
.cArgs
= 0;
1558 dispparams
.rgvarg
= NULL
;
1559 VariantInit(&varresult
);
1560 hr
= IDispatch_Invoke(pDispatch
, DISPID_TM_NEG_RESTRICTED
, &IID_NULL
, 0x40c, DISPATCH_METHOD
, &dispparams
, &varresult
, &excepinfo
, NULL
);
1561 ok( hr
== S_OK
, "got %08x\n", hr
);
1562 ok(V_VT(&varresult
) == VT_I4
, "got %x\n", V_VT(&varresult
));
1563 ok(V_I4(&varresult
) == DISPID_TM_NEG_RESTRICTED
, "got %x\n", V_I4(&varresult
));
1564 VariantClear(&varresult
);
1566 IDispatch_Release(pDispatch
);
1567 IWidget_Release(pWidget
);
1569 trace("calling end_host_object\n");
1570 end_host_object(tid
, thread
);
1573 static void test_DispCallFunc(void)
1575 static const WCHAR szEmpty
[] = { 0 };
1576 VARTYPE rgvt
[] = { VT_R8
, VT_BSTR
, VT_BSTR
, VT_VARIANT
|VT_BYREF
};
1577 VARIANTARG vararg
[4];
1579 VARIANTARG
*rgpvarg
[4] = { &vararg
[0], &vararg
[1], &vararg
[2], &vararg
[3] };
1580 VARIANTARG varresult
;
1582 IWidget
*pWidget
= Widget_Create();
1583 V_VT(&vararg
[0]) = VT_R8
;
1584 V_R8(&vararg
[0]) = 3.141;
1585 V_VT(&vararg
[1]) = VT_BSTR
;
1586 V_BSTRREF(&vararg
[1]) = CoTaskMemAlloc(sizeof(BSTR
));
1587 V_VT(&vararg
[2]) = VT_BSTR
;
1588 V_BSTR(&vararg
[2]) = SysAllocString(szEmpty
);
1589 V_VT(&vararg
[3]) = VT_VARIANT
|VT_BYREF
;
1590 V_VARIANTREF(&vararg
[3]) = &varref
;
1591 V_VT(&varref
) = VT_ERROR
;
1592 V_ERROR(&varref
) = DISP_E_PARAMNOTFOUND
;
1593 VariantInit(&varresult
);
1594 hr
= DispCallFunc(pWidget
, 9*sizeof(void*), CC_STDCALL
, VT_UI4
, 4, rgvt
, rgpvarg
, &varresult
);
1595 ok_ole_success(hr
, DispCallFunc
);
1596 VariantClear(&varresult
);
1597 SysFreeString(*V_BSTRREF(&vararg
[1]));
1598 CoTaskMemFree(V_BSTRREF(&vararg
[1]));
1599 VariantClear(&vararg
[2]);
1600 IWidget_Release(pWidget
);
1603 static void test_StaticWidget(void)
1605 ITypeInfo
*type_info
;
1606 DISPPARAMS dispparams
;
1607 VARIANTARG vararg
[4];
1608 EXCEPINFO excepinfo
;
1612 type_info
= get_type_info(&IID_IStaticWidget
);
1615 dispparams
.cNamedArgs
= 0;
1616 dispparams
.cArgs
= 1;
1617 dispparams
.rgdispidNamedArgs
= NULL
;
1618 dispparams
.rgvarg
= vararg
;
1619 V_VT(vararg
) = VT_DISPATCH
;
1620 V_DISPATCH(vararg
) = (IDispatch
*)&TestDualDisp
;
1621 VariantInit(&varresult
);
1622 hr
= ITypeInfo_Invoke(type_info
, &StaticWidget
, DISPID_TM_TESTDUAL
, DISPATCH_METHOD
,
1623 &dispparams
, &varresult
, &excepinfo
, NULL
);
1624 ok_ole_success(hr
, IDispatch_Invoke
);
1625 ok(V_VT(&varresult
) == VT_EMPTY
, "vt %x\n", V_VT(&varresult
));
1626 VariantClear(&varresult
);
1628 ITypeInfo_Release(type_info
);
1631 static void test_libattr(void)
1637 hr
= LoadRegTypeLib(&LIBID_TestTypelib
, 1, 0, LOCALE_NEUTRAL
, &pTypeLib
);
1638 ok_ole_success(hr
, LoadRegTypeLib
);
1642 hr
= ITypeLib_GetLibAttr(pTypeLib
, &pattr
);
1643 ok_ole_success(hr
, GetLibAttr
);
1646 ok(pattr
->lcid
== MAKELANGID(LANG_NEUTRAL
, SUBLANG_NEUTRAL
), "lcid %x\n", pattr
->lcid
);
1648 ITypeLib_ReleaseTLibAttr(pTypeLib
, pattr
);
1651 ITypeLib_Release(pTypeLib
);
1654 START_TEST(tmarshal
)
1657 HANDLE hOleaut32
= GetModuleHandleA("oleaut32.dll");
1658 pVarAdd
= (void*)GetProcAddress(hOleaut32
, "VarAdd");
1660 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1662 hr
= register_current_module_typelib();
1666 win_skip("Registration of the test typelib failed, skipping tests\n");
1670 test_typelibmarshal();
1671 test_DispCallFunc();
1672 test_StaticWidget();
1675 hr
= UnRegisterTypeLib(&LIBID_TestTypelib
, 1, 0, LOCALE_NEUTRAL
,
1676 sizeof(void*) == 8 ? SYS_WIN64
: SYS_WIN32
);
1677 ok_ole_success(hr
, UnRegisterTypeLib
);