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
21 #define WIN32_NO_STATUS
23 #define COM_NO_WINDOWS_H
35 #define USE_COM_CONTEXT_DEF
37 //#include "objbase.h"
38 //#include "shlguid.h"
40 #include <urlmon.h> /* for CLSID_FileProtocol */
45 #include <wine/test.h>
47 extern const IID GUID_NULL
;
49 #define DEFINE_EXPECT(func) \
50 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
52 #define SET_EXPECT(func) \
53 expect_ ## func = TRUE
55 #define CHECK_EXPECT2(func) \
57 ok(expect_ ##func, "unexpected call " #func "\n"); \
58 called_ ## func = TRUE; \
61 #define CHECK_EXPECT(func) \
63 CHECK_EXPECT2(func); \
64 expect_ ## func = FALSE; \
67 #define CHECK_CALLED(func) \
69 ok(called_ ## func, "expected " #func "\n"); \
70 expect_ ## func = called_ ## func = FALSE; \
73 DEFINE_EXPECT(CreateStub
);
75 /* functions that are not present on all versions of Windows */
76 static HRESULT (WINAPI
* pCoInitializeEx
)(LPVOID lpReserved
, DWORD dwCoInit
);
77 static HRESULT (WINAPI
* pCoGetObjectContext
)(REFIID riid
, LPVOID
*ppv
);
78 static HRESULT (WINAPI
* pCoSwitchCallContext
)(IUnknown
*pObject
, IUnknown
**ppOldObject
);
79 static HRESULT (WINAPI
* pCoGetTreatAsClass
)(REFCLSID clsidOld
, LPCLSID pClsidNew
);
80 static HRESULT (WINAPI
* pCoTreatAsClass
)(REFCLSID clsidOld
, REFCLSID pClsidNew
);
81 static HRESULT (WINAPI
* pCoGetContextToken
)(ULONG_PTR
*token
);
82 static LONG (WINAPI
* pRegDeleteKeyExA
)(HKEY
, LPCSTR
, REGSAM
, DWORD
);
83 static LONG (WINAPI
* pRegOverridePredefKey
)(HKEY key
, HKEY override
);
85 static BOOL (WINAPI
*pActivateActCtx
)(HANDLE
,ULONG_PTR
*);
86 static HANDLE (WINAPI
*pCreateActCtxW
)(PCACTCTXW
);
87 static BOOL (WINAPI
*pDeactivateActCtx
)(DWORD
,ULONG_PTR
);
88 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
, LPBOOL
);
89 static void (WINAPI
*pReleaseActCtx
)(HANDLE
);
91 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
92 #define ok_more_than_one_lock() ok(cLocks > 0, "Number of locks should be > 0, but actually is %d\n", cLocks)
93 #define ok_no_locks() ok(cLocks == 0, "Number of locks should be 0, but actually is %d\n", cLocks)
95 static const CLSID CLSID_non_existent
= { 0x12345678, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
96 static const CLSID CLSID_StdFont
= { 0x0be35203, 0x8f91, 0x11ce, { 0x9d, 0xe3, 0x00, 0xaa, 0x00, 0x4b, 0xb8, 0x51 } };
97 static const GUID IID_Testiface
= { 0x22222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
98 static const GUID IID_Testiface2
= { 0x32222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
99 static const GUID IID_Testiface3
= { 0x42222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
100 static const GUID IID_Testiface4
= { 0x52222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
101 static const GUID IID_Testiface5
= { 0x62222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
102 static const GUID IID_Testiface6
= { 0x72222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
103 static const GUID IID_TestPS
= { 0x66666666, 0x8888, 0x7777, { 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 } };
105 DEFINE_GUID(CLSID_InProcFreeMarshaler
, 0x0000033a,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
107 static const WCHAR stdfont
[] = {'S','t','d','F','o','n','t',0};
108 static const WCHAR wszNonExistent
[] = {'N','o','n','E','x','i','s','t','e','n','t',0};
109 static const WCHAR wszCLSID_StdFont
[] =
111 '{','0','b','e','3','5','2','0','3','-','8','f','9','1','-','1','1','c','e','-',
112 '9','d','e','3','-','0','0','a','a','0','0','4','b','b','8','5','1','}',0
114 static const WCHAR progidW
[] = {'P','r','o','g','I','d','.','P','r','o','g','I','d',0};
115 static const WCHAR cf_brokenW
[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-',
116 'c','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}','a',0};
118 DEFINE_GUID(IID_IWineTest
, 0x5201163f, 0x8164, 0x4fd0, 0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd);
119 DEFINE_GUID(CLSID_WineOOPTest
, 0x5201163f, 0x8164, 0x4fd0, 0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd);
123 static void LockModule(void)
125 InterlockedIncrement(&cLocks
);
128 static void UnlockModule(void)
130 InterlockedDecrement(&cLocks
);
133 static HRESULT WINAPI
Test_IClassFactory_QueryInterface(
134 LPCLASSFACTORY iface
,
138 if (ppvObj
== NULL
) return E_POINTER
;
140 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
141 IsEqualGUID(riid
, &IID_IClassFactory
))
144 IClassFactory_AddRef(iface
);
149 return E_NOINTERFACE
;
152 static ULONG WINAPI
Test_IClassFactory_AddRef(LPCLASSFACTORY iface
)
155 return 2; /* non-heap-based object */
158 static ULONG WINAPI
Test_IClassFactory_Release(LPCLASSFACTORY iface
)
161 return 1; /* non-heap-based object */
164 static IID create_instance_iid
;
165 static HRESULT WINAPI
Test_IClassFactory_CreateInstance(
166 LPCLASSFACTORY iface
,
172 create_instance_iid
= *riid
;
173 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
174 return E_NOINTERFACE
;
177 static HRESULT WINAPI
Test_IClassFactory_LockServer(
178 LPCLASSFACTORY iface
,
184 static const IClassFactoryVtbl TestClassFactory_Vtbl
=
186 Test_IClassFactory_QueryInterface
,
187 Test_IClassFactory_AddRef
,
188 Test_IClassFactory_Release
,
189 Test_IClassFactory_CreateInstance
,
190 Test_IClassFactory_LockServer
193 static IClassFactory Test_ClassFactory
= { &TestClassFactory_Vtbl
};
195 static WCHAR manifest_path
[MAX_PATH
];
197 static BOOL
create_manifest_file(const char *filename
, const char *manifest
)
202 WCHAR path
[MAX_PATH
];
204 MultiByteToWideChar( CP_ACP
, 0, filename
, -1, path
, MAX_PATH
);
205 GetFullPathNameW(path
, sizeof(manifest_path
)/sizeof(WCHAR
), manifest_path
, NULL
);
207 manifest_len
= strlen(manifest
);
208 file
= CreateFileW(path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
209 FILE_ATTRIBUTE_NORMAL
, NULL
);
210 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed: %u\n", GetLastError());
211 if(file
== INVALID_HANDLE_VALUE
)
213 WriteFile(file
, manifest
, manifest_len
, &size
, NULL
);
219 static HANDLE
activate_context(const char *manifest
, ULONG_PTR
*cookie
)
221 WCHAR path
[MAX_PATH
];
226 if (!pCreateActCtxW
) return NULL
;
228 create_manifest_file("file.manifest", manifest
);
230 MultiByteToWideChar( CP_ACP
, 0, "file.manifest", -1, path
, MAX_PATH
);
231 memset(&actctx
, 0, sizeof(ACTCTXW
));
232 actctx
.cbSize
= sizeof(ACTCTXW
);
233 actctx
.lpSource
= path
;
235 handle
= pCreateActCtxW(&actctx
);
236 ok(handle
!= INVALID_HANDLE_VALUE
|| broken(handle
== INVALID_HANDLE_VALUE
) /* some old XP/2k3 versions */,
237 "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
238 if (handle
== INVALID_HANDLE_VALUE
)
240 win_skip("activation context generation failed, some tests will be skipped\n");
244 ok(actctx
.cbSize
== sizeof(ACTCTXW
), "actctx.cbSize=%d\n", actctx
.cbSize
);
245 ok(actctx
.dwFlags
== 0, "actctx.dwFlags=%d\n", actctx
.dwFlags
);
246 ok(actctx
.lpSource
== path
, "actctx.lpSource=%p\n", actctx
.lpSource
);
247 ok(actctx
.wProcessorArchitecture
== 0, "actctx.wProcessorArchitecture=%d\n", actctx
.wProcessorArchitecture
);
248 ok(actctx
.wLangId
== 0, "actctx.wLangId=%d\n", actctx
.wLangId
);
249 ok(actctx
.lpAssemblyDirectory
== NULL
, "actctx.lpAssemblyDirectory=%p\n", actctx
.lpAssemblyDirectory
);
250 ok(actctx
.lpResourceName
== NULL
, "actctx.lpResourceName=%p\n", actctx
.lpResourceName
);
251 ok(actctx
.lpApplicationName
== NULL
, "actctx.lpApplicationName=%p\n", actctx
.lpApplicationName
);
252 ok(actctx
.hModule
== NULL
, "actctx.hModule=%p\n", actctx
.hModule
);
254 DeleteFileA("file.manifest");
258 ret
= pActivateActCtx(handle
, cookie
);
259 ok(ret
, "ActivateActCtx failed: %u\n", GetLastError());
265 static const char actctx_manifest
[] =
266 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
267 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\""
268 " publicKeyToken=\"6595b6414666f1df\" />"
269 "<file name=\"testlib.dll\">"
271 " clsid=\"{0000033a-0000-0000-c000-000000000046}\""
272 " progid=\"FTMarshal\""
275 " clsid=\"{5201163f-8164-4fd0-a1a2-5d5a3654d3bd}\""
276 " progid=\"WineOOPTest\""
278 " <comClass description=\"Test com class\""
279 " clsid=\"{12345678-1234-1234-1234-56789abcdef0}\""
280 " progid=\"ProgId.ProgId\""
281 " miscStatusIcon=\"recomposeonresize\""
283 " <comClass clsid=\"{0be35203-8f91-11ce-9de3-00aa004bb851}\""
284 " progid=\"CustomFont\""
285 " miscStatusIcon=\"recomposeonresize\""
286 " miscStatusContent=\"insideout\""
288 " <comClass clsid=\"{0be35203-8f91-11ce-9de3-00aa004bb852}\""
289 " progid=\"StdFont\""
291 " <comClass clsid=\"{62222222-1234-1234-1234-56789abcdef0}\" >"
292 " <progid>ProgId.ProgId.1</progid>"
294 " <comInterfaceProxyStub "
296 " iid=\"{22222222-1234-1234-1234-56789abcdef0}\""
297 " proxyStubClsid32=\"{66666666-8888-7777-6666-555555555555}\""
300 " <comInterfaceExternalProxyStub "
301 " name=\"Iifaceps2\""
302 " iid=\"{32222222-1234-1234-1234-56789abcdef0}\""
304 " <comInterfaceExternalProxyStub "
305 " name=\"Iifaceps3\""
306 " iid=\"{42222222-1234-1234-1234-56789abcdef0}\""
307 " proxyStubClsid32=\"{66666666-8888-7777-6666-555555555555}\""
309 " <comInterfaceExternalProxyStub "
310 " name=\"Iifaceps4\""
311 " iid=\"{52222222-1234-1234-1234-56789abcdef0}\""
312 " proxyStubClsid32=\"{00000000-0000-0000-0000-000000000000}\""
315 " clsid=\"{72222222-1234-1234-1234-56789abcdef0}\""
318 " <progid>clrprogid.1</progid>"
322 DEFINE_GUID(CLSID_Testclass
, 0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0);
324 static void test_ProgIDFromCLSID(void)
326 ULONG_PTR cookie
= 0;
331 hr
= ProgIDFromCLSID(&CLSID_StdFont
, &progid
);
332 ok(hr
== S_OK
, "ProgIDFromCLSID failed with error 0x%08x\n", hr
);
335 ok(!lstrcmpiW(progid
, stdfont
), "Didn't get expected prog ID\n");
336 CoTaskMemFree(progid
);
339 progid
= (LPWSTR
)0xdeadbeef;
340 hr
= ProgIDFromCLSID(&CLSID_non_existent
, &progid
);
341 ok(hr
== REGDB_E_CLASSNOTREG
, "ProgIDFromCLSID returned %08x\n", hr
);
342 ok(progid
== NULL
, "ProgIDFromCLSID returns with progid %p\n", progid
);
344 hr
= ProgIDFromCLSID(&CLSID_StdFont
, NULL
);
345 ok(hr
== E_INVALIDARG
, "ProgIDFromCLSID should return E_INVALIDARG instead of 0x%08x\n", hr
);
347 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
349 static const WCHAR customfontW
[] = {'C','u','s','t','o','m','F','o','n','t',0};
351 hr
= ProgIDFromCLSID(&CLSID_non_existent
, &progid
);
352 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
353 ok(!lstrcmpiW(progid
, progidW
), "got %s\n", wine_dbgstr_w(progid
));
354 CoTaskMemFree(progid
);
356 /* try something registered and redirected */
358 hr
= ProgIDFromCLSID(&CLSID_StdFont
, &progid
);
359 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
360 ok(!lstrcmpiW(progid
, customfontW
), "got wrong progid %s\n", wine_dbgstr_w(progid
));
361 CoTaskMemFree(progid
);
363 /* classes without default progid, progid list is not used */
364 hr
= ProgIDFromCLSID(&IID_Testiface5
, &progid
);
365 ok(hr
== REGDB_E_CLASSNOTREG
, "got 0x%08x\n", hr
);
367 hr
= ProgIDFromCLSID(&IID_Testiface6
, &progid
);
368 ok(hr
== REGDB_E_CLASSNOTREG
, "got 0x%08x\n", hr
);
370 pDeactivateActCtx(0, cookie
);
371 pReleaseActCtx(handle
);
375 static void test_CLSIDFromProgID(void)
377 ULONG_PTR cookie
= 0;
380 HRESULT hr
= CLSIDFromProgID(stdfont
, &clsid
);
381 ok(hr
== S_OK
, "CLSIDFromProgID failed with error 0x%08x\n", hr
);
382 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
384 hr
= CLSIDFromString(stdfont
, &clsid
);
385 ok_ole_success(hr
, "CLSIDFromString");
386 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
388 /* test some failure cases */
390 hr
= CLSIDFromProgID(wszNonExistent
, NULL
);
391 ok(hr
== E_INVALIDARG
, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
393 hr
= CLSIDFromProgID(NULL
, &clsid
);
394 ok(hr
== E_INVALIDARG
, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
396 memset(&clsid
, 0xcc, sizeof(clsid
));
397 hr
= CLSIDFromProgID(wszNonExistent
, &clsid
);
398 ok(hr
== CO_E_CLASSSTRING
, "CLSIDFromProgID on nonexistent ProgID should have returned CO_E_CLASSSTRING instead of 0x%08x\n", hr
);
399 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "CLSIDFromProgID should have set clsid to all-zeros on failure\n");
401 /* fails without proper context */
402 memset(&clsid
, 0xcc, sizeof(clsid
));
403 hr
= CLSIDFromProgID(progidW
, &clsid
);
404 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
405 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "wrong clsid\n");
407 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
411 memset(&clsid
, 0xcc, sizeof(clsid
));
412 hr
= CLSIDFromProgID(wszNonExistent
, &clsid
);
413 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
414 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "should have zero CLSID on failure\n");
416 /* CLSIDFromString() doesn't check activation context */
417 hr
= CLSIDFromString(progidW
, &clsid
);
418 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
421 hr
= CLSIDFromProgID(progidW
, &clsid
);
422 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
423 /* it returns generated CLSID here */
424 ok(!IsEqualCLSID(&clsid
, &CLSID_non_existent
) && !IsEqualCLSID(&clsid
, &CLSID_NULL
),
425 "got wrong clsid %s\n", wine_dbgstr_guid(&clsid
));
427 /* duplicate progid present in context - returns generated guid here too */
429 hr
= CLSIDFromProgID(stdfont
, &clsid
);
430 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
431 clsid1
= CLSID_StdFont
;
432 /* that's where it differs from StdFont */
433 clsid1
.Data4
[7] = 0x52;
434 ok(!IsEqualCLSID(&clsid
, &CLSID_StdFont
) && !IsEqualCLSID(&clsid
, &CLSID_NULL
) && !IsEqualCLSID(&clsid
, &clsid1
),
435 "got %s\n", wine_dbgstr_guid(&clsid
));
437 pDeactivateActCtx(0, cookie
);
438 pReleaseActCtx(handle
);
442 static void test_CLSIDFromString(void)
445 WCHAR wszCLSID_Broken
[50];
448 HRESULT hr
= CLSIDFromString(wszCLSID_StdFont
, &clsid
);
449 ok_ole_success(hr
, "CLSIDFromString");
450 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
452 memset(&clsid
, 0xab, sizeof(clsid
));
453 hr
= CLSIDFromString(NULL
, &clsid
);
454 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
455 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "clsid wasn't equal to CLSID_NULL\n");
457 /* string is longer, but starts with a valid CLSID */
458 memset(&clsid
, 0, sizeof(clsid
));
459 hr
= CLSIDFromString(cf_brokenW
, &clsid
);
460 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
461 ok(IsEqualCLSID(&clsid
, &IID_IClassFactory
), "got %s\n", wine_dbgstr_guid(&clsid
));
463 lstrcpyW(wszCLSID_Broken
, wszCLSID_StdFont
);
464 for(i
= lstrlenW(wszCLSID_StdFont
); i
< 49; i
++)
465 wszCLSID_Broken
[i
] = 'A';
466 wszCLSID_Broken
[i
] = '\0';
468 memset(&clsid
, 0, sizeof(CLSID
));
469 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
470 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
471 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
473 wszCLSID_Broken
[lstrlenW(wszCLSID_StdFont
)-1] = 'A';
474 memset(&clsid
, 0, sizeof(CLSID
));
475 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
476 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
477 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
479 wszCLSID_Broken
[lstrlenW(wszCLSID_StdFont
)] = '\0';
480 memset(&clsid
, 0, sizeof(CLSID
));
481 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
482 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
483 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
485 wszCLSID_Broken
[lstrlenW(wszCLSID_StdFont
)-1] = '\0';
486 memset(&clsid
, 0, sizeof(CLSID
));
487 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
488 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
489 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
491 memset(&clsid
, 0xcc, sizeof(CLSID
));
492 hr
= CLSIDFromString(wszCLSID_Broken
+1, &clsid
);
493 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
494 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "clsid wasn't equal to CLSID_NULL\n");
496 wszCLSID_Broken
[9] = '*';
497 memset(&clsid
, 0xcc, sizeof(CLSID
));
498 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
499 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
500 ok(clsid
.Data1
== CLSID_StdFont
.Data1
, "Got %08x\n", clsid
.Data1
);
501 ok(clsid
.Data2
== 0xcccc, "Got %04x\n", clsid
.Data2
);
503 wszCLSID_Broken
[3] = '*';
504 memset(&clsid
, 0xcc, sizeof(CLSID
));
505 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
506 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
507 ok(clsid
.Data1
== 0xb, "Got %08x\n", clsid
.Data1
);
508 ok(clsid
.Data2
== 0xcccc, "Got %04x\n", clsid
.Data2
);
510 wszCLSID_Broken
[3] = '\0';
511 memset(&clsid
, 0xcc, sizeof(CLSID
));
512 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
513 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
514 ok(clsid
.Data1
== 0xb, "Got %08x\n", clsid
.Data1
);
515 ok(clsid
.Data2
== 0xcccc, "Got %04x\n", clsid
.Data2
);
518 static void test_IIDFromString(void)
520 static const WCHAR cfW
[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-',
521 'c','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
522 static const WCHAR brokenW
[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-',
523 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
524 static const WCHAR broken2W
[] = {'{','0','0','0','0','0','0','0','1','=','0','0','0','0','-','0','0','0','0','-',
525 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
526 static const WCHAR broken3W
[] = {'b','r','o','k','e','n','0','0','1','=','0','0','0','0','-','0','0','0','0','-',
527 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
531 hr
= IIDFromString(wszCLSID_StdFont
, &iid
);
532 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
533 ok(IsEqualIID(&iid
, &CLSID_StdFont
), "got iid %s\n", wine_dbgstr_guid(&iid
));
535 memset(&iid
, 0xab, sizeof(iid
));
536 hr
= IIDFromString(NULL
, &iid
);
537 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
538 ok(IsEqualIID(&iid
, &CLSID_NULL
), "got iid %s\n", wine_dbgstr_guid(&iid
));
540 hr
= IIDFromString(cfW
, &iid
);
541 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
542 ok(IsEqualIID(&iid
, &IID_IClassFactory
), "got iid %s\n", wine_dbgstr_guid(&iid
));
544 /* string starts with a valid IID but is longer */
545 memset(&iid
, 0xab, sizeof(iid
));
546 hr
= IIDFromString(cf_brokenW
, &iid
);
547 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
548 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
550 /* invalid IID in a valid format */
551 memset(&iid
, 0xab, sizeof(iid
));
552 hr
= IIDFromString(brokenW
, &iid
);
553 ok(hr
== CO_E_IIDSTRING
, "got 0x%08x\n", hr
);
554 ok(iid
.Data1
== 0x00000001, "Got %08x\n", iid
.Data1
);
556 memset(&iid
, 0xab, sizeof(iid
));
557 hr
= IIDFromString(broken2W
, &iid
);
558 ok(hr
== CO_E_IIDSTRING
, "got 0x%08x\n", hr
);
559 ok(iid
.Data1
== 0x00000001, "Got %08x\n", iid
.Data1
);
561 /* format is broken, but string length is okay */
562 memset(&iid
, 0xab, sizeof(iid
));
563 hr
= IIDFromString(broken3W
, &iid
);
564 ok(hr
== CO_E_IIDSTRING
, "got 0x%08x\n", hr
);
565 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
568 memset(&iid
, 0xab, sizeof(iid
));
569 hr
= IIDFromString(wszNonExistent
, &iid
);
570 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
571 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
574 memset(&iid
, 0xab, sizeof(iid
));
575 hr
= IIDFromString(stdfont
, &iid
);
576 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
577 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
580 static void test_StringFromGUID2(void)
585 /* invalid pointer */
586 SetLastError(0xdeadbeef);
587 len
= StringFromGUID2(NULL
,str
,50);
588 ok(len
== 0, "len: %d (expected 0)\n", len
);
589 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %x\n", GetLastError());
591 /* Test corner cases for buffer size */
592 len
= StringFromGUID2(&CLSID_StdFont
,str
,50);
593 ok(len
== 39, "len: %d (expected 39)\n", len
);
594 ok(!lstrcmpiW(str
, wszCLSID_StdFont
),"string wasn't equal for CLSID_StdFont\n");
596 memset(str
,0,sizeof str
);
597 len
= StringFromGUID2(&CLSID_StdFont
,str
,39);
598 ok(len
== 39, "len: %d (expected 39)\n", len
);
599 ok(!lstrcmpiW(str
, wszCLSID_StdFont
),"string wasn't equal for CLSID_StdFont\n");
601 len
= StringFromGUID2(&CLSID_StdFont
,str
,38);
602 ok(len
== 0, "len: %d (expected 0)\n", len
);
604 len
= StringFromGUID2(&CLSID_StdFont
,str
,30);
605 ok(len
== 0, "len: %d (expected 0)\n", len
);
613 static DWORD CALLBACK
ole_initialize_thread(LPVOID pv
)
616 struct info
*info
= pv
;
618 hr
= pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
620 SetEvent(info
->wait
);
621 WaitForSingleObject(info
->stop
, 10000);
627 static void test_CoCreateInstance(void)
634 REFCLSID rclsid
= &CLSID_InternetZoneManager
;
636 pUnk
= (IUnknown
*)0xdeadbeef;
637 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
638 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
639 ok(pUnk
== NULL
, "CoCreateInstance should have changed the passed in pointer to NULL, instead of %p\n", pUnk
);
643 /* test errors returned for non-registered clsids */
644 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
645 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered inproc server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
646 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_INPROC_HANDLER
, &IID_IUnknown
, (void **)&pUnk
);
647 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered inproc handler should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
648 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_LOCAL_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
649 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered local server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
650 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_REMOTE_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
651 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered remote server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
653 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
654 if(hr
== REGDB_E_CLASSNOTREG
)
656 skip("IE not installed so can't test CoCreateInstance\n");
661 ok_ole_success(hr
, "CoCreateInstance");
662 if(pUnk
) IUnknown_Release(pUnk
);
665 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
666 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
668 /* show that COM doesn't have to be initialized for multi-threaded apartments if another
669 thread has already done so */
671 info
.wait
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
672 ok(info
.wait
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
674 info
.stop
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
675 ok(info
.stop
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
677 thread
= CreateThread(NULL
, 0, ole_initialize_thread
, &info
, 0, &tid
);
678 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
680 ok( !WaitForSingleObject(info
.wait
, 10000 ), "wait timed out\n" );
682 pUnk
= (IUnknown
*)0xdeadbeef;
683 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
684 ok(hr
== S_OK
, "CoCreateInstance should have returned S_OK instead of 0x%08x\n", hr
);
685 if (pUnk
) IUnknown_Release(pUnk
);
688 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
690 GetExitCodeThread(thread
, &exitcode
);
692 ok(hr
== S_OK
, "thread should have returned S_OK instead of 0x%08x\n", hr
);
695 CloseHandle(info
.wait
);
696 CloseHandle(info
.stop
);
699 static void test_CoGetClassObject(void)
702 HANDLE thread
, handle
;
707 REFCLSID rclsid
= &CLSID_InternetZoneManager
;
711 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
712 ok(hr
== CO_E_NOTINITIALIZED
, "CoGetClassObject should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
713 ok(pUnk
== NULL
, "CoGetClassObject should have changed the passed in pointer to NULL, instead of %p\n", pUnk
);
715 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, NULL
);
716 ok(hr
== E_INVALIDARG
||
717 broken(hr
== CO_E_NOTINITIALIZED
), /* win9x */
718 "CoGetClassObject should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
720 /* show that COM doesn't have to be initialized for multi-threaded apartments if another
721 thread has already done so */
723 info
.wait
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
724 ok(info
.wait
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
726 info
.stop
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
727 ok(info
.stop
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
729 thread
= CreateThread(NULL
, 0, ole_initialize_thread
, &info
, 0, &tid
);
730 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
732 ok( !WaitForSingleObject(info
.wait
, 10000), "wait timed out\n" );
734 pUnk
= (IUnknown
*)0xdeadbeef;
735 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
736 if(hr
== REGDB_E_CLASSNOTREG
)
737 skip("IE not installed so can't test CoGetClassObject\n");
740 ok(hr
== S_OK
, "CoGetClassObject should have returned S_OK instead of 0x%08x\n", hr
);
741 if (pUnk
) IUnknown_Release(pUnk
);
745 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
747 GetExitCodeThread(thread
, &exitcode
);
749 ok(hr
== S_OK
, "thread should have returned S_OK instead of 0x%08x\n", hr
);
752 CloseHandle(info
.wait
);
753 CloseHandle(info
.stop
);
755 if (!pRegOverridePredefKey
)
757 win_skip("RegOverridePredefKey not available\n");
761 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
763 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
766 IUnknown_Release(pUnk
);
768 res
= RegCreateKeyExA(HKEY_CURRENT_USER
, "Software\\Classes", 0, NULL
, 0,
769 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
);
770 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
772 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, hkey
);
773 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
775 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
776 ok(hr
== S_OK
, "CoGetClassObject should have returned S_OK instead of 0x%08x\n", hr
);
778 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, NULL
);
779 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
781 if (hr
== S_OK
) IUnknown_Release(pUnk
);
785 hr
= CoGetClassObject(&CLSID_InProcFreeMarshaler
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
786 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
787 IUnknown_Release(pUnk
);
789 /* context redefines FreeMarshaler CLSID */
790 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
792 hr
= CoGetClassObject(&CLSID_InProcFreeMarshaler
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
793 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
794 IUnknown_Release(pUnk
);
796 pDeactivateActCtx(0, cookie
);
797 pReleaseActCtx(handle
);
803 static void test_CoCreateInstanceEx(void)
805 MULTI_QI qi_res
= { &IID_IMoniker
};
811 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
812 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
813 ok_ole_success(hr
, "CoRegisterClassObject");
815 create_instance_iid
= IID_NULL
;
816 hr
= CoCreateInstanceEx(&CLSID_WineOOPTest
, NULL
, CLSCTX_INPROC_SERVER
, NULL
, 1, &qi_res
);
817 ok(hr
== E_NOINTERFACE
, "CoCreateInstanceEx failed: %08x\n", hr
);
818 ok(IsEqualGUID(&create_instance_iid
, qi_res
.pIID
), "Unexpected CreateInstance iid %s\n",
819 wine_dbgstr_guid(&create_instance_iid
));
821 hr
= CoRevokeClassObject(cookie
);
822 ok_ole_success(hr
, "CoRevokeClassObject");
827 static ATOM
register_dummy_class(void)
835 GetModuleHandleA(NULL
),
837 LoadCursorA(NULL
, (LPSTR
)IDC_ARROW
),
838 (HBRUSH
)(COLOR_BTNFACE
+1),
843 return RegisterClassA(&wc
);
846 static void test_ole_menu(void)
851 hwndFrame
= CreateWindowA((LPCSTR
)MAKEINTATOM(register_dummy_class()), "Test", 0, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, NULL
, NULL
, NULL
, NULL
);
852 hr
= OleSetMenuDescriptor(NULL
, hwndFrame
, NULL
, NULL
, NULL
);
853 todo_wine
ok_ole_success(hr
, "OleSetMenuDescriptor");
855 DestroyWindow(hwndFrame
);
859 static HRESULT WINAPI
MessageFilter_QueryInterface(IMessageFilter
*iface
, REFIID riid
, void ** ppvObj
)
861 if (ppvObj
== NULL
) return E_POINTER
;
863 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
864 IsEqualGUID(riid
, &IID_IClassFactory
))
867 IMessageFilter_AddRef(iface
);
871 return E_NOINTERFACE
;
874 static ULONG WINAPI
MessageFilter_AddRef(IMessageFilter
*iface
)
876 return 2; /* non-heap object */
879 static ULONG WINAPI
MessageFilter_Release(IMessageFilter
*iface
)
881 return 1; /* non-heap object */
884 static DWORD WINAPI
MessageFilter_HandleInComingCall(
885 IMessageFilter
*iface
,
887 HTASK threadIDCaller
,
889 LPINTERFACEINFO lpInterfaceInfo
)
891 trace("HandleInComingCall\n");
892 return SERVERCALL_ISHANDLED
;
895 static DWORD WINAPI
MessageFilter_RetryRejectedCall(
896 IMessageFilter
*iface
,
897 HTASK threadIDCallee
,
901 trace("RetryRejectedCall\n");
905 static DWORD WINAPI
MessageFilter_MessagePending(
906 IMessageFilter
*iface
,
907 HTASK threadIDCallee
,
911 trace("MessagePending\n");
912 return PENDINGMSG_WAITNOPROCESS
;
915 static const IMessageFilterVtbl MessageFilter_Vtbl
=
917 MessageFilter_QueryInterface
,
918 MessageFilter_AddRef
,
919 MessageFilter_Release
,
920 MessageFilter_HandleInComingCall
,
921 MessageFilter_RetryRejectedCall
,
922 MessageFilter_MessagePending
925 static IMessageFilter MessageFilter
= { &MessageFilter_Vtbl
};
927 static void test_CoRegisterMessageFilter(void)
930 IMessageFilter
*prev_filter
;
932 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
933 ok(hr
== CO_E_NOT_SUPPORTED
,
934 "CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08x\n",
937 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
938 prev_filter
= (IMessageFilter
*)0xdeadbeef;
939 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
940 ok(hr
== CO_E_NOT_SUPPORTED
,
941 "CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08x\n",
943 ok(prev_filter
== (IMessageFilter
*)0xdeadbeef,
944 "prev_filter should have been set to %p\n", prev_filter
);
947 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
949 hr
= CoRegisterMessageFilter(NULL
, NULL
);
950 ok_ole_success(hr
, "CoRegisterMessageFilter");
952 prev_filter
= (IMessageFilter
*)0xdeadbeef;
953 hr
= CoRegisterMessageFilter(NULL
, &prev_filter
);
954 ok_ole_success(hr
, "CoRegisterMessageFilter");
955 ok(prev_filter
== NULL
, "prev_filter should have been set to NULL instead of %p\n", prev_filter
);
957 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
958 ok_ole_success(hr
, "CoRegisterMessageFilter");
959 ok(prev_filter
== NULL
, "prev_filter should have been set to NULL instead of %p\n", prev_filter
);
961 hr
= CoRegisterMessageFilter(NULL
, NULL
);
962 ok_ole_success(hr
, "CoRegisterMessageFilter");
967 static IUnknown Test_Unknown
;
969 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
971 return IUnknown_QueryInterface(&Test_Unknown
, riid
, ppv
);
974 static ULONG WINAPI
EnumOLEVERB_AddRef(IEnumOLEVERB
*iface
)
979 static ULONG WINAPI
EnumOLEVERB_Release(IEnumOLEVERB
*iface
)
984 static HRESULT WINAPI
EnumOLEVERB_Next(IEnumOLEVERB
*iface
, ULONG celt
, OLEVERB
*rgelt
, ULONG
*fetched
)
986 ok(0, "unexpected call\n");
990 static HRESULT WINAPI
EnumOLEVERB_Skip(IEnumOLEVERB
*iface
, ULONG celt
)
992 ok(0, "unexpected call\n");
996 static HRESULT WINAPI
EnumOLEVERB_Reset(IEnumOLEVERB
*iface
)
998 ok(0, "unexpected call\n");
1002 static HRESULT WINAPI
EnumOLEVERB_Clone(IEnumOLEVERB
*iface
, IEnumOLEVERB
**ppenum
)
1004 ok(0, "unexpected call\n");
1008 static const IEnumOLEVERBVtbl EnumOLEVERBVtbl
= {
1009 EnumOLEVERB_QueryInterface
,
1011 EnumOLEVERB_Release
,
1018 static IEnumOLEVERB EnumOLEVERB
= { &EnumOLEVERBVtbl
};
1020 static HRESULT WINAPI
Test_IUnknown_QueryInterface(
1025 if (ppvObj
== NULL
) return E_POINTER
;
1027 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IWineTest
)) {
1029 }else if(IsEqualIID(riid
, &IID_IEnumOLEVERB
)) {
1030 *ppvObj
= &EnumOLEVERB
;
1033 return E_NOINTERFACE
;
1036 IUnknown_AddRef((IUnknown
*)*ppvObj
);
1040 static ULONG WINAPI
Test_IUnknown_AddRef(IUnknown
*iface
)
1042 return 2; /* non-heap-based object */
1045 static ULONG WINAPI
Test_IUnknown_Release(IUnknown
*iface
)
1047 return 1; /* non-heap-based object */
1050 static const IUnknownVtbl TestUnknown_Vtbl
=
1052 Test_IUnknown_QueryInterface
,
1053 Test_IUnknown_AddRef
,
1054 Test_IUnknown_Release
,
1057 static IUnknown Test_Unknown
= { &TestUnknown_Vtbl
};
1059 static IPSFactoryBuffer
*ps_factory_buffer
;
1061 static HRESULT WINAPI
PSFactoryBuffer_QueryInterface(
1062 IPSFactoryBuffer
* This
,
1063 /* [in] */ REFIID riid
,
1064 /* [iid_is][out] */ void **ppvObject
)
1066 if (IsEqualIID(riid
, &IID_IUnknown
) ||
1067 IsEqualIID(riid
, &IID_IPSFactoryBuffer
))
1070 IPSFactoryBuffer_AddRef(This
);
1073 return E_NOINTERFACE
;
1076 static ULONG WINAPI
PSFactoryBuffer_AddRef(
1077 IPSFactoryBuffer
* This
)
1082 static ULONG WINAPI
PSFactoryBuffer_Release(
1083 IPSFactoryBuffer
* This
)
1088 static HRESULT WINAPI
PSFactoryBuffer_CreateProxy(
1089 IPSFactoryBuffer
* This
,
1090 /* [in] */ IUnknown
*pUnkOuter
,
1091 /* [in] */ REFIID riid
,
1092 /* [out] */ IRpcProxyBuffer
**ppProxy
,
1093 /* [out] */ void **ppv
)
1098 static HRESULT WINAPI
PSFactoryBuffer_CreateStub(
1099 IPSFactoryBuffer
* This
,
1100 /* [in] */ REFIID riid
,
1101 /* [unique][in] */ IUnknown
*pUnkServer
,
1102 /* [out] */ IRpcStubBuffer
**ppStub
)
1104 CHECK_EXPECT(CreateStub
);
1106 ok(pUnkServer
== (IUnknown
*)&Test_Unknown
, "unexpected pUnkServer %p\n", pUnkServer
);
1107 if(!ps_factory_buffer
)
1110 return IPSFactoryBuffer_CreateStub(ps_factory_buffer
, &IID_IEnumOLEVERB
, pUnkServer
, ppStub
);
1113 static IPSFactoryBufferVtbl PSFactoryBufferVtbl
=
1115 PSFactoryBuffer_QueryInterface
,
1116 PSFactoryBuffer_AddRef
,
1117 PSFactoryBuffer_Release
,
1118 PSFactoryBuffer_CreateProxy
,
1119 PSFactoryBuffer_CreateStub
1122 static IPSFactoryBuffer PSFactoryBuffer
= { &PSFactoryBufferVtbl
};
1124 static const CLSID CLSID_WineTestPSFactoryBuffer
=
1129 {0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd}
1130 }; /* 52011640-8164-4fd0-a1a2-5d5a3654d3bd */
1132 static void test_CoRegisterPSClsid(void)
1135 DWORD dwRegistrationKey
;
1139 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
1140 ok(hr
== CO_E_NOTINITIALIZED
, "CoRegisterPSClsid should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
1142 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1144 hr
= CoRegisterClassObject(&CLSID_WineTestPSFactoryBuffer
, (IUnknown
*)&PSFactoryBuffer
,
1145 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &dwRegistrationKey
);
1146 ok_ole_success(hr
, "CoRegisterClassObject");
1148 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
1149 ok_ole_success(hr
, "CoRegisterPSClsid");
1151 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
1152 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1154 SET_EXPECT(CreateStub
);
1155 hr
= CoMarshalInterface(stream
, &IID_IWineTest
, &Test_Unknown
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1156 ok(hr
== E_NOTIMPL
, "CoMarshalInterface should have returned E_NOTIMPL instead of 0x%08x\n", hr
);
1157 CHECK_CALLED(CreateStub
);
1159 hr
= CoGetPSClsid(&IID_IEnumOLEVERB
, &clsid
);
1160 ok_ole_success(hr
, "CoGetPSClsid");
1162 hr
= CoGetClassObject(&clsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IPSFactoryBuffer
, (void **)&ps_factory_buffer
);
1163 ok_ole_success(hr
, "CoGetClassObject");
1165 hr
= CoRegisterPSClsid(&IID_IEnumOLEVERB
, &CLSID_WineTestPSFactoryBuffer
);
1166 ok_ole_success(hr
, "CoRegisterPSClsid");
1168 SET_EXPECT(CreateStub
);
1169 hr
= CoMarshalInterface(stream
, &IID_IEnumOLEVERB
, (IUnknown
*)&EnumOLEVERB
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1170 ok(hr
== S_OK
, "CoMarshalInterface should have returned E_NOTIMPL instead of 0x%08x\n", hr
);
1171 CHECK_CALLED(CreateStub
);
1173 hr
= CoMarshalInterface(stream
, &IID_IEnumOLEVERB
, &Test_Unknown
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1174 ok(hr
== S_OK
, "CoMarshalInterface should have returned E_NOTIMPL instead of 0x%08x\n", hr
);
1176 IStream_Release(stream
);
1177 IPSFactoryBuffer_Release(ps_factory_buffer
);
1178 ps_factory_buffer
= NULL
;
1180 hr
= CoRevokeClassObject(dwRegistrationKey
);
1181 ok_ole_success(hr
, "CoRevokeClassObject");
1185 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1187 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1188 ok(hr
== REGDB_E_IIDNOTREG
, "CoGetPSClsid should have returned REGDB_E_IIDNOTREG instead of 0x%08x\n", hr
);
1193 static void test_CoGetPSClsid(void)
1201 const BOOL is_win64
= (sizeof(void*) != sizeof(int));
1202 BOOL is_wow64
= FALSE
;
1204 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1205 ok(hr
== CO_E_NOTINITIALIZED
,
1206 "CoGetPSClsid should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n",
1209 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1211 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1212 ok_ole_success(hr
, "CoGetPSClsid");
1214 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1215 ok(hr
== REGDB_E_IIDNOTREG
,
1216 "CoGetPSClsid for random IID returned 0x%08x instead of REGDB_E_IIDNOTREG\n",
1219 hr
= CoGetPSClsid(&IID_IClassFactory
, NULL
);
1220 ok(hr
== E_INVALIDARG
,
1221 "CoGetPSClsid for null clsid returned 0x%08x instead of E_INVALIDARG\n",
1224 if (!pRegOverridePredefKey
)
1226 win_skip("RegOverridePredefKey not available\n");
1230 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1231 ok_ole_success(hr
, "CoGetPSClsid");
1233 res
= RegCreateKeyExA(HKEY_CURRENT_USER
, "Software\\Classes", 0, NULL
, 0,
1234 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
);
1235 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1237 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, hkey
);
1238 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
1240 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1241 ok_ole_success(hr
, "CoGetPSClsid");
1243 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, NULL
);
1244 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
1248 /* not registered CLSID */
1249 hr
= CoGetPSClsid(&IID_Testiface
, &clsid
);
1250 ok(hr
== REGDB_E_IIDNOTREG
, "got 0x%08x\n", hr
);
1252 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
1254 memset(&clsid
, 0, sizeof(clsid
));
1255 hr
= CoGetPSClsid(&IID_Testiface
, &clsid
);
1256 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1257 ok(IsEqualGUID(&clsid
, &IID_Testiface
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1259 memset(&clsid
, 0, sizeof(clsid
));
1260 hr
= CoGetPSClsid(&IID_Testiface2
, &clsid
);
1261 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1262 ok(IsEqualGUID(&clsid
, &IID_Testiface2
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1264 memset(&clsid
, 0, sizeof(clsid
));
1265 hr
= CoGetPSClsid(&IID_Testiface3
, &clsid
);
1266 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1267 ok(IsEqualGUID(&clsid
, &IID_TestPS
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1269 memset(&clsid
, 0xaa, sizeof(clsid
));
1270 hr
= CoGetPSClsid(&IID_Testiface4
, &clsid
);
1271 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1272 ok(IsEqualGUID(&clsid
, &GUID_NULL
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1274 /* register same interface and try to get CLSID back */
1275 hr
= CoRegisterPSClsid(&IID_Testiface
, &IID_Testiface4
);
1276 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1277 memset(&clsid
, 0, sizeof(clsid
));
1278 hr
= CoGetPSClsid(&IID_Testiface
, &clsid
);
1279 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1280 ok(IsEqualGUID(&clsid
, &IID_Testiface4
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1282 pDeactivateActCtx(0, cookie
);
1283 pReleaseActCtx(handle
);
1286 if (pRegDeleteKeyExA
&&
1288 (pIsWow64Process
&& pIsWow64Process(GetCurrentProcess(), &is_wow64
) && is_wow64
)))
1290 static GUID IID_DeadBeef
= {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
1291 static const char clsidDeadBeef
[] = "{deadbeef-dead-beef-dead-beefdeadbeef}";
1292 static const char clsidA
[] = "{66666666-8888-7777-6666-555555555555}";
1293 HKEY hkey_iface
, hkey_psclsid
;
1294 REGSAM opposite
= is_win64
? KEY_WOW64_32KEY
: KEY_WOW64_64KEY
;
1296 hr
= CoGetPSClsid(&IID_DeadBeef
, &clsid
);
1297 ok(hr
== REGDB_E_IIDNOTREG
, "got 0x%08x\n", hr
);
1299 res
= RegCreateKeyExA(HKEY_CLASSES_ROOT
, "Interface",
1300 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
, NULL
, &hkey_iface
, NULL
);
1301 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1302 res
= RegCreateKeyExA(hkey_iface
, clsidDeadBeef
,
1303 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
, NULL
, &hkey
, NULL
);
1304 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1305 res
= RegCreateKeyExA(hkey
, "ProxyStubClsid32",
1306 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
, NULL
, &hkey_psclsid
, NULL
);
1307 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1308 res
= RegSetValueExA(hkey_psclsid
, NULL
, 0, REG_SZ
, (const BYTE
*)clsidA
, strlen(clsidA
)+1);
1309 ok(!res
, "RegSetValueEx returned %d\n", res
);
1310 RegCloseKey(hkey_psclsid
);
1312 hr
= CoGetPSClsid(&IID_DeadBeef
, &clsid
);
1313 ok_ole_success(hr
, "CoGetPSClsid");
1314 ok(IsEqualGUID(&clsid
, &IID_TestPS
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1316 res
= pRegDeleteKeyExA(hkey
, "ProxyStubClsid32", opposite
, 0);
1317 ok(!res
, "RegDeleteKeyEx returned %d\n", res
);
1319 res
= pRegDeleteKeyExA(hkey_iface
, clsidDeadBeef
, opposite
, 0);
1320 ok(!res
, "RegDeleteKeyEx returned %d\n", res
);
1321 RegCloseKey(hkey_iface
);
1327 /* basic test, mainly for invalid arguments. see marshal.c for more */
1328 static void test_CoUnmarshalInterface(void)
1334 hr
= CoUnmarshalInterface(NULL
, &IID_IUnknown
, (void **)&pProxy
);
1335 ok(hr
== E_INVALIDARG
, "CoUnmarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1337 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
1338 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1340 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, (void **)&pProxy
);
1342 ok(hr
== CO_E_NOTINITIALIZED
, "CoUnmarshalInterface should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
1344 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1346 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, (void **)&pProxy
);
1347 ok(hr
== STG_E_READFAULT
, "CoUnmarshalInterface should have returned STG_E_READFAULT instead of 0x%08x\n", hr
);
1351 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, NULL
);
1352 ok(hr
== E_INVALIDARG
, "CoUnmarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1354 IStream_Release(pStream
);
1357 static void test_CoGetInterfaceAndReleaseStream(void)
1362 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1364 hr
= CoGetInterfaceAndReleaseStream(NULL
, &IID_IUnknown
, (void**)&pUnk
);
1365 ok(hr
== E_INVALIDARG
, "hr %08x\n", hr
);
1370 /* basic test, mainly for invalid arguments. see marshal.c for more */
1371 static void test_CoMarshalInterface(void)
1375 static const LARGE_INTEGER llZero
;
1377 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1379 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
1380 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1382 hr
= CoMarshalInterface(pStream
, &IID_IUnknown
, NULL
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1383 ok(hr
== E_INVALIDARG
, "CoMarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1385 hr
= CoMarshalInterface(NULL
, &IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1386 ok(hr
== E_INVALIDARG
, "CoMarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1388 hr
= CoMarshalInterface(pStream
, &IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1389 ok_ole_success(hr
, "CoMarshalInterface");
1391 /* stream not rewound */
1392 hr
= CoReleaseMarshalData(pStream
);
1393 ok(hr
== STG_E_READFAULT
, "CoReleaseMarshalData should have returned STG_E_READFAULT instead of 0x%08x\n", hr
);
1395 hr
= IStream_Seek(pStream
, llZero
, STREAM_SEEK_SET
, NULL
);
1396 ok_ole_success(hr
, "IStream_Seek");
1398 hr
= CoReleaseMarshalData(pStream
);
1399 ok_ole_success(hr
, "CoReleaseMarshalData");
1401 IStream_Release(pStream
);
1406 static void test_CoMarshalInterThreadInterfaceInStream(void)
1410 IClassFactory
*pProxy
;
1412 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1416 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, NULL
);
1417 ok(hr
== E_INVALIDARG
, "CoMarshalInterThreadInterfaceInStream should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1419 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, NULL
, &pStream
);
1420 ok(hr
== E_INVALIDARG
, "CoMarshalInterThreadInterfaceInStream should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1424 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, &pStream
);
1425 ok_ole_success(hr
, "CoMarshalInterThreadInterfaceInStream");
1427 ok_more_than_one_lock();
1429 hr
= CoUnmarshalInterface(pStream
, &IID_IClassFactory
, (void **)&pProxy
);
1430 ok_ole_success(hr
, "CoUnmarshalInterface");
1432 IClassFactory_Release(pProxy
);
1433 IStream_Release(pStream
);
1440 static void test_CoRegisterClassObject(void)
1442 ULONG_PTR ctxcookie
;
1448 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1450 /* CLSCTX_INPROC_SERVER */
1451 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1452 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1453 ok_ole_success(hr
, "CoRegisterClassObject");
1454 hr
= CoRevokeClassObject(cookie
);
1455 ok_ole_success(hr
, "CoRevokeClassObject");
1457 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1458 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
1459 ok_ole_success(hr
, "CoRegisterClassObject");
1460 hr
= CoRevokeClassObject(cookie
);
1461 ok_ole_success(hr
, "CoRevokeClassObject");
1463 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1464 CLSCTX_INPROC_SERVER
, REGCLS_MULTI_SEPARATE
, &cookie
);
1465 ok_ole_success(hr
, "CoRegisterClassObject");
1466 hr
= CoRevokeClassObject(cookie
);
1467 ok_ole_success(hr
, "CoRevokeClassObject");
1469 /* CLSCTX_LOCAL_SERVER */
1470 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1471 CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1472 ok_ole_success(hr
, "CoRegisterClassObject");
1473 hr
= CoRevokeClassObject(cookie
);
1474 ok_ole_success(hr
, "CoRevokeClassObject");
1476 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1477 CLSCTX_LOCAL_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
1478 ok_ole_success(hr
, "CoRegisterClassObject");
1479 hr
= CoRevokeClassObject(cookie
);
1480 ok_ole_success(hr
, "CoRevokeClassObject");
1482 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1483 CLSCTX_LOCAL_SERVER
, REGCLS_MULTI_SEPARATE
, &cookie
);
1484 ok_ole_success(hr
, "CoRegisterClassObject");
1485 hr
= CoRevokeClassObject(cookie
);
1486 ok_ole_success(hr
, "CoRevokeClassObject");
1488 /* CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER */
1489 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1490 CLSCTX_INPROC_SERVER
|CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1491 ok_ole_success(hr
, "CoRegisterClassObject");
1492 hr
= CoRevokeClassObject(cookie
);
1493 ok_ole_success(hr
, "CoRevokeClassObject");
1495 /* test whether an object that doesn't support IClassFactory can be
1496 * registered for CLSCTX_LOCAL_SERVER */
1497 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, &Test_Unknown
,
1498 CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1499 ok_ole_success(hr
, "CoRegisterClassObject");
1500 hr
= CoRevokeClassObject(cookie
);
1501 ok_ole_success(hr
, "CoRevokeClassObject");
1503 /* test whether registered class becomes invalid when apartment is destroyed */
1504 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1505 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1506 ok_ole_success(hr
, "CoRegisterClassObject");
1509 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1511 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
,
1512 &IID_IClassFactory
, (void **)&pcf
);
1513 ok(hr
== REGDB_E_CLASSNOTREG
, "object registered in an apartment shouldn't accessible after it is destroyed\n");
1515 /* crashes with at least win9x DCOM! */
1517 CoRevokeClassObject(cookie
);
1519 /* test that object is accessible */
1520 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
, CLSCTX_INPROC_SERVER
,
1521 REGCLS_MULTIPLEUSE
, &cookie
);
1522 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1524 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&pcf
);
1525 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1526 IClassFactory_Release(pcf
);
1528 /* context now contains CLSID_WineOOPTest, test if registered one could still be used */
1529 if ((handle
= activate_context(actctx_manifest
, &ctxcookie
)))
1531 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&pcf
);
1533 ok(hr
== HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND
), "got 0x%08x\n", hr
);
1535 pDeactivateActCtx(0, ctxcookie
);
1536 pReleaseActCtx(handle
);
1539 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&pcf
);
1540 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1541 IClassFactory_Release(pcf
);
1543 hr
= CoRevokeClassObject(cookie
);
1544 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1549 static HRESULT
get_class_object(CLSCTX clsctx
)
1554 hr
= CoGetClassObject(&CLSID_WineOOPTest
, clsctx
, NULL
, &IID_IClassFactory
,
1558 IClassFactory_Release(pcf
);
1563 static DWORD CALLBACK
get_class_object_thread(LPVOID pv
)
1565 CLSCTX clsctx
= (CLSCTX
)(DWORD_PTR
)pv
;
1568 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1570 hr
= get_class_object(clsctx
);
1577 static DWORD CALLBACK
get_class_object_proxy_thread(LPVOID pv
)
1579 CLSCTX clsctx
= (CLSCTX
)(DWORD_PTR
)pv
;
1584 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1586 hr
= CoGetClassObject(&CLSID_WineOOPTest
, clsctx
, NULL
, &IID_IClassFactory
,
1591 hr
= IClassFactory_QueryInterface(pcf
, &IID_IMultiQI
, (void **)&pMQI
);
1593 IMultiQI_Release(pMQI
);
1594 IClassFactory_Release(pcf
);
1602 static DWORD CALLBACK
register_class_object_thread(LPVOID pv
)
1607 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1609 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1610 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1617 static DWORD CALLBACK
revoke_class_object_thread(LPVOID pv
)
1619 DWORD cookie
= (DWORD_PTR
)pv
;
1622 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1624 hr
= CoRevokeClassObject(cookie
);
1631 static void test_registered_object_thread_affinity(void)
1639 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1641 /* CLSCTX_INPROC_SERVER */
1643 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1644 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1645 ok_ole_success(hr
, "CoRegisterClassObject");
1647 thread
= CreateThread(NULL
, 0, get_class_object_thread
, (LPVOID
)CLSCTX_INPROC_SERVER
, 0, &tid
);
1648 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1649 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1650 GetExitCodeThread(thread
, &exitcode
);
1652 ok(hr
== REGDB_E_CLASSNOTREG
, "CoGetClassObject on inproc object "
1653 "registered in different thread should return REGDB_E_CLASSNOTREG "
1654 "instead of 0x%08x\n", hr
);
1656 hr
= get_class_object(CLSCTX_INPROC_SERVER
);
1657 ok(hr
== S_OK
, "CoGetClassObject on inproc object registered in same "
1658 "thread should return S_OK instead of 0x%08x\n", hr
);
1660 thread
= CreateThread(NULL
, 0, register_class_object_thread
, NULL
, 0, &tid
);
1661 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1662 ok ( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1663 GetExitCodeThread(thread
, &exitcode
);
1665 ok(hr
== S_OK
, "CoRegisterClassObject with same CLSID but in different thread should return S_OK instead of 0x%08x\n", hr
);
1667 hr
= CoRevokeClassObject(cookie
);
1668 ok_ole_success(hr
, "CoRevokeClassObject");
1670 /* CLSCTX_LOCAL_SERVER */
1672 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1673 CLSCTX_LOCAL_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
1674 ok_ole_success(hr
, "CoRegisterClassObject");
1676 thread
= CreateThread(NULL
, 0, get_class_object_proxy_thread
, (LPVOID
)CLSCTX_LOCAL_SERVER
, 0, &tid
);
1677 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1678 while (MsgWaitForMultipleObjects(1, &thread
, FALSE
, 10000, QS_ALLINPUT
) == WAIT_OBJECT_0
+ 1)
1681 while (PeekMessageA(&msg
, NULL
, 0, 0, PM_REMOVE
))
1683 TranslateMessage(&msg
);
1684 DispatchMessageA(&msg
);
1687 GetExitCodeThread(thread
, &exitcode
);
1689 ok(hr
== S_OK
, "CoGetClassObject on local server object "
1690 "registered in different thread should return S_OK "
1691 "instead of 0x%08x\n", hr
);
1693 hr
= get_class_object(CLSCTX_LOCAL_SERVER
);
1694 ok(hr
== S_OK
, "CoGetClassObject on local server object registered in same "
1695 "thread should return S_OK instead of 0x%08x\n", hr
);
1697 thread
= CreateThread(NULL
, 0, revoke_class_object_thread
, (LPVOID
)(DWORD_PTR
)cookie
, 0, &tid
);
1698 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1699 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1700 GetExitCodeThread(thread
, &exitcode
);
1702 ok(hr
== RPC_E_WRONG_THREAD
|| broken(hr
== S_OK
) /* win8 */, "CoRevokeClassObject called from different "
1703 "thread to where registered should return RPC_E_WRONG_THREAD instead of 0x%08x\n", hr
);
1705 thread
= CreateThread(NULL
, 0, register_class_object_thread
, NULL
, 0, &tid
);
1706 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1707 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1708 GetExitCodeThread(thread
, &exitcode
);
1710 ok(hr
== S_OK
, "CoRegisterClassObject with same CLSID but in different "
1711 "thread should return S_OK instead of 0x%08x\n", hr
);
1713 hr
= CoRevokeClassObject(cookie
);
1714 ok_ole_success(hr
, "CoRevokeClassObject");
1719 static DWORD CALLBACK
free_libraries_thread(LPVOID p
)
1721 CoFreeUnusedLibraries();
1725 static inline BOOL
is_module_loaded(const char *module
)
1727 return GetModuleHandleA(module
) != 0;
1730 static void test_CoFreeUnusedLibraries(void)
1737 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1739 ok(!is_module_loaded("urlmon.dll"), "urlmon.dll shouldn't be loaded\n");
1741 hr
= CoCreateInstance(&CLSID_FileProtocol
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IInternetProtocol
, (void **)&pUnk
);
1742 if (hr
== REGDB_E_CLASSNOTREG
)
1744 skip("IE not installed so can't run CoFreeUnusedLibraries test\n");
1748 ok_ole_success(hr
, "CoCreateInstance");
1750 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1753 broken(pUnk
== NULL
), /* win9x */
1754 "Expected a valid pointer\n");
1756 IUnknown_Release(pUnk
);
1758 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1760 thread
= CreateThread(NULL
, 0, free_libraries_thread
, NULL
, 0, &tid
);
1761 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1762 CloseHandle(thread
);
1764 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1766 CoFreeUnusedLibraries();
1768 ok(!is_module_loaded("urlmon.dll"), "urlmon.dll shouldn't be loaded\n");
1773 static void test_CoGetObjectContext(void)
1777 IComThreadingInfo
*pComThreadingInfo
;
1778 IContextCallback
*pContextCallback
;
1779 IObjContext
*pObjContext
;
1784 DWORD tid
, exitcode
;
1786 if (!pCoGetObjectContext
)
1788 skip("CoGetObjectContext not present\n");
1792 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1793 ok(hr
== CO_E_NOTINITIALIZED
, "CoGetObjectContext should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
1794 ok(pComThreadingInfo
== NULL
, "pComThreadingInfo should have been set to NULL\n");
1796 /* show that COM doesn't have to be initialized for multi-threaded apartments if another
1797 thread has already done so */
1799 info
.wait
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
1800 ok(info
.wait
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
1802 info
.stop
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
1803 ok(info
.stop
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
1805 thread
= CreateThread(NULL
, 0, ole_initialize_thread
, &info
, 0, &tid
);
1806 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1808 ok( !WaitForSingleObject(info
.wait
, 10000), "wait timed out\n" );
1810 pComThreadingInfo
= NULL
;
1811 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1812 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
1813 IComThreadingInfo_Release(pComThreadingInfo
);
1815 SetEvent(info
.stop
);
1816 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1818 GetExitCodeThread(thread
, &exitcode
);
1820 ok(hr
== S_OK
, "thread should have returned S_OK instead of 0x%08x\n", hr
);
1822 CloseHandle(thread
);
1823 CloseHandle(info
.wait
);
1824 CloseHandle(info
.stop
);
1826 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1828 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1829 ok_ole_success(hr
, "CoGetObjectContext");
1831 hr
= IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo
, &apttype
);
1832 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentApartmentType");
1833 ok(apttype
== APTTYPE_MAINSTA
, "apartment type should be APTTYPE_MAINSTA instead of %d\n", apttype
);
1835 hr
= IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo
, &thdtype
);
1836 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentThreadType");
1837 ok(thdtype
== THDTYPE_PROCESSMESSAGES
, "thread type should be THDTYPE_PROCESSMESSAGES instead of %d\n", thdtype
);
1839 refs
= IComThreadingInfo_Release(pComThreadingInfo
);
1840 ok(refs
== 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs
);
1842 hr
= pCoGetObjectContext(&IID_IContextCallback
, (void **)&pContextCallback
);
1843 ok_ole_success(hr
, "CoGetObjectContext(ContextCallback)");
1847 refs
= IContextCallback_Release(pContextCallback
);
1848 ok(refs
== 0, "pContextCallback should have 0 refs instead of %d refs\n", refs
);
1853 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
1855 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1856 ok_ole_success(hr
, "CoGetObjectContext");
1858 hr
= IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo
, &apttype
);
1859 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentApartmentType");
1860 ok(apttype
== APTTYPE_MTA
, "apartment type should be APTTYPE_MTA instead of %d\n", apttype
);
1862 hr
= IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo
, &thdtype
);
1863 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentThreadType");
1864 ok(thdtype
== THDTYPE_BLOCKMESSAGES
, "thread type should be THDTYPE_BLOCKMESSAGES instead of %d\n", thdtype
);
1866 refs
= IComThreadingInfo_Release(pComThreadingInfo
);
1867 ok(refs
== 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs
);
1869 hr
= pCoGetObjectContext(&IID_IContextCallback
, (void **)&pContextCallback
);
1870 ok_ole_success(hr
, "CoGetObjectContext(ContextCallback)");
1874 refs
= IContextCallback_Release(pContextCallback
);
1875 ok(refs
== 0, "pContextCallback should have 0 refs instead of %d refs\n", refs
);
1878 hr
= pCoGetObjectContext(&IID_IObjContext
, (void **)&pObjContext
);
1879 ok_ole_success(hr
, "CoGetObjectContext");
1881 refs
= IObjContext_Release(pObjContext
);
1882 ok(refs
== 0, "pObjContext should have 0 refs instead of %d refs\n", refs
);
1888 IUnknown IUnknown_iface
;
1892 static inline Test_CallContext
*impl_from_IUnknown(IUnknown
*iface
)
1894 return CONTAINING_RECORD(iface
, Test_CallContext
, IUnknown_iface
);
1897 static HRESULT WINAPI
Test_CallContext_QueryInterface(
1902 if (ppvObj
== NULL
) return E_POINTER
;
1904 if (IsEqualGUID(riid
, &IID_IUnknown
))
1907 IUnknown_AddRef(iface
);
1912 return E_NOINTERFACE
;
1915 static ULONG WINAPI
Test_CallContext_AddRef(IUnknown
*iface
)
1917 Test_CallContext
*This
= impl_from_IUnknown(iface
);
1918 return InterlockedIncrement(&This
->refs
);
1921 static ULONG WINAPI
Test_CallContext_Release(IUnknown
*iface
)
1923 Test_CallContext
*This
= impl_from_IUnknown(iface
);
1924 ULONG refs
= InterlockedDecrement(&This
->refs
);
1926 HeapFree(GetProcessHeap(), 0, This
);
1930 static const IUnknownVtbl TestCallContext_Vtbl
=
1932 Test_CallContext_QueryInterface
,
1933 Test_CallContext_AddRef
,
1934 Test_CallContext_Release
1937 static void test_CoGetCallContext(void)
1942 Test_CallContext
*test_object
;
1944 if (!pCoSwitchCallContext
)
1946 skip("CoSwitchCallContext not present\n");
1952 test_object
= HeapAlloc(GetProcessHeap(), 0, sizeof(Test_CallContext
));
1953 test_object
->IUnknown_iface
.lpVtbl
= &TestCallContext_Vtbl
;
1954 test_object
->refs
= 1;
1956 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
1957 ok(hr
== RPC_E_CALL_COMPLETE
, "Expected RPC_E_CALL_COMPLETE, got 0x%08x\n", hr
);
1959 pUnk
= (IUnknown
*)0xdeadbeef;
1960 hr
= pCoSwitchCallContext(&test_object
->IUnknown_iface
, &pUnk
);
1961 ok_ole_success(hr
, "CoSwitchCallContext");
1962 ok(pUnk
== NULL
, "expected NULL, got %p\n", pUnk
);
1963 refs
= IUnknown_AddRef(&test_object
->IUnknown_iface
);
1964 ok(refs
== 2, "Expected refcount 2, got %d\n", refs
);
1965 IUnknown_Release(&test_object
->IUnknown_iface
);
1967 pUnk
= (IUnknown
*)0xdeadbeef;
1968 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
1969 ok_ole_success(hr
, "CoGetCallContext");
1970 ok(pUnk
== &test_object
->IUnknown_iface
, "expected %p, got %p\n",
1971 &test_object
->IUnknown_iface
, pUnk
);
1972 refs
= IUnknown_AddRef(&test_object
->IUnknown_iface
);
1973 ok(refs
== 3, "Expected refcount 3, got %d\n", refs
);
1974 IUnknown_Release(&test_object
->IUnknown_iface
);
1975 IUnknown_Release(pUnk
);
1977 pUnk
= (IUnknown
*)0xdeadbeef;
1978 hr
= pCoSwitchCallContext(NULL
, &pUnk
);
1979 ok_ole_success(hr
, "CoSwitchCallContext");
1980 ok(pUnk
== &test_object
->IUnknown_iface
, "expected %p, got %p\n",
1981 &test_object
->IUnknown_iface
, pUnk
);
1982 refs
= IUnknown_AddRef(&test_object
->IUnknown_iface
);
1983 ok(refs
== 2, "Expected refcount 2, got %d\n", refs
);
1984 IUnknown_Release(&test_object
->IUnknown_iface
);
1986 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
1987 ok(hr
== RPC_E_CALL_COMPLETE
, "Expected RPC_E_CALL_COMPLETE, got 0x%08x\n", hr
);
1989 IUnknown_Release(&test_object
->IUnknown_iface
);
1994 static void test_CoGetContextToken(void)
2002 DWORD tid
, exitcode
;
2004 if (!pCoGetContextToken
)
2006 win_skip("CoGetContextToken not present\n");
2011 hr
= pCoGetContextToken(&token
);
2012 ok(hr
== CO_E_NOTINITIALIZED
, "Expected CO_E_NOTINITIALIZED, got 0x%08x\n", hr
);
2013 ok(token
== 0xdeadbeef, "Expected 0, got 0x%lx\n", token
);
2015 /* show that COM doesn't have to be initialized for multi-threaded apartments if another
2016 thread has already done so */
2018 info
.wait
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
2019 ok(info
.wait
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
2021 info
.stop
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
2022 ok(info
.stop
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
2024 thread
= CreateThread(NULL
, 0, ole_initialize_thread
, &info
, 0, &tid
);
2025 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
2027 ok( !WaitForSingleObject(info
.wait
, 10000), "wait timed out\n" );
2030 hr
= pCoGetContextToken(&token
);
2031 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2033 SetEvent(info
.stop
);
2034 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
2036 GetExitCodeThread(thread
, &exitcode
);
2038 ok(hr
== S_OK
, "thread should have returned S_OK instead of 0x%08x\n", hr
);
2040 CloseHandle(thread
);
2041 CloseHandle(info
.wait
);
2042 CloseHandle(info
.stop
);
2046 hr
= pCoGetContextToken(NULL
);
2047 ok(hr
== E_POINTER
, "Expected E_POINTER, got 0x%08x\n", hr
);
2050 hr
= pCoGetContextToken(&token
);
2051 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2052 ok(token
, "Expected token != 0\n");
2054 refs
= IUnknown_AddRef((IUnknown
*)token
);
2055 todo_wine
ok(refs
== 1, "Expected 1, got %u\n", refs
);
2057 hr
= pCoGetObjectContext(&IID_IObjContext
, (void **)&ctx
);
2058 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2059 todo_wine
ok(ctx
== (IObjContext
*)token
, "Expected interface pointers to be the same\n");
2061 refs
= IObjContext_AddRef(ctx
);
2062 todo_wine
ok(refs
== 3, "Expected 3, got %u\n", refs
);
2064 refs
= IObjContext_Release(ctx
);
2065 todo_wine
ok(refs
== 2, "Expected 2, got %u\n", refs
);
2067 refs
= IUnknown_Release((IUnknown
*)token
);
2068 ok(refs
== 1, "Expected 1, got %u\n", refs
);
2070 /* CoGetContextToken does not add a reference */
2072 hr
= pCoGetContextToken(&token
);
2073 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2074 ok(token
, "Expected token != 0\n");
2075 todo_wine
ok(ctx
== (IObjContext
*)token
, "Expected interface pointers to be the same\n");
2077 refs
= IObjContext_AddRef(ctx
);
2078 ok(refs
== 2, "Expected 1, got %u\n", refs
);
2080 refs
= IObjContext_Release(ctx
);
2081 ok(refs
== 1, "Expected 0, got %u\n", refs
);
2083 refs
= IObjContext_Release(ctx
);
2084 ok(refs
== 0, "Expected 0, got %u\n", refs
);
2089 static void test_TreatAsClass(void)
2093 static GUID deadbeef
= {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
2094 static const char deadbeefA
[] = "{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}";
2095 IInternetProtocol
*pIP
= NULL
;
2096 HKEY clsidkey
, deadbeefkey
;
2099 if (!pCoGetTreatAsClass
)
2101 win_skip("CoGetTreatAsClass not present\n");
2104 hr
= pCoGetTreatAsClass(&deadbeef
,&out
);
2105 ok (hr
== S_FALSE
, "expected S_FALSE got %x\n",hr
);
2106 ok (IsEqualGUID(&out
,&deadbeef
), "expected to get same clsid back\n");
2108 lr
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "CLSID", 0, KEY_READ
, &clsidkey
);
2109 ok(lr
== ERROR_SUCCESS
, "Couldn't open CLSID key\n");
2111 lr
= RegCreateKeyExA(clsidkey
, deadbeefA
, 0, NULL
, 0, KEY_WRITE
, NULL
, &deadbeefkey
, NULL
);
2113 win_skip("CoGetTreatAsClass() tests will be skipped (failed to create a test key, error %d)\n",
2115 RegCloseKey(clsidkey
);
2119 hr
= pCoTreatAsClass(&deadbeef
, &deadbeef
);
2120 ok(hr
== REGDB_E_WRITEREGDB
, "CoTreatAsClass gave wrong error: %08x\n", hr
);
2122 hr
= pCoTreatAsClass(&deadbeef
, &CLSID_FileProtocol
);
2123 if(hr
== REGDB_E_WRITEREGDB
){
2124 win_skip("Insufficient privileges to use CoTreatAsClass\n");
2127 ok(hr
== S_OK
, "CoTreatAsClass failed: %08x\n", hr
);
2129 hr
= pCoGetTreatAsClass(&deadbeef
, &out
);
2130 ok(hr
== S_OK
, "CoGetTreatAsClass failed: %08x\n",hr
);
2131 ok(IsEqualGUID(&out
, &CLSID_FileProtocol
), "expected to get substituted clsid\n");
2133 OleInitialize(NULL
);
2135 hr
= CoCreateInstance(&deadbeef
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IInternetProtocol
, (void **)&pIP
);
2136 if(hr
== REGDB_E_CLASSNOTREG
)
2138 win_skip("IE not installed so can't test CoCreateInstance\n");
2142 ok(hr
== S_OK
, "CoCreateInstance failed: %08x\n", hr
);
2144 IInternetProtocol_Release(pIP
);
2148 hr
= pCoTreatAsClass(&deadbeef
, &CLSID_NULL
);
2149 ok(hr
== S_OK
, "CoTreatAsClass failed: %08x\n", hr
);
2151 hr
= pCoGetTreatAsClass(&deadbeef
, &out
);
2152 ok(hr
== S_FALSE
, "expected S_FALSE got %08x\n", hr
);
2153 ok(IsEqualGUID(&out
, &deadbeef
), "expected to get same clsid back\n");
2155 /* bizarrely, native's CoTreatAsClass takes some time to take effect in CoCreateInstance */
2158 hr
= CoCreateInstance(&deadbeef
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IInternetProtocol
, (void **)&pIP
);
2159 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance gave wrong error: %08x\n", hr
);
2162 IInternetProtocol_Release(pIP
);
2166 RegCloseKey(deadbeefkey
);
2167 RegDeleteKeyA(clsidkey
, deadbeefA
);
2168 RegCloseKey(clsidkey
);
2171 static void test_CoInitializeEx(void)
2175 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2176 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2178 /* Calling OleInitialize for the first time should yield S_OK even with
2179 * apartment already initialized by previous CoInitialize(Ex) calls. */
2180 hr
= OleInitialize(NULL
);
2181 ok(hr
== S_OK
, "OleInitialize failed with error 0x%08x\n", hr
);
2183 /* Subsequent calls to OleInitialize should return S_FALSE */
2184 hr
= OleInitialize(NULL
);
2185 ok(hr
== S_FALSE
, "Expected S_FALSE, hr = 0x%08x\n", hr
);
2193 static void test_OleRegGetMiscStatus(void)
2200 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_ICON
, NULL
);
2201 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2203 status
= 0xdeadbeef;
2204 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_ICON
, &status
);
2205 ok(hr
== REGDB_E_CLASSNOTREG
, "got 0x%08x\n", hr
);
2206 ok(status
== 0, "got 0x%08x\n", status
);
2209 hr
= OleRegGetMiscStatus(&CLSID_StdFont
, DVASPECT_ICON
, &status
);
2210 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2211 ok(status
== 0, "got 0x%08x\n", status
);
2213 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
2216 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_ICON
, &status
);
2217 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2218 ok(status
== OLEMISC_RECOMPOSEONRESIZE
, "got 0x%08x\n", status
);
2220 /* context data takes precedence over registration info */
2222 hr
= OleRegGetMiscStatus(&CLSID_StdFont
, DVASPECT_ICON
, &status
);
2223 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2224 ok(status
== OLEMISC_RECOMPOSEONRESIZE
, "got 0x%08x\n", status
);
2226 /* there's no such attribute in context */
2228 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_DOCPRINT
, &status
);
2229 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2230 ok(status
== 0, "got 0x%08x\n", status
);
2232 pDeactivateActCtx(0, cookie
);
2233 pReleaseActCtx(handle
);
2237 static void test_CoCreateGuid(void)
2241 hr
= CoCreateGuid(NULL
);
2242 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2245 static void CALLBACK
apc_test_proc(ULONG_PTR param
)
2250 static DWORD CALLBACK
release_semaphore_thread( LPVOID arg
)
2252 HANDLE handle
= arg
;
2253 if (WaitForSingleObject(handle
, 200) == WAIT_TIMEOUT
)
2254 ReleaseSemaphore(handle
, 1, NULL
);
2258 static DWORD CALLBACK
send_message_thread(LPVOID arg
)
2262 SendMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2266 static DWORD CALLBACK
post_message_thread(LPVOID arg
)
2270 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2274 static const char cls_name
[] = "cowait_test_class";
2275 static DWORD CALLBACK
test_CoWaitForMultipleHandles_thread(LPVOID arg
)
2277 HANDLE
*handles
= arg
;
2284 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2285 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2287 hWnd
= CreateWindowExA(0, cls_name
, "Test (thread)", WS_TILEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
2288 ok(hWnd
!= 0, "CreateWindowExA failed %u\n", GetLastError());
2291 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2292 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2293 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2294 ok(index
==0 || index
==0xdeadbeef/* Win 8 */, "expected index 0, got %u\n", index
);
2295 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2296 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2299 PostMessageA(hWnd
, WM_USER
, 0, 0);
2300 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2301 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2302 ok(index
==0 || index
==0xdeadbeef/* Win 8 */, "expected index 0, got %u\n", index
);
2303 success
= PeekMessageA(&msg
, hWnd
, WM_USER
, WM_USER
, PM_REMOVE
);
2304 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2306 DestroyWindow(hWnd
);
2311 static void test_CoWaitForMultipleHandles(void)
2313 HANDLE handles
[2], thread
;
2321 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2322 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2324 memset(&wc
, 0, sizeof(wc
));
2325 wc
.cbSize
= sizeof(wc
);
2326 wc
.style
= CS_VREDRAW
| CS_HREDRAW
;
2327 wc
.hInstance
= GetModuleHandleA(0);
2328 wc
.hCursor
= LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
);
2329 wc
.hbrBackground
= NULL
;
2330 wc
.lpszClassName
= cls_name
;
2331 wc
.lpfnWndProc
= DefWindowProcA
;
2332 success
= RegisterClassExA(&wc
) != 0;
2333 ok(success
, "RegisterClassExA failed %u\n", GetLastError());
2335 hWnd
= CreateWindowExA(0, cls_name
, "Test", WS_TILEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
2336 ok(hWnd
!= 0, "CreateWindowExA failed %u\n", GetLastError());
2337 handles
[0] = CreateSemaphoreA(NULL
, 1, 1, NULL
);
2338 ok(handles
[0] != 0, "CreateSemaphoreA failed %u\n", GetLastError());
2339 handles
[1] = CreateSemaphoreA(NULL
, 1, 1, NULL
);
2340 ok(handles
[1] != 0, "CreateSemaphoreA failed %u\n", GetLastError());
2342 /* test without flags */
2344 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2345 hr
= CoWaitForMultipleHandles(0, 50, 0, handles
, NULL
);
2346 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
2347 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2348 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2351 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2352 hr
= CoWaitForMultipleHandles(0, 50, 0, NULL
, &index
);
2353 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
2354 ok(index
== 0, "expected index 0, got %u\n", index
);
2355 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2356 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2359 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2360 hr
= CoWaitForMultipleHandles(0, 50, 0, handles
, &index
);
2361 ok(hr
== RPC_E_NO_SYNC
, "expected RPC_E_NO_SYNC, got 0x%08x\n", hr
);
2362 ok(index
== 0, "expected index 0, got %u\n", index
);
2363 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2364 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2367 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2368 hr
= CoWaitForMultipleHandles(0, 50, 1, handles
, &index
);
2369 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2370 ok(index
== 0, "expected index 0, got %u\n", index
);
2371 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2372 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2375 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2376 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2377 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2378 ok(index
== 1, "expected index 1, got %u\n", index
);
2379 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2380 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2383 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2384 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2385 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2386 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2387 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2388 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2390 /* test PostMessageA/SendMessageA from a different thread */
2393 thread
= CreateThread(NULL
, 0, post_message_thread
, hWnd
, 0, &tid
);
2394 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2395 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2396 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2397 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2398 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2399 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2400 index
= WaitForSingleObject(thread
, 200);
2401 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2402 CloseHandle(thread
);
2405 thread
= CreateThread(NULL
, 0, send_message_thread
, hWnd
, 0, &tid
);
2406 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2407 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2408 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2409 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2410 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2411 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2412 index
= WaitForSingleObject(thread
, 200);
2413 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2414 CloseHandle(thread
);
2416 ReleaseSemaphore(handles
[0], 1, NULL
);
2417 ReleaseSemaphore(handles
[1], 1, NULL
);
2419 /* test with COWAIT_WAITALL */
2422 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2423 hr
= CoWaitForMultipleHandles(COWAIT_WAITALL
, 50, 2, handles
, &index
);
2424 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2425 ok(index
== 0, "expected index 0, got %u\n", index
);
2426 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2427 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2430 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2431 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2432 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2433 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2434 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2435 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2437 ReleaseSemaphore(handles
[0], 1, NULL
);
2438 ReleaseSemaphore(handles
[1], 1, NULL
);
2440 /* test with COWAIT_ALERTABLE */
2443 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2444 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 1, handles
, &index
);
2445 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2446 ok(index
== 0, "expected index 0, got %u\n", index
);
2447 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2448 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2451 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2452 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 2, handles
, &index
);
2453 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2454 ok(index
== 1, "expected index 1, got %u\n", index
);
2455 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2456 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2459 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2460 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 2, handles
, &index
);
2461 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2462 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2463 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2464 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2467 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2468 success
= QueueUserAPC(apc_test_proc
, GetCurrentThread(), 0);
2469 ok(success
, "QueueUserAPC failed %u\n", GetLastError());
2470 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 2, handles
, &index
);
2471 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2472 ok(index
== WAIT_IO_COMPLETION
, "expected index WAIT_IO_COMPLETION, got %u\n", index
);
2473 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2474 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2476 /* test with COWAIT_INPUTAVAILABLE (semaphores are still locked) */
2479 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2480 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_NOREMOVE
);
2481 ok(success
, "PeekMessageA returned FALSE\n");
2482 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2483 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2484 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2485 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2486 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2489 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2490 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_NOREMOVE
);
2491 ok(success
, "PeekMessageA returned FALSE\n");
2492 thread
= CreateThread(NULL
, 0, release_semaphore_thread
, handles
[1], 0, &tid
);
2493 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2494 hr
= CoWaitForMultipleHandles(COWAIT_INPUTAVAILABLE
, 50, 2, handles
, &index
);
2495 ok(hr
== RPC_S_CALLPENDING
|| broken(hr
== E_INVALIDARG
) || broken(hr
== S_OK
) /* Win 8 */,
2496 "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2497 if (hr
!= S_OK
) ReleaseSemaphore(handles
[1], 1, NULL
);
2498 ok(index
== 0 || broken(index
== 1) /* Win 8 */, "expected index 0, got %u\n", index
);
2499 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2500 ok(!success
|| broken(success
&& hr
== E_INVALIDARG
),
2501 "CoWaitForMultipleHandles didn't pump any messages\n");
2502 index
= WaitForSingleObject(thread
, 200);
2503 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2504 CloseHandle(thread
);
2506 /* test behaviour of WM_QUIT (semaphores are still locked) */
2508 PostMessageA(hWnd
, WM_QUIT
, 40, 0);
2509 memset(&msg
, 0, sizeof(msg
));
2510 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2511 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2512 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2513 ok(msg
.wParam
== 40, "expected msg.wParam = 40, got %lu\n", msg
.wParam
);
2514 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2515 ok(!success
, "PeekMessageA succeeded\n");
2518 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2519 PostMessageA(hWnd
, WM_QUIT
, 41, 0);
2520 thread
= CreateThread(NULL
, 0, post_message_thread
, hWnd
, 0, &tid
);
2521 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2522 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2523 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2524 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2525 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2527 ok(success
|| broken(!success
) /* Win 2000/XP/8 */, "PeekMessageA failed, error %u\n", GetLastError());
2528 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2529 ok(!success
, "PeekMessageA succeeded\n");
2530 memset(&msg
, 0, sizeof(msg
));
2531 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2533 ok(!success
|| broken(success
) /* Win 2000/XP/8 */, "PeekMessageA succeeded\n");
2536 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2537 ok(msg
.wParam
== 41, "expected msg.wParam = 41, got %lu\n", msg
.wParam
);
2539 index
= WaitForSingleObject(thread
, 200);
2540 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2541 CloseHandle(thread
);
2544 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2545 PostMessageA(hWnd
, WM_QUIT
, 42, 0);
2546 thread
= CreateThread(NULL
, 0, send_message_thread
, hWnd
, 0, &tid
);
2547 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2548 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2549 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2550 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2551 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2552 ok(!success
, "CoWaitForMultipleHandles didn't pump all WM_DDE_FIRST messages\n");
2553 memset(&msg
, 0, sizeof(msg
));
2554 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2555 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2556 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2557 ok(msg
.wParam
== 42, "expected msg.wParam = 42, got %lu\n", msg
.wParam
);
2558 index
= WaitForSingleObject(thread
, 200);
2559 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2560 CloseHandle(thread
);
2562 PostQuitMessage(43);
2563 memset(&msg
, 0, sizeof(msg
));
2564 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2565 ok(success
|| broken(!success
) /* Win 8 */, "PeekMessageA failed, error %u\n", GetLastError());
2567 win_skip("PostQuitMessage didn't queue a WM_QUIT message, skipping tests\n");
2570 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2571 ok(msg
.wParam
== 43, "expected msg.wParam = 43, got %lu\n", msg
.wParam
);
2572 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2573 ok(!success
, "PeekMessageA succeeded\n");
2576 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2577 PostQuitMessage(44);
2578 thread
= CreateThread(NULL
, 0, post_message_thread
, hWnd
, 0, &tid
);
2579 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2580 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2581 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2582 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2583 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2584 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2585 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2587 ok(!success
, "PeekMessageA succeeded\n");
2588 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2590 ok(!success
, "CoWaitForMultipleHandles didn't remove WM_QUIT messages\n");
2591 index
= WaitForSingleObject(thread
, 200);
2592 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2593 CloseHandle(thread
);
2596 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2597 PostQuitMessage(45);
2598 thread
= CreateThread(NULL
, 0, send_message_thread
, hWnd
, 0, &tid
);
2599 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2600 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2601 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2602 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2603 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2604 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2605 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2607 ok(!success
, "PeekMessageA succeeded\n");
2608 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2609 ok(!success
, "CoWaitForMultipleHandles didn't remove WM_QUIT messages\n");
2610 index
= WaitForSingleObject(thread
, 200);
2611 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2612 CloseHandle(thread
);
2615 /* test message pumping when CoWaitForMultipleHandles is called from non main apartment thread */
2616 thread
= CreateThread(NULL
, 0, test_CoWaitForMultipleHandles_thread
, handles
, 0, &tid
);
2617 index
= WaitForSingleObject(thread
, 500);
2618 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2619 CloseHandle(thread
);
2621 CloseHandle(handles
[0]);
2622 CloseHandle(handles
[1]);
2623 DestroyWindow(hWnd
);
2625 success
= UnregisterClassA(cls_name
, GetModuleHandleA(0));
2626 ok(success
, "UnregisterClass failed %u\n", GetLastError());
2631 static void init_funcs(void)
2633 HMODULE hOle32
= GetModuleHandleA("ole32");
2634 HMODULE hAdvapi32
= GetModuleHandleA("advapi32");
2635 HMODULE hkernel32
= GetModuleHandleA("kernel32");
2637 pCoGetObjectContext
= (void*)GetProcAddress(hOle32
, "CoGetObjectContext");
2638 pCoSwitchCallContext
= (void*)GetProcAddress(hOle32
, "CoSwitchCallContext");
2639 pCoGetTreatAsClass
= (void*)GetProcAddress(hOle32
,"CoGetTreatAsClass");
2640 pCoTreatAsClass
= (void*)GetProcAddress(hOle32
,"CoTreatAsClass");
2641 pCoGetContextToken
= (void*)GetProcAddress(hOle32
, "CoGetContextToken");
2642 pRegDeleteKeyExA
= (void*)GetProcAddress(hAdvapi32
, "RegDeleteKeyExA");
2643 pRegOverridePredefKey
= (void*)GetProcAddress(hAdvapi32
, "RegOverridePredefKey");
2644 pCoInitializeEx
= (void*)GetProcAddress(hOle32
, "CoInitializeEx");
2646 pActivateActCtx
= (void*)GetProcAddress(hkernel32
, "ActivateActCtx");
2647 pCreateActCtxW
= (void*)GetProcAddress(hkernel32
, "CreateActCtxW");
2648 pDeactivateActCtx
= (void*)GetProcAddress(hkernel32
, "DeactivateActCtx");
2649 pIsWow64Process
= (void*)GetProcAddress(hkernel32
, "IsWow64Process");
2650 pReleaseActCtx
= (void*)GetProcAddress(hkernel32
, "ReleaseActCtx");
2657 if (!pCoInitializeEx
)
2659 trace("You need DCOM95 installed to run this test\n");
2663 if (!pCreateActCtxW
)
2664 win_skip("Activation contexts are not supported, some tests will be skipped.\n");
2666 test_ProgIDFromCLSID();
2667 test_CLSIDFromProgID();
2668 test_CLSIDFromString();
2669 test_IIDFromString();
2670 test_StringFromGUID2();
2671 test_CoCreateInstance();
2673 test_CoGetClassObject();
2674 test_CoCreateInstanceEx();
2675 test_CoRegisterMessageFilter();
2676 test_CoRegisterPSClsid();
2677 test_CoGetPSClsid();
2678 test_CoUnmarshalInterface();
2679 test_CoGetInterfaceAndReleaseStream();
2680 test_CoMarshalInterface();
2681 test_CoMarshalInterThreadInterfaceInStream();
2682 test_CoRegisterClassObject();
2683 test_registered_object_thread_affinity();
2684 test_CoFreeUnusedLibraries();
2685 test_CoGetObjectContext();
2686 test_CoGetCallContext();
2687 test_CoGetContextToken();
2688 test_TreatAsClass();
2689 test_CoInitializeEx();
2690 test_OleRegGetMiscStatus();
2691 test_CoCreateGuid();
2692 test_CoWaitForMultipleHandles();