2 * Component Object Tests
4 * Copyright 2005 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "urlmon.h" /* for CLSID_FileProtocol */
35 #include "wine/test.h"
37 /* functions that are not present on all versions of Windows */
38 HRESULT (WINAPI
* pCoInitializeEx
)(LPVOID lpReserved
, DWORD dwCoInit
);
39 HRESULT (WINAPI
* pCoGetObjectContext
)(REFIID riid
, LPVOID
*ppv
);
40 HRESULT (WINAPI
* pCoSwitchCallContext
)(IUnknown
*pObject
, IUnknown
**ppOldObject
);
41 HRESULT (WINAPI
* pCoGetTreatAsClass
)(REFCLSID clsidOld
, LPCLSID pClsidNew
);
43 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
44 #define ok_more_than_one_lock() ok(cLocks > 0, "Number of locks should be > 0, but actually is %d\n", cLocks)
45 #define ok_no_locks() ok(cLocks == 0, "Number of locks should be 0, but actually is %d\n", cLocks)
47 static const CLSID CLSID_non_existent
= { 0x12345678, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
48 static const CLSID CLSID_StdFont
= { 0x0be35203, 0x8f91, 0x11ce, { 0x9d, 0xe3, 0x00, 0xaa, 0x00, 0x4b, 0xb8, 0x51 } };
49 static WCHAR stdfont
[] = {'S','t','d','F','o','n','t',0};
50 static const WCHAR wszNonExistent
[] = {'N','o','n','E','x','i','s','t','e','n','t',0};
51 static WCHAR wszCLSID_StdFont
[] =
53 '{','0','b','e','3','5','2','0','3','-','8','f','9','1','-','1','1','c','e','-',
54 '9','d','e','3','-','0','0','a','a','0','0','4','b','b','8','5','1','}',0
57 static const IID IID_IWineTest
=
62 {0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd}
63 }; /* 5201163f-8164-4fd0-a1a2-5d5a3654d3bd */
64 static const CLSID CLSID_WineOOPTest
= {
68 {0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd}
69 }; /* 5201163f-8164-4fd0-a1a2-5d5a3654d3bd */
73 static void LockModule(void)
75 InterlockedIncrement(&cLocks
);
78 static void UnlockModule(void)
80 InterlockedDecrement(&cLocks
);
83 static HRESULT WINAPI
Test_IClassFactory_QueryInterface(
88 if (ppvObj
== NULL
) return E_POINTER
;
90 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
91 IsEqualGUID(riid
, &IID_IClassFactory
))
94 IClassFactory_AddRef(iface
);
102 static ULONG WINAPI
Test_IClassFactory_AddRef(LPCLASSFACTORY iface
)
105 return 2; /* non-heap-based object */
108 static ULONG WINAPI
Test_IClassFactory_Release(LPCLASSFACTORY iface
)
111 return 1; /* non-heap-based object */
114 static HRESULT WINAPI
Test_IClassFactory_CreateInstance(
115 LPCLASSFACTORY iface
,
121 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
122 return E_NOINTERFACE
;
125 static HRESULT WINAPI
Test_IClassFactory_LockServer(
126 LPCLASSFACTORY iface
,
132 static const IClassFactoryVtbl TestClassFactory_Vtbl
=
134 Test_IClassFactory_QueryInterface
,
135 Test_IClassFactory_AddRef
,
136 Test_IClassFactory_Release
,
137 Test_IClassFactory_CreateInstance
,
138 Test_IClassFactory_LockServer
141 static IClassFactory Test_ClassFactory
= { &TestClassFactory_Vtbl
};
143 static void test_ProgIDFromCLSID(void)
146 HRESULT hr
= ProgIDFromCLSID(&CLSID_StdFont
, &progid
);
147 ok(hr
== S_OK
, "ProgIDFromCLSID failed with error 0x%08x\n", hr
);
150 ok(!lstrcmpiW(progid
, stdfont
), "Didn't get expected prog ID\n");
151 CoTaskMemFree(progid
);
154 progid
= (LPWSTR
)0xdeadbeef;
155 hr
= ProgIDFromCLSID(&CLSID_non_existent
, &progid
);
156 ok(hr
== REGDB_E_CLASSNOTREG
, "ProgIDFromCLSID returned %08x\n", hr
);
157 ok(progid
== NULL
, "ProgIDFromCLSID returns with progid %p\n", progid
);
159 hr
= ProgIDFromCLSID(&CLSID_StdFont
, NULL
);
160 ok(hr
== E_INVALIDARG
, "ProgIDFromCLSID should return E_INVALIDARG instead of 0x%08x\n", hr
);
163 static void test_CLSIDFromProgID(void)
166 HRESULT hr
= CLSIDFromProgID(stdfont
, &clsid
);
167 ok(hr
== S_OK
, "CLSIDFromProgID failed with error 0x%08x\n", hr
);
168 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
170 hr
= CLSIDFromString(stdfont
, &clsid
);
171 ok_ole_success(hr
, "CLSIDFromString");
172 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
174 /* test some failure cases */
176 hr
= CLSIDFromProgID(wszNonExistent
, NULL
);
177 ok(hr
== E_INVALIDARG
, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
179 hr
= CLSIDFromProgID(NULL
, &clsid
);
180 ok(hr
== E_INVALIDARG
, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
182 memset(&clsid
, 0xcc, sizeof(clsid
));
183 hr
= CLSIDFromProgID(wszNonExistent
, &clsid
);
184 ok(hr
== CO_E_CLASSSTRING
, "CLSIDFromProgID on nonexistent ProgID should have returned CO_E_CLASSSTRING instead of 0x%08x\n", hr
);
185 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "CLSIDFromProgID should have set clsid to all-zeros on failure\n");
188 static void test_CLSIDFromString(void)
191 HRESULT hr
= CLSIDFromString(wszCLSID_StdFont
, &clsid
);
192 ok_ole_success(hr
, "CLSIDFromString");
193 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
195 hr
= CLSIDFromString(NULL
, &clsid
);
196 ok_ole_success(hr
, "CLSIDFromString");
197 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "clsid wasn't equal to CLSID_NULL\n");
200 static void test_StringFromGUID2(void)
204 /* Test corner cases for buffer size */
205 len
= StringFromGUID2(&CLSID_StdFont
,str
,50);
206 ok(len
== 39, "len: %d (expected 39)\n", len
);
207 ok(!lstrcmpiW(str
, wszCLSID_StdFont
),"string wasn't equal for CLSID_StdFont\n");
209 memset(str
,0,sizeof str
);
210 len
= StringFromGUID2(&CLSID_StdFont
,str
,39);
211 ok(len
== 39, "len: %d (expected 39)\n", len
);
212 ok(!lstrcmpiW(str
, wszCLSID_StdFont
),"string wasn't equal for CLSID_StdFont\n");
214 len
= StringFromGUID2(&CLSID_StdFont
,str
,38);
215 ok(len
== 0, "len: %d (expected 0)\n", len
);
217 len
= StringFromGUID2(&CLSID_StdFont
,str
,30);
218 ok(len
== 0, "len: %d (expected 0)\n", len
);
226 static DWORD CALLBACK
ole_initialize_thread(LPVOID pv
)
229 struct info
*info
= pv
;
231 hr
= pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
233 SetEvent(info
->wait
);
234 WaitForSingleObject(info
->stop
, INFINITE
);
240 static void test_CoCreateInstance(void)
247 REFCLSID rclsid
= &CLSID_InternetZoneManager
;
249 pUnk
= (IUnknown
*)0xdeadbeef;
250 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
251 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
252 ok(pUnk
== NULL
, "CoCreateInstance should have changed the passed in pointer to NULL, instead of %p\n", pUnk
);
255 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
256 ok_ole_success(hr
, "CoCreateInstance");
257 if(pUnk
) IUnknown_Release(pUnk
);
260 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
261 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
263 /* show that COM doesn't have to be initialized for multi-threaded apartments if another
264 thread has already done so */
266 info
.wait
= CreateEvent(NULL
, TRUE
, FALSE
, NULL
);
267 ok(info
.wait
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
269 info
.stop
= CreateEvent(NULL
, TRUE
, FALSE
, NULL
);
270 ok(info
.stop
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
272 thread
= CreateThread(NULL
, 0, ole_initialize_thread
, &info
, 0, &tid
);
273 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
275 WaitForSingleObject(info
.wait
, INFINITE
);
277 pUnk
= (IUnknown
*)0xdeadbeef;
278 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
279 ok(hr
== S_OK
, "CoCreateInstance should have returned S_OK instead of 0x%08x\n", hr
);
280 if (pUnk
) IUnknown_Release(pUnk
);
283 WaitForSingleObject(thread
, INFINITE
);
285 GetExitCodeThread(thread
, &exitcode
);
287 ok(hr
== S_OK
, "thread should have returned S_OK instead of 0x%08x\n", hr
);
290 CloseHandle(info
.wait
);
291 CloseHandle(info
.stop
);
294 static void test_CoGetClassObject(void)
301 REFCLSID rclsid
= &CLSID_InternetZoneManager
;
303 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
304 ok(hr
== CO_E_NOTINITIALIZED
, "CoGetClassObject should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
305 ok(pUnk
== NULL
, "CoGetClassObject should have changed the passed in pointer to NULL, instead of %p\n", pUnk
);
307 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, NULL
);
308 ok(hr
== E_INVALIDARG
||
309 broken(hr
== CO_E_NOTINITIALIZED
), /* win9x */
310 "CoGetClassObject should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
312 /* show that COM doesn't have to be initialized for multi-threaded apartments if another
313 thread has already done so */
315 info
.wait
= CreateEvent(NULL
, TRUE
, FALSE
, NULL
);
316 ok(info
.wait
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
318 info
.stop
= CreateEvent(NULL
, TRUE
, FALSE
, NULL
);
319 ok(info
.stop
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
321 thread
= CreateThread(NULL
, 0, ole_initialize_thread
, &info
, 0, &tid
);
322 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
324 WaitForSingleObject(info
.wait
, INFINITE
);
326 pUnk
= (IUnknown
*)0xdeadbeef;
327 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
328 ok(hr
== S_OK
, "CoGetClassObject should have returned S_OK instead of 0x%08x\n", hr
);
329 if (pUnk
) IUnknown_Release(pUnk
);
332 WaitForSingleObject(thread
, INFINITE
);
334 GetExitCodeThread(thread
, &exitcode
);
336 ok(hr
== S_OK
, "thread should have returned S_OK instead of 0x%08x\n", hr
);
339 CloseHandle(info
.wait
);
340 CloseHandle(info
.stop
);
343 static ATOM
register_dummy_class(void)
351 GetModuleHandle(NULL
),
353 LoadCursor(NULL
, IDC_ARROW
),
354 (HBRUSH
)(COLOR_BTNFACE
+1),
356 TEXT("WineOleTestClass"),
359 return RegisterClass(&wc
);
362 static void test_ole_menu(void)
367 hwndFrame
= CreateWindow(MAKEINTATOM(register_dummy_class()), "Test", 0, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, NULL
, NULL
, NULL
, NULL
);
368 hr
= OleSetMenuDescriptor(NULL
, hwndFrame
, NULL
, NULL
, NULL
);
369 todo_wine
ok_ole_success(hr
, "OleSetMenuDescriptor");
371 DestroyWindow(hwndFrame
);
375 static HRESULT WINAPI
MessageFilter_QueryInterface(IMessageFilter
*iface
, REFIID riid
, void ** ppvObj
)
377 if (ppvObj
== NULL
) return E_POINTER
;
379 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
380 IsEqualGUID(riid
, &IID_IClassFactory
))
383 IMessageFilter_AddRef(iface
);
387 return E_NOINTERFACE
;
390 static ULONG WINAPI
MessageFilter_AddRef(IMessageFilter
*iface
)
392 return 2; /* non-heap object */
395 static ULONG WINAPI
MessageFilter_Release(IMessageFilter
*iface
)
397 return 1; /* non-heap object */
400 static DWORD WINAPI
MessageFilter_HandleInComingCall(
401 IMessageFilter
*iface
,
403 HTASK threadIDCaller
,
405 LPINTERFACEINFO lpInterfaceInfo
)
407 trace("HandleInComingCall\n");
408 return SERVERCALL_ISHANDLED
;
411 static DWORD WINAPI
MessageFilter_RetryRejectedCall(
412 IMessageFilter
*iface
,
413 HTASK threadIDCallee
,
417 trace("RetryRejectedCall\n");
421 static DWORD WINAPI
MessageFilter_MessagePending(
422 IMessageFilter
*iface
,
423 HTASK threadIDCallee
,
427 trace("MessagePending\n");
428 return PENDINGMSG_WAITNOPROCESS
;
431 static const IMessageFilterVtbl MessageFilter_Vtbl
=
433 MessageFilter_QueryInterface
,
434 MessageFilter_AddRef
,
435 MessageFilter_Release
,
436 MessageFilter_HandleInComingCall
,
437 MessageFilter_RetryRejectedCall
,
438 MessageFilter_MessagePending
441 static IMessageFilter MessageFilter
= { &MessageFilter_Vtbl
};
443 static void test_CoRegisterMessageFilter(void)
446 IMessageFilter
*prev_filter
;
448 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
449 ok(hr
== CO_E_NOT_SUPPORTED
,
450 "CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08x\n",
453 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
454 prev_filter
= (IMessageFilter
*)0xdeadbeef;
455 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
456 ok(hr
== CO_E_NOT_SUPPORTED
,
457 "CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08x\n",
459 ok(prev_filter
== (IMessageFilter
*)0xdeadbeef,
460 "prev_filter should have been set to %p\n", prev_filter
);
463 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
465 hr
= CoRegisterMessageFilter(NULL
, NULL
);
466 ok_ole_success(hr
, "CoRegisterMessageFilter");
468 prev_filter
= (IMessageFilter
*)0xdeadbeef;
469 hr
= CoRegisterMessageFilter(NULL
, &prev_filter
);
470 ok_ole_success(hr
, "CoRegisterMessageFilter");
471 ok(prev_filter
== NULL
, "prev_filter should have been set to NULL instead of %p\n", prev_filter
);
473 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
474 ok_ole_success(hr
, "CoRegisterMessageFilter");
475 ok(prev_filter
== NULL
, "prev_filter should have been set to NULL instead of %p\n", prev_filter
);
477 hr
= CoRegisterMessageFilter(NULL
, NULL
);
478 ok_ole_success(hr
, "CoRegisterMessageFilter");
483 static HRESULT WINAPI
Test_IUnknown_QueryInterface(
488 if (ppvObj
== NULL
) return E_POINTER
;
490 if (IsEqualIID(riid
, &IID_IUnknown
) ||
491 IsEqualIID(riid
, &IID_IWineTest
))
494 IUnknown_AddRef(iface
);
499 return E_NOINTERFACE
;
502 static ULONG WINAPI
Test_IUnknown_AddRef(LPUNKNOWN iface
)
504 return 2; /* non-heap-based object */
507 static ULONG WINAPI
Test_IUnknown_Release(LPUNKNOWN iface
)
509 return 1; /* non-heap-based object */
512 static const IUnknownVtbl TestUnknown_Vtbl
=
514 Test_IUnknown_QueryInterface
,
515 Test_IUnknown_AddRef
,
516 Test_IUnknown_Release
,
519 static IUnknown Test_Unknown
= { &TestUnknown_Vtbl
};
521 static HRESULT WINAPI
PSFactoryBuffer_QueryInterface(
522 IPSFactoryBuffer
* This
,
523 /* [in] */ REFIID riid
,
524 /* [iid_is][out] */ void **ppvObject
)
526 if (IsEqualIID(riid
, &IID_IUnknown
) ||
527 IsEqualIID(riid
, &IID_IPSFactoryBuffer
))
530 IPSFactoryBuffer_AddRef(This
);
533 return E_NOINTERFACE
;
536 static ULONG WINAPI
PSFactoryBuffer_AddRef(
537 IPSFactoryBuffer
* This
)
542 static ULONG WINAPI
PSFactoryBuffer_Release(
543 IPSFactoryBuffer
* This
)
548 static HRESULT WINAPI
PSFactoryBuffer_CreateProxy(
549 IPSFactoryBuffer
* This
,
550 /* [in] */ IUnknown
*pUnkOuter
,
551 /* [in] */ REFIID riid
,
552 /* [out] */ IRpcProxyBuffer
**ppProxy
,
553 /* [out] */ void **ppv
)
558 static HRESULT WINAPI
PSFactoryBuffer_CreateStub(
559 IPSFactoryBuffer
* This
,
560 /* [in] */ REFIID riid
,
561 /* [unique][in] */ IUnknown
*pUnkServer
,
562 /* [out] */ IRpcStubBuffer
**ppStub
)
567 static IPSFactoryBufferVtbl PSFactoryBufferVtbl
=
569 PSFactoryBuffer_QueryInterface
,
570 PSFactoryBuffer_AddRef
,
571 PSFactoryBuffer_Release
,
572 PSFactoryBuffer_CreateProxy
,
573 PSFactoryBuffer_CreateStub
576 static IPSFactoryBuffer PSFactoryBuffer
= { &PSFactoryBufferVtbl
};
578 static const CLSID CLSID_WineTestPSFactoryBuffer
=
583 {0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd}
584 }; /* 52011640-8164-4fd0-a1a2-5d5a3654d3bd */
586 static void test_CoRegisterPSClsid(void)
589 DWORD dwRegistrationKey
;
593 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
594 ok(hr
== CO_E_NOTINITIALIZED
, "CoRegisterPSClsid should have returened CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
596 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
598 hr
= CoRegisterClassObject(&CLSID_WineTestPSFactoryBuffer
, (IUnknown
*)&PSFactoryBuffer
,
599 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &dwRegistrationKey
);
600 ok_ole_success(hr
, "CoRegisterClassObject");
602 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
603 ok_ole_success(hr
, "CoRegisterPSClsid");
605 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
606 ok_ole_success(hr
, "CreateStreamOnHGlobal");
608 hr
= CoMarshalInterface(stream
, &IID_IWineTest
, &Test_Unknown
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
609 ok(hr
== E_NOTIMPL
, "CoMarshalInterface should have returned E_NOTIMPL instead of 0x%08x\n", hr
);
610 IStream_Release(stream
);
612 hr
= CoRevokeClassObject(dwRegistrationKey
);
613 ok_ole_success(hr
, "CoRevokeClassObject");
617 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
619 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
620 ok(hr
== REGDB_E_IIDNOTREG
, "CoGetPSClsid should have returned REGDB_E_IIDNOTREG instead of 0x%08x\n", hr
);
625 static void test_CoGetPSClsid(void)
630 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
631 ok(hr
== CO_E_NOTINITIALIZED
,
632 "CoGetPSClsid should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n",
635 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
637 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
638 ok_ole_success(hr
, "CoGetPSClsid");
640 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
641 ok(hr
== REGDB_E_IIDNOTREG
,
642 "CoGetPSClsid for random IID returned 0x%08x instead of REGDB_E_IIDNOTREG\n",
645 hr
= CoGetPSClsid(&IID_IClassFactory
, NULL
);
646 ok(hr
== E_INVALIDARG
,
647 "CoGetPSClsid for null clsid returned 0x%08x instead of E_INVALIDARG\n",
653 /* basic test, mainly for invalid arguments. see marshal.c for more */
654 static void test_CoUnmarshalInterface(void)
660 hr
= CoUnmarshalInterface(NULL
, &IID_IUnknown
, (void **)&pProxy
);
661 ok(hr
== E_INVALIDARG
, "CoUnmarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
663 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
664 ok_ole_success(hr
, "CreateStreamOnHGlobal");
666 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, (void **)&pProxy
);
668 ok(hr
== CO_E_NOTINITIALIZED
, "CoUnmarshalInterface should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
670 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
672 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, (void **)&pProxy
);
673 ok(hr
== STG_E_READFAULT
, "CoUnmarshalInterface should have returned STG_E_READFAULT instead of 0x%08x\n", hr
);
677 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, NULL
);
678 ok(hr
== E_INVALIDARG
, "CoUnmarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
680 IStream_Release(pStream
);
683 static void test_CoGetInterfaceAndReleaseStream(void)
688 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
690 hr
= CoGetInterfaceAndReleaseStream(NULL
, &IID_IUnknown
, (void**)&pUnk
);
691 ok(hr
== E_INVALIDARG
, "hr %08x\n", hr
);
696 /* basic test, mainly for invalid arguments. see marshal.c for more */
697 static void test_CoMarshalInterface(void)
701 static const LARGE_INTEGER llZero
;
703 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
705 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
706 ok_ole_success(hr
, "CreateStreamOnHGlobal");
708 hr
= CoMarshalInterface(pStream
, &IID_IUnknown
, NULL
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
709 ok(hr
== E_INVALIDARG
, "CoMarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
711 hr
= CoMarshalInterface(NULL
, &IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
712 ok(hr
== E_INVALIDARG
, "CoMarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
714 hr
= CoMarshalInterface(pStream
, &IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
715 ok_ole_success(hr
, "CoMarshalInterface");
717 /* stream not rewound */
718 hr
= CoReleaseMarshalData(pStream
);
719 ok(hr
== STG_E_READFAULT
, "CoReleaseMarshalData should have returned STG_E_READFAULT instead of 0x%08x\n", hr
);
721 hr
= IStream_Seek(pStream
, llZero
, STREAM_SEEK_SET
, NULL
);
722 ok_ole_success(hr
, "IStream_Seek");
724 hr
= CoReleaseMarshalData(pStream
);
725 ok_ole_success(hr
, "CoReleaseMarshalData");
727 IStream_Release(pStream
);
732 static void test_CoMarshalInterThreadInterfaceInStream(void)
736 IClassFactory
*pProxy
;
738 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
742 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, NULL
);
743 ok(hr
== E_INVALIDARG
, "CoMarshalInterThreadInterfaceInStream should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
745 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, NULL
, &pStream
);
746 ok(hr
== E_INVALIDARG
, "CoMarshalInterThreadInterfaceInStream should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
750 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, &pStream
);
751 ok_ole_success(hr
, "CoMarshalInterThreadInterfaceInStream");
753 ok_more_than_one_lock();
755 hr
= CoUnmarshalInterface(pStream
, &IID_IClassFactory
, (void **)&pProxy
);
756 ok_ole_success(hr
, "CoUnmarshalInterface");
758 IClassFactory_Release(pProxy
);
759 IStream_Release(pStream
);
766 static void test_CoRegisterClassObject(void)
772 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
774 /* CLSCTX_INPROC_SERVER */
775 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
776 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
777 ok_ole_success(hr
, "CoRegisterClassObject");
778 hr
= CoRevokeClassObject(cookie
);
779 ok_ole_success(hr
, "CoRevokeClassObject");
781 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
782 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
783 ok_ole_success(hr
, "CoRegisterClassObject");
784 hr
= CoRevokeClassObject(cookie
);
785 ok_ole_success(hr
, "CoRevokeClassObject");
787 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
788 CLSCTX_INPROC_SERVER
, REGCLS_MULTI_SEPARATE
, &cookie
);
789 ok_ole_success(hr
, "CoRegisterClassObject");
790 hr
= CoRevokeClassObject(cookie
);
791 ok_ole_success(hr
, "CoRevokeClassObject");
793 /* CLSCTX_LOCAL_SERVER */
794 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
795 CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
796 ok_ole_success(hr
, "CoRegisterClassObject");
797 hr
= CoRevokeClassObject(cookie
);
798 ok_ole_success(hr
, "CoRevokeClassObject");
800 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
801 CLSCTX_LOCAL_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
802 ok_ole_success(hr
, "CoRegisterClassObject");
803 hr
= CoRevokeClassObject(cookie
);
804 ok_ole_success(hr
, "CoRevokeClassObject");
806 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
807 CLSCTX_LOCAL_SERVER
, REGCLS_MULTI_SEPARATE
, &cookie
);
808 ok_ole_success(hr
, "CoRegisterClassObject");
809 hr
= CoRevokeClassObject(cookie
);
810 ok_ole_success(hr
, "CoRevokeClassObject");
812 /* CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER */
813 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
814 CLSCTX_INPROC_SERVER
|CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
815 ok_ole_success(hr
, "CoRegisterClassObject");
816 hr
= CoRevokeClassObject(cookie
);
817 ok_ole_success(hr
, "CoRevokeClassObject");
819 /* test whether registered class becomes invalid when apartment is destroyed */
820 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
821 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
822 ok_ole_success(hr
, "CoRegisterClassObject");
825 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
827 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
,
828 &IID_IClassFactory
, (void **)&pcf
);
829 ok(hr
== REGDB_E_CLASSNOTREG
, "object registered in an apartment shouldn't accessible after it is destroyed\n");
831 /* crashes with at least win9x DCOM! */
833 hr
= CoRevokeClassObject(cookie
);
838 static HRESULT
get_class_object(CLSCTX clsctx
)
843 hr
= CoGetClassObject(&CLSID_WineOOPTest
, clsctx
, NULL
, &IID_IClassFactory
,
847 IClassFactory_Release(pcf
);
852 static DWORD CALLBACK
get_class_object_thread(LPVOID pv
)
854 CLSCTX clsctx
= (CLSCTX
)(DWORD_PTR
)pv
;
857 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
859 hr
= get_class_object(clsctx
);
866 static DWORD CALLBACK
get_class_object_proxy_thread(LPVOID pv
)
868 CLSCTX clsctx
= (CLSCTX
)(DWORD_PTR
)pv
;
873 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
875 hr
= CoGetClassObject(&CLSID_WineOOPTest
, clsctx
, NULL
, &IID_IClassFactory
,
880 hr
= IClassFactory_QueryInterface(pcf
, &IID_IMultiQI
, (void **)&pMQI
);
882 IMultiQI_Release(pMQI
);
883 IClassFactory_Release(pcf
);
891 static DWORD CALLBACK
register_class_object_thread(LPVOID pv
)
896 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
898 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
899 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
906 static DWORD CALLBACK
revoke_class_object_thread(LPVOID pv
)
908 DWORD cookie
= (DWORD_PTR
)pv
;
911 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
913 hr
= CoRevokeClassObject(cookie
);
920 static void test_registered_object_thread_affinity(void)
928 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
930 /* CLSCTX_INPROC_SERVER */
932 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
933 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
934 ok_ole_success(hr
, "CoRegisterClassObject");
936 thread
= CreateThread(NULL
, 0, get_class_object_thread
, (LPVOID
)CLSCTX_INPROC_SERVER
, 0, &tid
);
937 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
938 WaitForSingleObject(thread
, INFINITE
);
939 GetExitCodeThread(thread
, &exitcode
);
941 ok(hr
== REGDB_E_CLASSNOTREG
, "CoGetClassObject on inproc object "
942 "registered in different thread should return REGDB_E_CLASSNOTREG "
943 "instead of 0x%08x\n", hr
);
945 hr
= get_class_object(CLSCTX_INPROC_SERVER
);
946 ok(hr
== S_OK
, "CoGetClassObject on inproc object registered in same "
947 "thread should return S_OK instead of 0x%08x\n", hr
);
949 thread
= CreateThread(NULL
, 0, register_class_object_thread
, NULL
, 0, &tid
);
950 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
951 WaitForSingleObject(thread
, INFINITE
);
952 GetExitCodeThread(thread
, &exitcode
);
954 ok(hr
== S_OK
, "CoRegisterClassObject with same CLSID but in different thread should return S_OK instead of 0x%08x\n", hr
);
956 hr
= CoRevokeClassObject(cookie
);
957 ok_ole_success(hr
, "CoRevokeClassObject");
959 /* CLSCTX_LOCAL_SERVER */
961 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
962 CLSCTX_LOCAL_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
963 ok_ole_success(hr
, "CoRegisterClassObject");
965 thread
= CreateThread(NULL
, 0, get_class_object_proxy_thread
, (LPVOID
)CLSCTX_LOCAL_SERVER
, 0, &tid
);
966 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
967 while (MsgWaitForMultipleObjects(1, &thread
, FALSE
, INFINITE
, QS_ALLINPUT
) == WAIT_OBJECT_0
+ 1)
970 while (PeekMessageA(&msg
, NULL
, 0, 0, PM_REMOVE
))
972 TranslateMessage(&msg
);
973 DispatchMessageA(&msg
);
976 GetExitCodeThread(thread
, &exitcode
);
978 ok(hr
== S_OK
, "CoGetClassObject on local server object "
979 "registered in different thread should return S_OK "
980 "instead of 0x%08x\n", hr
);
982 hr
= get_class_object(CLSCTX_LOCAL_SERVER
);
983 ok(hr
== S_OK
, "CoGetClassObject on local server object registered in same "
984 "thread should return S_OK instead of 0x%08x\n", hr
);
986 thread
= CreateThread(NULL
, 0, revoke_class_object_thread
, (LPVOID
)(DWORD_PTR
)cookie
, 0, &tid
);
987 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
988 WaitForSingleObject(thread
, INFINITE
);
989 GetExitCodeThread(thread
, &exitcode
);
991 ok(hr
== RPC_E_WRONG_THREAD
, "CoRevokeClassObject called from different "
992 "thread to where registered should return RPC_E_WRONG_THREAD instead of 0x%08x\n", hr
);
994 thread
= CreateThread(NULL
, 0, register_class_object_thread
, NULL
, 0, &tid
);
995 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
996 WaitForSingleObject(thread
, INFINITE
);
997 GetExitCodeThread(thread
, &exitcode
);
999 ok(hr
== S_OK
, "CoRegisterClassObject with same CLSID but in different "
1000 "thread should return S_OK instead of 0x%08x\n", hr
);
1002 hr
= CoRevokeClassObject(cookie
);
1003 ok_ole_success(hr
, "CoRevokeClassObject");
1008 static DWORD CALLBACK
free_libraries_thread(LPVOID p
)
1010 CoFreeUnusedLibraries();
1014 static inline BOOL
is_module_loaded(const char *module
)
1016 return GetModuleHandle(module
) ? TRUE
: FALSE
;
1019 static void test_CoFreeUnusedLibraries(void)
1026 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1028 ok(!is_module_loaded("urlmon.dll"), "urlmon.dll shouldn't be loaded\n");
1030 hr
= CoCreateInstance(&CLSID_FileProtocol
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IInternetProtocol
, (void **)&pUnk
);
1031 if (hr
== REGDB_E_CLASSNOTREG
)
1033 trace("IE not installed so can't run CoFreeUnusedLibraries test\n");
1037 ok_ole_success(hr
, "CoCreateInstance");
1039 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1042 broken(pUnk
== NULL
), /* win9x */
1043 "Expected a valid pointer\n");
1045 IUnknown_Release(pUnk
);
1047 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1049 thread
= CreateThread(NULL
, 0, free_libraries_thread
, NULL
, 0, &tid
);
1050 WaitForSingleObject(thread
, INFINITE
);
1051 CloseHandle(thread
);
1053 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1055 CoFreeUnusedLibraries();
1057 ok(!is_module_loaded("urlmon.dll"), "urlmon.dll shouldn't be loaded\n");
1062 static void test_CoGetObjectContext(void)
1066 IComThreadingInfo
*pComThreadingInfo
;
1067 IContextCallback
*pContextCallback
;
1071 if (!pCoGetObjectContext
)
1073 skip("CoGetObjectContext not present\n");
1077 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1078 ok(hr
== CO_E_NOTINITIALIZED
, "CoGetObjectContext should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
1079 ok(pComThreadingInfo
== NULL
, "pComThreadingInfo should have been set to NULL\n");
1081 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1083 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1084 ok_ole_success(hr
, "CoGetObjectContext");
1086 hr
= IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo
, &apttype
);
1087 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentApartmentType");
1088 ok(apttype
== APTTYPE_MAINSTA
, "apartment type should be APTTYPE_MAINSTA instead of %d\n", apttype
);
1090 hr
= IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo
, &thdtype
);
1091 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentThreadType");
1092 ok(thdtype
== THDTYPE_PROCESSMESSAGES
, "thread type should be THDTYPE_PROCESSMESSAGES instead of %d\n", thdtype
);
1094 refs
= IComThreadingInfo_Release(pComThreadingInfo
);
1095 ok(refs
== 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs
);
1097 hr
= pCoGetObjectContext(&IID_IContextCallback
, (void **)&pContextCallback
);
1098 ok_ole_success(hr
, "CoGetObjectContext(ContextCallback)");
1102 refs
= IContextCallback_Release(pContextCallback
);
1103 ok(refs
== 0, "pContextCallback should have 0 refs instead of %d refs\n", refs
);
1108 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
1110 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1111 ok_ole_success(hr
, "CoGetObjectContext");
1113 hr
= IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo
, &apttype
);
1114 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentApartmentType");
1115 ok(apttype
== APTTYPE_MTA
, "apartment type should be APTTYPE_MTA instead of %d\n", apttype
);
1117 hr
= IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo
, &thdtype
);
1118 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentThreadType");
1119 ok(thdtype
== THDTYPE_BLOCKMESSAGES
, "thread type should be THDTYPE_BLOCKMESSAGES instead of %d\n", thdtype
);
1121 refs
= IComThreadingInfo_Release(pComThreadingInfo
);
1122 ok(refs
== 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs
);
1124 hr
= pCoGetObjectContext(&IID_IContextCallback
, (void **)&pContextCallback
);
1125 ok_ole_success(hr
, "CoGetObjectContext(ContextCallback)");
1129 refs
= IContextCallback_Release(pContextCallback
);
1130 ok(refs
== 0, "pContextCallback should have 0 refs instead of %d refs\n", refs
);
1137 const IUnknownVtbl
*lpVtbl
;
1141 static HRESULT WINAPI
Test_CallContext_QueryInterface(
1146 if (ppvObj
== NULL
) return E_POINTER
;
1148 if (IsEqualGUID(riid
, &IID_IUnknown
))
1151 IUnknown_AddRef(iface
);
1156 return E_NOINTERFACE
;
1159 static ULONG WINAPI
Test_CallContext_AddRef(IUnknown
*iface
)
1161 Test_CallContext
*This
= (Test_CallContext
*)iface
;
1162 return InterlockedIncrement(&This
->refs
);
1165 static ULONG WINAPI
Test_CallContext_Release(IUnknown
*iface
)
1167 Test_CallContext
*This
= (Test_CallContext
*)iface
;
1168 ULONG refs
= InterlockedDecrement(&This
->refs
);
1170 HeapFree(GetProcessHeap(), 0, This
);
1174 static const IUnknownVtbl TestCallContext_Vtbl
=
1176 Test_CallContext_QueryInterface
,
1177 Test_CallContext_AddRef
,
1178 Test_CallContext_Release
1181 static void test_CoGetCallContext(void)
1186 IUnknown
*test_object
;
1188 if (!pCoSwitchCallContext
)
1190 skip("CoSwitchCallContext not present\n");
1196 test_object
= HeapAlloc(GetProcessHeap(), 0, sizeof(Test_CallContext
));
1197 ((Test_CallContext
*)test_object
)->lpVtbl
= &TestCallContext_Vtbl
;
1198 ((Test_CallContext
*)test_object
)->refs
= 1;
1200 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
1201 ok(hr
== RPC_E_CALL_COMPLETE
, "Expected RPC_E_CALL_COMPLETE, got 0x%08x\n", hr
);
1203 pUnk
= (IUnknown
*)0xdeadbeef;
1204 hr
= pCoSwitchCallContext(test_object
, &pUnk
);
1205 ok_ole_success(hr
, "CoSwitchCallContext");
1206 ok(pUnk
== NULL
, "expected NULL, got %p\n", pUnk
);
1207 refs
= IUnknown_AddRef(test_object
);
1208 ok(refs
== 2, "Expected refcount 2, got %d\n", refs
);
1209 IUnknown_Release(test_object
);
1211 pUnk
= (IUnknown
*)0xdeadbeef;
1212 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
1213 ok_ole_success(hr
, "CoGetCallContext");
1214 ok(pUnk
== test_object
, "expected %p, got %p\n", test_object
, pUnk
);
1215 refs
= IUnknown_AddRef(test_object
);
1216 ok(refs
== 3, "Expected refcount 3, got %d\n", refs
);
1217 IUnknown_Release(test_object
);
1218 IUnknown_Release(pUnk
);
1220 pUnk
= (IUnknown
*)0xdeadbeef;
1221 hr
= pCoSwitchCallContext(NULL
, &pUnk
);
1222 ok_ole_success(hr
, "CoSwitchCallContext");
1223 ok(pUnk
== test_object
, "expected %p, got %p\n", test_object
, pUnk
);
1224 refs
= IUnknown_AddRef(test_object
);
1225 ok(refs
== 2, "Expected refcount 2, got %d\n", refs
);
1226 IUnknown_Release(test_object
);
1228 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
1229 ok(hr
== RPC_E_CALL_COMPLETE
, "Expected RPC_E_CALL_COMPLETE, got 0x%08x\n", hr
);
1231 IUnknown_Release(test_object
);
1236 static void test_CoGetTreatAsClass(void)
1240 static GUID deadbeef
= {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
1242 if (!pCoGetTreatAsClass
)
1244 win_skip("CoGetTreatAsClass not present\n");
1247 hr
= pCoGetTreatAsClass(&deadbeef
,&out
);
1248 ok (hr
== S_FALSE
, "expected S_FALSE got %x\n",hr
);
1249 ok (IsEqualGUID(&out
,&deadbeef
), "expected to get same clsid back\n");
1252 static void test_CoInitializeEx(void)
1256 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1257 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
1259 /* Calling OleInitialize for the first time should yield S_OK even with
1260 * apartment already initialized by previous CoInitialize(Ex) calls. */
1261 hr
= OleInitialize(NULL
);
1262 todo_wine
ok(hr
== S_OK
, "OleInitialize failed with error 0x%08x\n", hr
);
1264 /* Subsequent calls to OleInitialize should return S_FALSE */
1265 hr
= OleInitialize(NULL
);
1266 ok(hr
== S_FALSE
, "Expected S_FALSE, hr = 0x%08x\n", hr
);
1275 HMODULE hOle32
= GetModuleHandle("ole32");
1276 pCoGetObjectContext
= (void*)GetProcAddress(hOle32
, "CoGetObjectContext");
1277 pCoSwitchCallContext
= (void*)GetProcAddress(hOle32
, "CoSwitchCallContext");
1278 pCoGetTreatAsClass
= (void*)GetProcAddress(hOle32
,"CoGetTreatAsClass");
1279 if (!(pCoInitializeEx
= (void*)GetProcAddress(hOle32
, "CoInitializeEx")))
1281 trace("You need DCOM95 installed to run this test\n");
1285 test_ProgIDFromCLSID();
1286 test_CLSIDFromProgID();
1287 test_CLSIDFromString();
1288 test_StringFromGUID2();
1289 test_CoCreateInstance();
1291 test_CoGetClassObject();
1292 test_CoRegisterMessageFilter();
1293 test_CoRegisterPSClsid();
1294 test_CoGetPSClsid();
1295 test_CoUnmarshalInterface();
1296 test_CoGetInterfaceAndReleaseStream();
1297 test_CoMarshalInterface();
1298 test_CoMarshalInterThreadInterfaceInStream();
1299 test_CoRegisterClassObject();
1300 test_registered_object_thread_affinity();
1301 test_CoFreeUnusedLibraries();
1302 test_CoGetObjectContext();
1303 test_CoGetCallContext();
1304 test_CoGetTreatAsClass();
1305 test_CoInitializeEx();