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
29 #define USE_COM_CONTEXT_DEF
32 #include "urlmon.h" /* for CLSID_FileProtocol */
38 #include "wine/test.h"
41 #define DEFINE_EXPECT(func) \
42 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
44 #define SET_EXPECT(func) \
45 expect_ ## func = TRUE
47 #define CHECK_EXPECT2(func) \
49 ok(expect_ ##func, "unexpected call " #func "\n"); \
50 called_ ## func = TRUE; \
53 #define CHECK_EXPECT(func) \
55 CHECK_EXPECT2(func); \
56 expect_ ## func = FALSE; \
59 #define CHECK_CALLED(func) \
61 ok(called_ ## func, "expected " #func "\n"); \
62 expect_ ## func = called_ ## func = FALSE; \
65 DEFINE_EXPECT(CreateStub
);
67 /* functions that are not present on all versions of Windows */
68 static HRESULT (WINAPI
* pCoInitializeEx
)(LPVOID lpReserved
, DWORD dwCoInit
);
69 static HRESULT (WINAPI
* pCoGetObjectContext
)(REFIID riid
, LPVOID
*ppv
);
70 static HRESULT (WINAPI
* pCoSwitchCallContext
)(IUnknown
*pObject
, IUnknown
**ppOldObject
);
71 static HRESULT (WINAPI
* pCoGetTreatAsClass
)(REFCLSID clsidOld
, LPCLSID pClsidNew
);
72 static HRESULT (WINAPI
* pCoTreatAsClass
)(REFCLSID clsidOld
, REFCLSID pClsidNew
);
73 static HRESULT (WINAPI
* pCoGetContextToken
)(ULONG_PTR
*token
);
74 static HRESULT (WINAPI
* pCoGetApartmentType
)(APTTYPE
*type
, APTTYPEQUALIFIER
*qualifier
);
75 static LONG (WINAPI
* pRegDeleteKeyExA
)(HKEY
, LPCSTR
, REGSAM
, DWORD
);
76 static LONG (WINAPI
* pRegOverridePredefKey
)(HKEY key
, HKEY override
);
78 static BOOL (WINAPI
*pActivateActCtx
)(HANDLE
,ULONG_PTR
*);
79 static HANDLE (WINAPI
*pCreateActCtxW
)(PCACTCTXW
);
80 static BOOL (WINAPI
*pDeactivateActCtx
)(DWORD
,ULONG_PTR
);
81 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
, LPBOOL
);
82 static void (WINAPI
*pReleaseActCtx
)(HANDLE
);
84 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
85 #define ok_more_than_one_lock() ok(cLocks > 0, "Number of locks should be > 0, but actually is %d\n", cLocks)
86 #define ok_no_locks() ok(cLocks == 0, "Number of locks should be 0, but actually is %d\n", cLocks)
88 static const CLSID CLSID_non_existent
= { 0x12345678, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
89 static const CLSID CLSID_StdFont
= { 0x0be35203, 0x8f91, 0x11ce, { 0x9d, 0xe3, 0x00, 0xaa, 0x00, 0x4b, 0xb8, 0x51 } };
90 static const GUID IID_Testiface
= { 0x22222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
91 static const GUID IID_Testiface2
= { 0x32222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
92 static const GUID IID_Testiface3
= { 0x42222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
93 static const GUID IID_Testiface4
= { 0x52222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
94 static const GUID IID_Testiface5
= { 0x62222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
95 static const GUID IID_Testiface6
= { 0x72222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
96 static const GUID IID_TestPS
= { 0x66666666, 0x8888, 0x7777, { 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 } };
98 DEFINE_GUID(CLSID_testclsid
, 0xacd014c7,0x9535,0x4fac,0x8b,0x53,0xa4,0x8c,0xa7,0xf4,0xd7,0x26);
100 static const WCHAR stdfont
[] = {'S','t','d','F','o','n','t',0};
101 static const WCHAR wszNonExistent
[] = {'N','o','n','E','x','i','s','t','e','n','t',0};
102 static const WCHAR wszCLSID_StdFont
[] =
104 '{','0','b','e','3','5','2','0','3','-','8','f','9','1','-','1','1','c','e','-',
105 '9','d','e','3','-','0','0','a','a','0','0','4','b','b','8','5','1','}',0
107 static const WCHAR progidW
[] = {'P','r','o','g','I','d','.','P','r','o','g','I','d',0};
108 static const WCHAR cf_brokenW
[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-',
109 'c','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}','a',0};
111 DEFINE_GUID(IID_IWineTest
, 0x5201163f, 0x8164, 0x4fd0, 0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd);
112 DEFINE_GUID(CLSID_WineOOPTest
, 0x5201163f, 0x8164, 0x4fd0, 0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd);
116 static void LockModule(void)
118 InterlockedIncrement(&cLocks
);
121 static void UnlockModule(void)
123 InterlockedDecrement(&cLocks
);
126 static HRESULT WINAPI
Test_IClassFactory_QueryInterface(
127 LPCLASSFACTORY iface
,
131 if (ppvObj
== NULL
) return E_POINTER
;
133 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
134 IsEqualGUID(riid
, &IID_IClassFactory
))
137 IClassFactory_AddRef(iface
);
142 return E_NOINTERFACE
;
145 static ULONG WINAPI
Test_IClassFactory_AddRef(LPCLASSFACTORY iface
)
148 return 2; /* non-heap-based object */
151 static ULONG WINAPI
Test_IClassFactory_Release(LPCLASSFACTORY iface
)
154 return 1; /* non-heap-based object */
157 static IID create_instance_iid
;
158 static HRESULT WINAPI
Test_IClassFactory_CreateInstance(
159 LPCLASSFACTORY iface
,
165 create_instance_iid
= *riid
;
166 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
167 return E_NOINTERFACE
;
170 static HRESULT WINAPI
Test_IClassFactory_LockServer(
171 LPCLASSFACTORY iface
,
177 static const IClassFactoryVtbl TestClassFactory_Vtbl
=
179 Test_IClassFactory_QueryInterface
,
180 Test_IClassFactory_AddRef
,
181 Test_IClassFactory_Release
,
182 Test_IClassFactory_CreateInstance
,
183 Test_IClassFactory_LockServer
186 static IClassFactory Test_ClassFactory
= { &TestClassFactory_Vtbl
};
188 static WCHAR manifest_path
[MAX_PATH
];
190 static BOOL
create_manifest_file(const char *filename
, const char *manifest
)
195 WCHAR path
[MAX_PATH
];
197 MultiByteToWideChar( CP_ACP
, 0, filename
, -1, path
, MAX_PATH
);
198 GetFullPathNameW(path
, ARRAY_SIZE(manifest_path
), manifest_path
, NULL
);
200 manifest_len
= strlen(manifest
);
201 file
= CreateFileW(path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
202 FILE_ATTRIBUTE_NORMAL
, NULL
);
203 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed: %u\n", GetLastError());
204 if(file
== INVALID_HANDLE_VALUE
)
206 WriteFile(file
, manifest
, manifest_len
, &size
, NULL
);
212 static HANDLE
activate_context(const char *manifest
, ULONG_PTR
*cookie
)
214 WCHAR path
[MAX_PATH
];
219 if (!pCreateActCtxW
) return NULL
;
221 create_manifest_file("file.manifest", manifest
);
223 MultiByteToWideChar( CP_ACP
, 0, "file.manifest", -1, path
, MAX_PATH
);
224 memset(&actctx
, 0, sizeof(ACTCTXW
));
225 actctx
.cbSize
= sizeof(ACTCTXW
);
226 actctx
.lpSource
= path
;
228 handle
= pCreateActCtxW(&actctx
);
229 ok(handle
!= INVALID_HANDLE_VALUE
|| broken(handle
== INVALID_HANDLE_VALUE
) /* some old XP/2k3 versions */,
230 "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
231 if (handle
== INVALID_HANDLE_VALUE
)
233 win_skip("activation context generation failed, some tests will be skipped\n");
237 ok(actctx
.cbSize
== sizeof(ACTCTXW
), "actctx.cbSize=%d\n", actctx
.cbSize
);
238 ok(actctx
.dwFlags
== 0, "actctx.dwFlags=%d\n", actctx
.dwFlags
);
239 ok(actctx
.lpSource
== path
, "actctx.lpSource=%p\n", actctx
.lpSource
);
240 ok(actctx
.wProcessorArchitecture
== 0, "actctx.wProcessorArchitecture=%d\n", actctx
.wProcessorArchitecture
);
241 ok(actctx
.wLangId
== 0, "actctx.wLangId=%d\n", actctx
.wLangId
);
242 ok(actctx
.lpAssemblyDirectory
== NULL
, "actctx.lpAssemblyDirectory=%p\n", actctx
.lpAssemblyDirectory
);
243 ok(actctx
.lpResourceName
== NULL
, "actctx.lpResourceName=%p\n", actctx
.lpResourceName
);
244 ok(actctx
.lpApplicationName
== NULL
, "actctx.lpApplicationName=%p\n", actctx
.lpApplicationName
);
245 ok(actctx
.hModule
== NULL
, "actctx.hModule=%p\n", actctx
.hModule
);
247 DeleteFileA("file.manifest");
251 ret
= pActivateActCtx(handle
, cookie
);
252 ok(ret
, "ActivateActCtx failed: %u\n", GetLastError());
258 static const char actctx_manifest
[] =
259 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
260 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\""
261 " publicKeyToken=\"6595b6414666f1df\" />"
262 "<file name=\"testlib.dll\">"
264 " clsid=\"{0000033a-0000-0000-c000-000000000046}\""
265 " progid=\"FTMarshal\""
268 " clsid=\"{5201163f-8164-4fd0-a1a2-5d5a3654d3bd}\""
269 " progid=\"WineOOPTest\""
271 " <comClass description=\"Test com class\""
272 " clsid=\"{12345678-1234-1234-1234-56789abcdef0}\""
273 " progid=\"ProgId.ProgId\""
274 " miscStatusIcon=\"recomposeonresize\""
276 " <comClass description=\"CustomFont Description\" clsid=\"{0be35203-8f91-11ce-9de3-00aa004bb851}\""
277 " progid=\"CustomFont\""
278 " miscStatusIcon=\"recomposeonresize\""
279 " miscStatusContent=\"insideout\""
281 " <comClass description=\"StdFont Description\" clsid=\"{0be35203-8f91-11ce-9de3-00aa004bb852}\""
282 " progid=\"StdFont\""
284 " <comClass clsid=\"{62222222-1234-1234-1234-56789abcdef0}\" >"
285 " <progid>ProgId.ProgId.1</progid>"
287 " <comInterfaceProxyStub "
289 " iid=\"{22222222-1234-1234-1234-56789abcdef0}\""
290 " proxyStubClsid32=\"{66666666-8888-7777-6666-555555555555}\""
293 " <comInterfaceExternalProxyStub "
294 " name=\"Iifaceps2\""
295 " iid=\"{32222222-1234-1234-1234-56789abcdef0}\""
297 " <comInterfaceExternalProxyStub "
298 " name=\"Iifaceps3\""
299 " iid=\"{42222222-1234-1234-1234-56789abcdef0}\""
300 " proxyStubClsid32=\"{66666666-8888-7777-6666-555555555555}\""
302 " <comInterfaceExternalProxyStub "
303 " name=\"Iifaceps4\""
304 " iid=\"{52222222-1234-1234-1234-56789abcdef0}\""
305 " proxyStubClsid32=\"{00000000-0000-0000-0000-000000000000}\""
308 " clsid=\"{72222222-1234-1234-1234-56789abcdef0}\""
311 " <progid>clrprogid.1</progid>"
315 DEFINE_GUID(CLSID_Testclass
, 0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0);
317 static void test_ProgIDFromCLSID(void)
319 ULONG_PTR cookie
= 0;
324 hr
= ProgIDFromCLSID(&CLSID_StdFont
, &progid
);
325 ok(hr
== S_OK
, "ProgIDFromCLSID failed with error 0x%08x\n", hr
);
328 ok(!lstrcmpiW(progid
, stdfont
), "Didn't get expected prog ID\n");
329 CoTaskMemFree(progid
);
332 progid
= (LPWSTR
)0xdeadbeef;
333 hr
= ProgIDFromCLSID(&CLSID_non_existent
, &progid
);
334 ok(hr
== REGDB_E_CLASSNOTREG
, "ProgIDFromCLSID returned %08x\n", hr
);
335 ok(progid
== NULL
, "ProgIDFromCLSID returns with progid %p\n", progid
);
337 hr
= ProgIDFromCLSID(&CLSID_StdFont
, NULL
);
338 ok(hr
== E_INVALIDARG
, "ProgIDFromCLSID should return E_INVALIDARG instead of 0x%08x\n", hr
);
340 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
342 static const WCHAR customfontW
[] = {'C','u','s','t','o','m','F','o','n','t',0};
344 hr
= ProgIDFromCLSID(&CLSID_non_existent
, &progid
);
345 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
346 ok(!lstrcmpiW(progid
, progidW
), "got %s\n", wine_dbgstr_w(progid
));
347 CoTaskMemFree(progid
);
349 /* try something registered and redirected */
351 hr
= ProgIDFromCLSID(&CLSID_StdFont
, &progid
);
352 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
353 ok(!lstrcmpiW(progid
, customfontW
), "got wrong progid %s\n", wine_dbgstr_w(progid
));
354 CoTaskMemFree(progid
);
356 /* classes without default progid, progid list is not used */
357 progid
= (void *)0xdeadbeef;
358 hr
= ProgIDFromCLSID(&IID_Testiface5
, &progid
);
359 ok(hr
== REGDB_E_CLASSNOTREG
&& progid
== NULL
, "got 0x%08x, progid %p\n", hr
, progid
);
361 progid
= (void *)0xdeadbeef;
362 hr
= ProgIDFromCLSID(&IID_Testiface6
, &progid
);
363 ok(hr
== REGDB_E_CLASSNOTREG
&& progid
== NULL
, "got 0x%08x, progid %p\n", hr
, progid
);
365 pDeactivateActCtx(0, cookie
);
366 pReleaseActCtx(handle
);
370 static void test_CLSIDFromProgID(void)
372 ULONG_PTR cookie
= 0;
375 HRESULT hr
= CLSIDFromProgID(stdfont
, &clsid
);
376 ok(hr
== S_OK
, "CLSIDFromProgID failed with error 0x%08x\n", hr
);
377 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
379 hr
= CLSIDFromString(stdfont
, &clsid
);
380 ok_ole_success(hr
, "CLSIDFromString");
381 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
383 /* test some failure cases */
385 hr
= CLSIDFromProgID(wszNonExistent
, NULL
);
386 ok(hr
== E_INVALIDARG
, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
388 hr
= CLSIDFromProgID(NULL
, &clsid
);
389 ok(hr
== E_INVALIDARG
, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
391 memset(&clsid
, 0xcc, sizeof(clsid
));
392 hr
= CLSIDFromProgID(wszNonExistent
, &clsid
);
393 ok(hr
== CO_E_CLASSSTRING
, "CLSIDFromProgID on nonexistent ProgID should have returned CO_E_CLASSSTRING instead of 0x%08x\n", hr
);
394 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "CLSIDFromProgID should have set clsid to all-zeros on failure\n");
396 /* fails without proper context */
397 memset(&clsid
, 0xcc, sizeof(clsid
));
398 hr
= CLSIDFromProgID(progidW
, &clsid
);
399 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
400 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "wrong clsid\n");
402 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
406 memset(&clsid
, 0xcc, sizeof(clsid
));
407 hr
= CLSIDFromProgID(wszNonExistent
, &clsid
);
408 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
409 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "should have zero CLSID on failure\n");
411 /* CLSIDFromString() doesn't check activation context */
412 hr
= CLSIDFromString(progidW
, &clsid
);
413 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
416 hr
= CLSIDFromProgID(progidW
, &clsid
);
417 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
418 /* it returns generated CLSID here */
419 ok(!IsEqualCLSID(&clsid
, &CLSID_non_existent
) && !IsEqualCLSID(&clsid
, &CLSID_NULL
),
420 "got wrong clsid %s\n", wine_dbgstr_guid(&clsid
));
422 /* duplicate progid present in context - returns generated guid here too */
424 hr
= CLSIDFromProgID(stdfont
, &clsid
);
425 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
426 clsid1
= CLSID_StdFont
;
427 /* that's where it differs from StdFont */
428 clsid1
.Data4
[7] = 0x52;
429 ok(!IsEqualCLSID(&clsid
, &CLSID_StdFont
) && !IsEqualCLSID(&clsid
, &CLSID_NULL
) && !IsEqualCLSID(&clsid
, &clsid1
),
430 "got %s\n", wine_dbgstr_guid(&clsid
));
432 pDeactivateActCtx(0, cookie
);
433 pReleaseActCtx(handle
);
437 static void test_CLSIDFromString(void)
440 WCHAR wszCLSID_Broken
[50];
443 HRESULT hr
= CLSIDFromString(wszCLSID_StdFont
, &clsid
);
444 ok_ole_success(hr
, "CLSIDFromString");
445 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
447 memset(&clsid
, 0xab, sizeof(clsid
));
448 hr
= CLSIDFromString(NULL
, &clsid
);
449 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
450 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "clsid wasn't equal to CLSID_NULL\n");
452 /* string is longer, but starts with a valid CLSID */
453 memset(&clsid
, 0, sizeof(clsid
));
454 hr
= CLSIDFromString(cf_brokenW
, &clsid
);
455 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
456 ok(IsEqualCLSID(&clsid
, &IID_IClassFactory
), "got %s\n", wine_dbgstr_guid(&clsid
));
458 lstrcpyW(wszCLSID_Broken
, wszCLSID_StdFont
);
459 for(i
= lstrlenW(wszCLSID_StdFont
); i
< 49; i
++)
460 wszCLSID_Broken
[i
] = 'A';
461 wszCLSID_Broken
[i
] = '\0';
463 memset(&clsid
, 0, sizeof(CLSID
));
464 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
465 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
466 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
468 wszCLSID_Broken
[lstrlenW(wszCLSID_StdFont
)-1] = 'A';
469 memset(&clsid
, 0, sizeof(CLSID
));
470 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
471 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
472 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
474 wszCLSID_Broken
[lstrlenW(wszCLSID_StdFont
)] = '\0';
475 memset(&clsid
, 0, sizeof(CLSID
));
476 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
477 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
478 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
480 wszCLSID_Broken
[lstrlenW(wszCLSID_StdFont
)-1] = '\0';
481 memset(&clsid
, 0, sizeof(CLSID
));
482 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
483 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
484 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
486 memset(&clsid
, 0xcc, sizeof(CLSID
));
487 hr
= CLSIDFromString(wszCLSID_Broken
+1, &clsid
);
488 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
489 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "clsid wasn't equal to CLSID_NULL\n");
491 wszCLSID_Broken
[9] = '*';
492 memset(&clsid
, 0xcc, sizeof(CLSID
));
493 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
494 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
495 ok(clsid
.Data1
== CLSID_StdFont
.Data1
, "Got %08x\n", clsid
.Data1
);
496 ok(clsid
.Data2
== 0xcccc, "Got %04x\n", clsid
.Data2
);
498 wszCLSID_Broken
[3] = '*';
499 memset(&clsid
, 0xcc, sizeof(CLSID
));
500 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
501 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
502 ok(clsid
.Data1
== 0xb, "Got %08x\n", clsid
.Data1
);
503 ok(clsid
.Data2
== 0xcccc, "Got %04x\n", clsid
.Data2
);
505 wszCLSID_Broken
[3] = '\0';
506 memset(&clsid
, 0xcc, sizeof(CLSID
));
507 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
508 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
509 ok(clsid
.Data1
== 0xb, "Got %08x\n", clsid
.Data1
);
510 ok(clsid
.Data2
== 0xcccc, "Got %04x\n", clsid
.Data2
);
513 static void test_IIDFromString(void)
515 static const WCHAR cfW
[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-',
516 'c','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
517 static const WCHAR brokenW
[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-',
518 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
519 static const WCHAR broken2W
[] = {'{','0','0','0','0','0','0','0','1','=','0','0','0','0','-','0','0','0','0','-',
520 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
521 static const WCHAR broken3W
[] = {'b','r','o','k','e','n','0','0','1','=','0','0','0','0','-','0','0','0','0','-',
522 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
526 hr
= IIDFromString(wszCLSID_StdFont
, &iid
);
527 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
528 ok(IsEqualIID(&iid
, &CLSID_StdFont
), "got iid %s\n", wine_dbgstr_guid(&iid
));
530 memset(&iid
, 0xab, sizeof(iid
));
531 hr
= IIDFromString(NULL
, &iid
);
532 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
533 ok(IsEqualIID(&iid
, &CLSID_NULL
), "got iid %s\n", wine_dbgstr_guid(&iid
));
535 hr
= IIDFromString(cfW
, &iid
);
536 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
537 ok(IsEqualIID(&iid
, &IID_IClassFactory
), "got iid %s\n", wine_dbgstr_guid(&iid
));
539 /* string starts with a valid IID but is longer */
540 memset(&iid
, 0xab, sizeof(iid
));
541 hr
= IIDFromString(cf_brokenW
, &iid
);
542 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
543 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
545 /* invalid IID in a valid format */
546 memset(&iid
, 0xab, sizeof(iid
));
547 hr
= IIDFromString(brokenW
, &iid
);
548 ok(hr
== CO_E_IIDSTRING
, "got 0x%08x\n", hr
);
549 ok(iid
.Data1
== 0x00000001, "Got %08x\n", iid
.Data1
);
551 memset(&iid
, 0xab, sizeof(iid
));
552 hr
= IIDFromString(broken2W
, &iid
);
553 ok(hr
== CO_E_IIDSTRING
, "got 0x%08x\n", hr
);
554 ok(iid
.Data1
== 0x00000001, "Got %08x\n", iid
.Data1
);
556 /* format is broken, but string length is okay */
557 memset(&iid
, 0xab, sizeof(iid
));
558 hr
= IIDFromString(broken3W
, &iid
);
559 ok(hr
== CO_E_IIDSTRING
, "got 0x%08x\n", hr
);
560 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
563 memset(&iid
, 0xab, sizeof(iid
));
564 hr
= IIDFromString(wszNonExistent
, &iid
);
565 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
566 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
569 memset(&iid
, 0xab, sizeof(iid
));
570 hr
= IIDFromString(stdfont
, &iid
);
571 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
572 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
575 static void test_StringFromGUID2(void)
580 /* invalid pointer */
581 SetLastError(0xdeadbeef);
582 len
= StringFromGUID2(NULL
,str
,50);
583 ok(len
== 0, "len: %d (expected 0)\n", len
);
584 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %x\n", GetLastError());
586 /* Test corner cases for buffer size */
587 len
= StringFromGUID2(&CLSID_StdFont
,str
,50);
588 ok(len
== 39, "len: %d (expected 39)\n", len
);
589 ok(!lstrcmpiW(str
, wszCLSID_StdFont
),"string wasn't equal for CLSID_StdFont\n");
591 memset(str
,0,sizeof str
);
592 len
= StringFromGUID2(&CLSID_StdFont
,str
,39);
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 len
= StringFromGUID2(&CLSID_StdFont
,str
,38);
597 ok(len
== 0, "len: %d (expected 0)\n", len
);
599 len
= StringFromGUID2(&CLSID_StdFont
,str
,30);
600 ok(len
== 0, "len: %d (expected 0)\n", len
);
603 #define test_apt_type(t, q) _test_apt_type(t, q, __LINE__)
604 static void _test_apt_type(APTTYPE expected_type
, APTTYPEQUALIFIER expected_qualifier
, int line
)
606 APTTYPEQUALIFIER qualifier
= ~0u;
610 if (!pCoGetApartmentType
)
613 hr
= pCoGetApartmentType(&type
, &qualifier
);
614 ok_(__FILE__
, line
)(hr
== S_OK
|| hr
== CO_E_NOTINITIALIZED
, "Unexpected return code: 0x%08x\n", hr
);
615 ok_(__FILE__
, line
)(type
== expected_type
, "Wrong apartment type %d, expected %d\n", type
, expected_type
);
616 ok_(__FILE__
, line
)(qualifier
== expected_qualifier
, "Wrong apartment qualifier %d, expected %d\n", qualifier
,
620 static void test_CoCreateInstance(void)
624 REFCLSID rclsid
= &CLSID_InternetZoneManager
;
626 pUnk
= (IUnknown
*)0xdeadbeef;
627 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
628 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
629 ok(pUnk
== NULL
, "CoCreateInstance should have changed the passed in pointer to NULL, instead of %p\n", pUnk
);
633 /* test errors returned for non-registered clsids */
634 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
635 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered inproc server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
636 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_INPROC_HANDLER
, &IID_IUnknown
, (void **)&pUnk
);
637 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered inproc handler should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
638 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_LOCAL_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
639 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered local server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
640 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_REMOTE_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
641 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered remote server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
643 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
644 if(hr
== REGDB_E_CLASSNOTREG
)
646 skip("IE not installed so can't test CoCreateInstance\n");
651 ok_ole_success(hr
, "CoCreateInstance");
652 if(pUnk
) IUnknown_Release(pUnk
);
655 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
656 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
658 test_apt_type(APTTYPE_CURRENT
, APTTYPEQUALIFIER_NONE
);
661 static void test_CoGetClassObject(void)
667 REFCLSID rclsid
= &CLSID_InternetZoneManager
;
671 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
672 ok(hr
== CO_E_NOTINITIALIZED
, "CoGetClassObject should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
673 ok(pUnk
== NULL
, "CoGetClassObject should have changed the passed in pointer to NULL, instead of %p\n", pUnk
);
675 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, NULL
);
676 ok(hr
== E_INVALIDARG
||
677 broken(hr
== CO_E_NOTINITIALIZED
), /* win9x */
678 "CoGetClassObject should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
680 test_apt_type(APTTYPE_CURRENT
, APTTYPEQUALIFIER_NONE
);
682 if (!pRegOverridePredefKey
)
684 win_skip("RegOverridePredefKey not available\n");
688 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
690 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
693 IUnknown_Release(pUnk
);
695 res
= RegCreateKeyExA(HKEY_CURRENT_USER
, "Software\\Classes", 0, NULL
, 0,
696 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
);
697 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
699 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, hkey
);
700 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
702 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
703 ok(hr
== S_OK
, "CoGetClassObject should have returned S_OK instead of 0x%08x\n", hr
);
705 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, NULL
);
706 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
708 if (hr
== S_OK
) IUnknown_Release(pUnk
);
712 hr
= CoGetClassObject(&CLSID_InProcFreeMarshaler
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
713 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
714 IUnknown_Release(pUnk
);
716 /* context redefines FreeMarshaler CLSID */
717 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
719 hr
= CoGetClassObject(&CLSID_InProcFreeMarshaler
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
720 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
721 IUnknown_Release(pUnk
);
723 pDeactivateActCtx(0, cookie
);
724 pReleaseActCtx(handle
);
730 static void test_CoCreateInstanceEx(void)
732 MULTI_QI qi_res
= { &IID_IMoniker
};
738 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
739 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
740 ok_ole_success(hr
, "CoRegisterClassObject");
742 create_instance_iid
= IID_NULL
;
743 hr
= CoCreateInstanceEx(&CLSID_WineOOPTest
, NULL
, CLSCTX_INPROC_SERVER
, NULL
, 1, &qi_res
);
744 ok(hr
== E_NOINTERFACE
, "CoCreateInstanceEx failed: %08x\n", hr
);
745 ok(IsEqualGUID(&create_instance_iid
, qi_res
.pIID
), "Unexpected CreateInstance iid %s\n",
746 wine_dbgstr_guid(&create_instance_iid
));
748 hr
= CoRevokeClassObject(cookie
);
749 ok_ole_success(hr
, "CoRevokeClassObject");
754 static ATOM
register_dummy_class(void)
762 GetModuleHandleA(NULL
),
764 LoadCursorA(NULL
, (LPSTR
)IDC_ARROW
),
765 (HBRUSH
)(COLOR_BTNFACE
+1),
770 return RegisterClassA(&wc
);
773 static void test_ole_menu(void)
778 hwndFrame
= CreateWindowA((LPCSTR
)MAKEINTATOM(register_dummy_class()), "Test", 0, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, NULL
, NULL
, NULL
, NULL
);
779 hr
= OleSetMenuDescriptor(NULL
, hwndFrame
, NULL
, NULL
, NULL
);
780 todo_wine
ok_ole_success(hr
, "OleSetMenuDescriptor");
782 DestroyWindow(hwndFrame
);
786 static HRESULT WINAPI
MessageFilter_QueryInterface(IMessageFilter
*iface
, REFIID riid
, void ** ppvObj
)
788 if (ppvObj
== NULL
) return E_POINTER
;
790 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
791 IsEqualGUID(riid
, &IID_IClassFactory
))
794 IMessageFilter_AddRef(iface
);
798 return E_NOINTERFACE
;
801 static ULONG WINAPI
MessageFilter_AddRef(IMessageFilter
*iface
)
803 return 2; /* non-heap object */
806 static ULONG WINAPI
MessageFilter_Release(IMessageFilter
*iface
)
808 return 1; /* non-heap object */
811 static DWORD WINAPI
MessageFilter_HandleInComingCall(
812 IMessageFilter
*iface
,
814 HTASK threadIDCaller
,
816 LPINTERFACEINFO lpInterfaceInfo
)
818 trace("HandleInComingCall\n");
819 return SERVERCALL_ISHANDLED
;
822 static DWORD WINAPI
MessageFilter_RetryRejectedCall(
823 IMessageFilter
*iface
,
824 HTASK threadIDCallee
,
828 trace("RetryRejectedCall\n");
832 static DWORD WINAPI
MessageFilter_MessagePending(
833 IMessageFilter
*iface
,
834 HTASK threadIDCallee
,
838 trace("MessagePending\n");
839 todo_wine
ok(0, "unexpected call\n");
840 return PENDINGMSG_WAITNOPROCESS
;
843 static const IMessageFilterVtbl MessageFilter_Vtbl
=
845 MessageFilter_QueryInterface
,
846 MessageFilter_AddRef
,
847 MessageFilter_Release
,
848 MessageFilter_HandleInComingCall
,
849 MessageFilter_RetryRejectedCall
,
850 MessageFilter_MessagePending
853 static IMessageFilter MessageFilter
= { &MessageFilter_Vtbl
};
855 static void test_CoRegisterMessageFilter(void)
858 IMessageFilter
*prev_filter
;
860 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
861 ok(hr
== CO_E_NOT_SUPPORTED
,
862 "CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08x\n",
865 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
866 prev_filter
= (IMessageFilter
*)0xdeadbeef;
867 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
868 ok(hr
== CO_E_NOT_SUPPORTED
,
869 "CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08x\n",
871 ok(prev_filter
== (IMessageFilter
*)0xdeadbeef,
872 "prev_filter should have been set to %p\n", prev_filter
);
875 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
877 hr
= CoRegisterMessageFilter(NULL
, NULL
);
878 ok_ole_success(hr
, "CoRegisterMessageFilter");
880 prev_filter
= (IMessageFilter
*)0xdeadbeef;
881 hr
= CoRegisterMessageFilter(NULL
, &prev_filter
);
882 ok_ole_success(hr
, "CoRegisterMessageFilter");
883 ok(prev_filter
== NULL
, "prev_filter should have been set to NULL instead of %p\n", prev_filter
);
885 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
886 ok_ole_success(hr
, "CoRegisterMessageFilter");
887 ok(prev_filter
== NULL
, "prev_filter should have been set to NULL instead of %p\n", prev_filter
);
889 hr
= CoRegisterMessageFilter(NULL
, NULL
);
890 ok_ole_success(hr
, "CoRegisterMessageFilter");
895 static IUnknown Test_Unknown
;
897 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
899 return IUnknown_QueryInterface(&Test_Unknown
, riid
, ppv
);
902 static ULONG WINAPI
EnumOLEVERB_AddRef(IEnumOLEVERB
*iface
)
907 static ULONG WINAPI
EnumOLEVERB_Release(IEnumOLEVERB
*iface
)
912 static HRESULT WINAPI
EnumOLEVERB_Next(IEnumOLEVERB
*iface
, ULONG celt
, OLEVERB
*rgelt
, ULONG
*fetched
)
914 ok(0, "unexpected call\n");
918 static HRESULT WINAPI
EnumOLEVERB_Skip(IEnumOLEVERB
*iface
, ULONG celt
)
920 ok(0, "unexpected call\n");
924 static HRESULT WINAPI
EnumOLEVERB_Reset(IEnumOLEVERB
*iface
)
926 ok(0, "unexpected call\n");
930 static HRESULT WINAPI
EnumOLEVERB_Clone(IEnumOLEVERB
*iface
, IEnumOLEVERB
**ppenum
)
932 ok(0, "unexpected call\n");
936 static const IEnumOLEVERBVtbl EnumOLEVERBVtbl
= {
937 EnumOLEVERB_QueryInterface
,
946 static IEnumOLEVERB EnumOLEVERB
= { &EnumOLEVERBVtbl
};
948 static HRESULT WINAPI
Test_IUnknown_QueryInterface(
953 if (ppvObj
== NULL
) return E_POINTER
;
955 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IWineTest
)) {
957 }else if(IsEqualIID(riid
, &IID_IEnumOLEVERB
)) {
958 *ppvObj
= &EnumOLEVERB
;
961 return E_NOINTERFACE
;
964 IUnknown_AddRef((IUnknown
*)*ppvObj
);
968 static ULONG WINAPI
Test_IUnknown_AddRef(IUnknown
*iface
)
970 return 2; /* non-heap-based object */
973 static ULONG WINAPI
Test_IUnknown_Release(IUnknown
*iface
)
975 return 1; /* non-heap-based object */
978 static const IUnknownVtbl TestUnknown_Vtbl
=
980 Test_IUnknown_QueryInterface
,
981 Test_IUnknown_AddRef
,
982 Test_IUnknown_Release
,
985 static IUnknown Test_Unknown
= { &TestUnknown_Vtbl
};
987 static IPSFactoryBuffer
*ps_factory_buffer
;
989 static HRESULT WINAPI
PSFactoryBuffer_QueryInterface(
990 IPSFactoryBuffer
* This
,
991 /* [in] */ REFIID riid
,
992 /* [iid_is][out] */ void **ppvObject
)
994 if (IsEqualIID(riid
, &IID_IUnknown
) ||
995 IsEqualIID(riid
, &IID_IPSFactoryBuffer
))
998 IPSFactoryBuffer_AddRef(This
);
1001 return E_NOINTERFACE
;
1004 static ULONG WINAPI
PSFactoryBuffer_AddRef(
1005 IPSFactoryBuffer
* This
)
1010 static ULONG WINAPI
PSFactoryBuffer_Release(
1011 IPSFactoryBuffer
* This
)
1016 static HRESULT WINAPI
PSFactoryBuffer_CreateProxy(
1017 IPSFactoryBuffer
* This
,
1018 /* [in] */ IUnknown
*pUnkOuter
,
1019 /* [in] */ REFIID riid
,
1020 /* [out] */ IRpcProxyBuffer
**ppProxy
,
1021 /* [out] */ void **ppv
)
1026 static HRESULT WINAPI
PSFactoryBuffer_CreateStub(
1027 IPSFactoryBuffer
* This
,
1028 /* [in] */ REFIID riid
,
1029 /* [unique][in] */ IUnknown
*pUnkServer
,
1030 /* [out] */ IRpcStubBuffer
**ppStub
)
1032 CHECK_EXPECT(CreateStub
);
1034 ok(pUnkServer
== (IUnknown
*)&Test_Unknown
, "unexpected pUnkServer %p\n", pUnkServer
);
1035 if(!ps_factory_buffer
)
1038 return IPSFactoryBuffer_CreateStub(ps_factory_buffer
, &IID_IEnumOLEVERB
, pUnkServer
, ppStub
);
1041 static IPSFactoryBufferVtbl PSFactoryBufferVtbl
=
1043 PSFactoryBuffer_QueryInterface
,
1044 PSFactoryBuffer_AddRef
,
1045 PSFactoryBuffer_Release
,
1046 PSFactoryBuffer_CreateProxy
,
1047 PSFactoryBuffer_CreateStub
1050 static IPSFactoryBuffer PSFactoryBuffer
= { &PSFactoryBufferVtbl
};
1052 static const CLSID CLSID_WineTestPSFactoryBuffer
=
1057 {0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd}
1058 }; /* 52011640-8164-4fd0-a1a2-5d5a3654d3bd */
1060 static DWORD CALLBACK
register_ps_clsid_thread(void *context
)
1065 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1067 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1068 ok_ole_success(hr
, "CoGetPSClsid");
1069 ok(IsEqualGUID(&clsid
, &CLSID_WineTestPSFactoryBuffer
), "expected %s, got %s\n",
1070 wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer
), wine_dbgstr_guid(&clsid
));
1072 /* test registering a PSClsid in an apartment which is then destroyed */
1073 hr
= CoRegisterPSClsid(&IID_TestPS
, &clsid
);
1074 ok_ole_success(hr
, "CoRegisterPSClsid");
1081 static void test_CoRegisterPSClsid(void)
1084 DWORD dwRegistrationKey
;
1090 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
1091 ok(hr
== CO_E_NOTINITIALIZED
, "CoRegisterPSClsid should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
1093 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1095 hr
= CoRegisterClassObject(&CLSID_WineTestPSFactoryBuffer
, (IUnknown
*)&PSFactoryBuffer
,
1096 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &dwRegistrationKey
);
1097 ok_ole_success(hr
, "CoRegisterClassObject");
1099 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
1100 ok_ole_success(hr
, "CoRegisterPSClsid");
1102 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1103 ok_ole_success(hr
, "CoGetPSClsid");
1104 ok(IsEqualGUID(&clsid
, &CLSID_WineTestPSFactoryBuffer
), "expected %s, got %s\n",
1105 wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer
), wine_dbgstr_guid(&clsid
));
1107 thread
= CreateThread(NULL
, 0, register_ps_clsid_thread
, NULL
, 0, &tid
);
1108 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1109 ok(!WaitForSingleObject(thread
, 10000), "wait timed out\n");
1110 CloseHandle(thread
);
1112 hr
= CoGetPSClsid(&IID_TestPS
, &clsid
);
1113 ok_ole_success(hr
, "CoGetPSClsid");
1114 ok(IsEqualGUID(&clsid
, &CLSID_WineTestPSFactoryBuffer
), "expected %s, got %s\n",
1115 wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer
), wine_dbgstr_guid(&clsid
));
1117 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
1118 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1120 SET_EXPECT(CreateStub
);
1121 hr
= CoMarshalInterface(stream
, &IID_IWineTest
, &Test_Unknown
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1122 ok(hr
== E_NOTIMPL
, "CoMarshalInterface should have returned E_NOTIMPL instead of 0x%08x\n", hr
);
1123 CHECK_CALLED(CreateStub
);
1125 hr
= CoGetPSClsid(&IID_IEnumOLEVERB
, &clsid
);
1126 ok_ole_success(hr
, "CoGetPSClsid");
1128 hr
= CoGetClassObject(&clsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IPSFactoryBuffer
, (void **)&ps_factory_buffer
);
1129 ok_ole_success(hr
, "CoGetClassObject");
1131 hr
= CoRegisterPSClsid(&IID_IEnumOLEVERB
, &CLSID_WineTestPSFactoryBuffer
);
1132 ok_ole_success(hr
, "CoRegisterPSClsid");
1134 SET_EXPECT(CreateStub
);
1135 hr
= CoMarshalInterface(stream
, &IID_IEnumOLEVERB
, (IUnknown
*)&EnumOLEVERB
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1136 ok(hr
== S_OK
, "CoMarshalInterface should have returned S_OK instead of 0x%08x\n", hr
);
1137 CHECK_CALLED(CreateStub
);
1139 hr
= CoMarshalInterface(stream
, &IID_IEnumOLEVERB
, &Test_Unknown
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1140 ok(hr
== S_OK
, "CoMarshalInterface should have returned S_OK instead of 0x%08x\n", hr
);
1142 IStream_Release(stream
);
1143 IPSFactoryBuffer_Release(ps_factory_buffer
);
1144 ps_factory_buffer
= NULL
;
1146 hr
= CoRevokeClassObject(dwRegistrationKey
);
1147 ok_ole_success(hr
, "CoRevokeClassObject");
1151 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1153 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1154 ok(hr
== REGDB_E_IIDNOTREG
, "CoGetPSClsid should have returned REGDB_E_IIDNOTREG instead of 0x%08x\n", hr
);
1156 hr
= CoGetPSClsid(&IID_TestPS
, &clsid
);
1157 ok(hr
== REGDB_E_IIDNOTREG
, "CoGetPSClsid should have returned REGDB_E_IIDNOTREG instead of 0x%08x\n", hr
);
1161 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
1163 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
1164 ok_ole_success(hr
, "CoRegisterPSClsid");
1166 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1167 ok_ole_success(hr
, "CoGetPSClsid");
1168 ok(IsEqualGUID(&clsid
, &CLSID_WineTestPSFactoryBuffer
), "expected %s, got %s\n",
1169 wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer
), wine_dbgstr_guid(&clsid
));
1171 thread
= CreateThread(NULL
, 0, register_ps_clsid_thread
, NULL
, 0, &tid
);
1172 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1173 ok(!WaitForSingleObject(thread
, 10000), "wait timed out\n");
1174 CloseHandle(thread
);
1176 hr
= CoGetPSClsid(&IID_TestPS
, &clsid
);
1177 ok_ole_success(hr
, "CoGetPSClsid");
1178 ok(IsEqualGUID(&clsid
, &CLSID_WineTestPSFactoryBuffer
), "expected %s, got %s\n",
1179 wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer
), wine_dbgstr_guid(&clsid
));
1184 static void test_CoGetPSClsid(void)
1192 const BOOL is_win64
= (sizeof(void*) != sizeof(int));
1193 BOOL is_wow64
= FALSE
;
1195 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1196 ok(hr
== CO_E_NOTINITIALIZED
,
1197 "CoGetPSClsid should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n",
1200 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1202 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1203 ok_ole_success(hr
, "CoGetPSClsid");
1205 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1206 ok(hr
== REGDB_E_IIDNOTREG
,
1207 "CoGetPSClsid for random IID returned 0x%08x instead of REGDB_E_IIDNOTREG\n",
1210 hr
= CoGetPSClsid(&IID_IClassFactory
, NULL
);
1211 ok(hr
== E_INVALIDARG
,
1212 "CoGetPSClsid for null clsid returned 0x%08x instead of E_INVALIDARG\n",
1215 if (!pRegOverridePredefKey
)
1217 win_skip("RegOverridePredefKey not available\n");
1221 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1222 ok_ole_success(hr
, "CoGetPSClsid");
1224 res
= RegCreateKeyExA(HKEY_CURRENT_USER
, "Software\\Classes", 0, NULL
, 0,
1225 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
);
1226 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1228 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, hkey
);
1229 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
1231 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1232 ok_ole_success(hr
, "CoGetPSClsid");
1234 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, NULL
);
1235 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
1239 /* not registered CLSID */
1240 hr
= CoGetPSClsid(&IID_Testiface
, &clsid
);
1241 ok(hr
== REGDB_E_IIDNOTREG
, "got 0x%08x\n", hr
);
1243 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
1245 memset(&clsid
, 0, sizeof(clsid
));
1246 hr
= CoGetPSClsid(&IID_Testiface
, &clsid
);
1247 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1248 ok(IsEqualGUID(&clsid
, &IID_Testiface
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1250 memset(&clsid
, 0, sizeof(clsid
));
1251 hr
= CoGetPSClsid(&IID_Testiface2
, &clsid
);
1252 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1253 ok(IsEqualGUID(&clsid
, &IID_Testiface2
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1255 memset(&clsid
, 0, sizeof(clsid
));
1256 hr
= CoGetPSClsid(&IID_Testiface3
, &clsid
);
1257 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1258 ok(IsEqualGUID(&clsid
, &IID_TestPS
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1260 memset(&clsid
, 0xaa, sizeof(clsid
));
1261 hr
= CoGetPSClsid(&IID_Testiface4
, &clsid
);
1262 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1263 ok(IsEqualGUID(&clsid
, &GUID_NULL
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1265 /* register same interface and try to get CLSID back */
1266 hr
= CoRegisterPSClsid(&IID_Testiface
, &IID_Testiface4
);
1267 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1268 memset(&clsid
, 0, sizeof(clsid
));
1269 hr
= CoGetPSClsid(&IID_Testiface
, &clsid
);
1270 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1271 ok(IsEqualGUID(&clsid
, &IID_Testiface4
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1273 pDeactivateActCtx(0, cookie
);
1274 pReleaseActCtx(handle
);
1277 if (pRegDeleteKeyExA
&&
1279 (pIsWow64Process
&& pIsWow64Process(GetCurrentProcess(), &is_wow64
) && is_wow64
)))
1281 static GUID IID_DeadBeef
= {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
1282 static const char clsidDeadBeef
[] = "{deadbeef-dead-beef-dead-beefdeadbeef}";
1283 static const char clsidA
[] = "{66666666-8888-7777-6666-555555555555}";
1284 HKEY hkey_iface
, hkey_psclsid
;
1285 REGSAM opposite
= is_win64
? KEY_WOW64_32KEY
: KEY_WOW64_64KEY
;
1287 hr
= CoGetPSClsid(&IID_DeadBeef
, &clsid
);
1288 ok(hr
== REGDB_E_IIDNOTREG
, "got 0x%08x\n", hr
);
1290 res
= RegCreateKeyExA(HKEY_CLASSES_ROOT
, "Interface",
1291 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
, NULL
, &hkey_iface
, NULL
);
1292 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1293 res
= RegCreateKeyExA(hkey_iface
, clsidDeadBeef
,
1294 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
, NULL
, &hkey
, NULL
);
1295 if (res
== ERROR_ACCESS_DENIED
)
1297 win_skip("Failed to create a key, skipping some of CoGetPSClsid() tests\n");
1301 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1302 res
= RegCreateKeyExA(hkey
, "ProxyStubClsid32",
1303 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
, NULL
, &hkey_psclsid
, NULL
);
1304 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1305 res
= RegSetValueExA(hkey_psclsid
, NULL
, 0, REG_SZ
, (const BYTE
*)clsidA
, strlen(clsidA
)+1);
1306 ok(!res
, "RegSetValueEx returned %d\n", res
);
1307 RegCloseKey(hkey_psclsid
);
1309 hr
= CoGetPSClsid(&IID_DeadBeef
, &clsid
);
1310 ok_ole_success(hr
, "CoGetPSClsid");
1311 ok(IsEqualGUID(&clsid
, &IID_TestPS
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1313 res
= pRegDeleteKeyExA(hkey
, "ProxyStubClsid32", opposite
, 0);
1314 ok(!res
, "RegDeleteKeyEx returned %d\n", res
);
1316 res
= pRegDeleteKeyExA(hkey_iface
, clsidDeadBeef
, opposite
, 0);
1317 ok(!res
, "RegDeleteKeyEx returned %d\n", res
);
1320 RegCloseKey(hkey_iface
);
1326 /* basic test, mainly for invalid arguments. see marshal.c for more */
1327 static void test_CoUnmarshalInterface(void)
1333 hr
= CoUnmarshalInterface(NULL
, &IID_IUnknown
, (void **)&pProxy
);
1334 ok(hr
== E_INVALIDARG
, "CoUnmarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1336 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
1337 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1339 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, (void **)&pProxy
);
1341 ok(hr
== CO_E_NOTINITIALIZED
, "CoUnmarshalInterface should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
1343 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1345 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, (void **)&pProxy
);
1346 ok(hr
== STG_E_READFAULT
, "CoUnmarshalInterface should have returned STG_E_READFAULT instead of 0x%08x\n", hr
);
1350 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, NULL
);
1351 ok(hr
== E_INVALIDARG
, "CoUnmarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1353 IStream_Release(pStream
);
1356 static void test_CoGetInterfaceAndReleaseStream(void)
1361 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1363 hr
= CoGetInterfaceAndReleaseStream(NULL
, &IID_IUnknown
, (void**)&pUnk
);
1364 ok(hr
== E_INVALIDARG
, "hr %08x\n", hr
);
1369 /* basic test, mainly for invalid arguments. see marshal.c for more */
1370 static void test_CoMarshalInterface(void)
1374 static const LARGE_INTEGER llZero
;
1376 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1378 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
1379 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1381 hr
= CoMarshalInterface(pStream
, &IID_IUnknown
, NULL
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1382 ok(hr
== E_INVALIDARG
, "CoMarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1384 hr
= CoMarshalInterface(NULL
, &IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1385 ok(hr
== E_INVALIDARG
, "CoMarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1387 hr
= CoMarshalInterface(pStream
, &IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1388 ok_ole_success(hr
, "CoMarshalInterface");
1390 /* stream not rewound */
1391 hr
= CoReleaseMarshalData(pStream
);
1392 ok(hr
== STG_E_READFAULT
, "CoReleaseMarshalData should have returned STG_E_READFAULT instead of 0x%08x\n", hr
);
1394 hr
= IStream_Seek(pStream
, llZero
, STREAM_SEEK_SET
, NULL
);
1395 ok_ole_success(hr
, "IStream_Seek");
1397 hr
= CoReleaseMarshalData(pStream
);
1398 ok_ole_success(hr
, "CoReleaseMarshalData");
1400 IStream_Release(pStream
);
1405 static void test_CoMarshalInterThreadInterfaceInStream(void)
1409 IClassFactory
*pProxy
;
1411 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1415 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, NULL
);
1416 ok(hr
== E_INVALIDARG
, "CoMarshalInterThreadInterfaceInStream should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1418 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, NULL
, &pStream
);
1419 ok(hr
== E_INVALIDARG
, "CoMarshalInterThreadInterfaceInStream should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1423 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, &pStream
);
1424 ok_ole_success(hr
, "CoMarshalInterThreadInterfaceInStream");
1426 ok_more_than_one_lock();
1428 hr
= CoUnmarshalInterface(pStream
, &IID_IClassFactory
, (void **)&pProxy
);
1429 ok_ole_success(hr
, "CoUnmarshalInterface");
1431 IClassFactory_Release(pProxy
);
1432 IStream_Release(pStream
);
1439 static void test_CoRegisterClassObject(void)
1441 ULONG_PTR ctxcookie
;
1447 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1449 /* CLSCTX_INPROC_SERVER */
1450 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1451 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1452 ok_ole_success(hr
, "CoRegisterClassObject");
1453 hr
= CoRevokeClassObject(cookie
);
1454 ok_ole_success(hr
, "CoRevokeClassObject");
1456 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1457 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
1458 ok_ole_success(hr
, "CoRegisterClassObject");
1459 hr
= CoRevokeClassObject(cookie
);
1460 ok_ole_success(hr
, "CoRevokeClassObject");
1462 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1463 CLSCTX_INPROC_SERVER
, REGCLS_MULTI_SEPARATE
, &cookie
);
1464 ok_ole_success(hr
, "CoRegisterClassObject");
1465 hr
= CoRevokeClassObject(cookie
);
1466 ok_ole_success(hr
, "CoRevokeClassObject");
1468 /* CLSCTX_LOCAL_SERVER */
1469 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1470 CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1471 ok_ole_success(hr
, "CoRegisterClassObject");
1472 hr
= CoRevokeClassObject(cookie
);
1473 ok_ole_success(hr
, "CoRevokeClassObject");
1475 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1476 CLSCTX_LOCAL_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
1477 ok_ole_success(hr
, "CoRegisterClassObject");
1478 hr
= CoRevokeClassObject(cookie
);
1479 ok_ole_success(hr
, "CoRevokeClassObject");
1481 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1482 CLSCTX_LOCAL_SERVER
, REGCLS_MULTI_SEPARATE
, &cookie
);
1483 ok_ole_success(hr
, "CoRegisterClassObject");
1484 hr
= CoRevokeClassObject(cookie
);
1485 ok_ole_success(hr
, "CoRevokeClassObject");
1487 /* CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER */
1488 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1489 CLSCTX_INPROC_SERVER
|CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1490 ok_ole_success(hr
, "CoRegisterClassObject");
1491 hr
= CoRevokeClassObject(cookie
);
1492 ok_ole_success(hr
, "CoRevokeClassObject");
1494 /* test whether an object that doesn't support IClassFactory can be
1495 * registered for CLSCTX_LOCAL_SERVER */
1496 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, &Test_Unknown
,
1497 CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1498 ok_ole_success(hr
, "CoRegisterClassObject");
1499 hr
= CoRevokeClassObject(cookie
);
1500 ok_ole_success(hr
, "CoRevokeClassObject");
1502 /* test whether registered class becomes invalid when apartment is destroyed */
1503 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1504 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1505 ok_ole_success(hr
, "CoRegisterClassObject");
1508 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1510 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
,
1511 &IID_IClassFactory
, (void **)&pcf
);
1512 ok(hr
== REGDB_E_CLASSNOTREG
, "object registered in an apartment shouldn't accessible after it is destroyed\n");
1514 /* crashes with at least win9x DCOM! */
1516 CoRevokeClassObject(cookie
);
1518 /* test that object is accessible */
1519 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
, CLSCTX_INPROC_SERVER
,
1520 REGCLS_MULTIPLEUSE
, &cookie
);
1521 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1523 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&pcf
);
1524 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1525 IClassFactory_Release(pcf
);
1527 /* context now contains CLSID_WineOOPTest, test if registered one could still be used */
1528 if ((handle
= activate_context(actctx_manifest
, &ctxcookie
)))
1530 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&pcf
);
1532 ok(hr
== HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND
), "got 0x%08x\n", hr
);
1534 pDeactivateActCtx(0, ctxcookie
);
1535 pReleaseActCtx(handle
);
1538 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&pcf
);
1539 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1540 IClassFactory_Release(pcf
);
1542 hr
= CoRevokeClassObject(cookie
);
1543 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1548 static HRESULT
get_class_object(CLSCTX clsctx
)
1553 hr
= CoGetClassObject(&CLSID_WineOOPTest
, clsctx
, NULL
, &IID_IClassFactory
,
1557 IClassFactory_Release(pcf
);
1562 static DWORD CALLBACK
get_class_object_thread(LPVOID pv
)
1564 CLSCTX clsctx
= (CLSCTX
)(DWORD_PTR
)pv
;
1567 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1569 hr
= get_class_object(clsctx
);
1576 static DWORD CALLBACK
get_class_object_proxy_thread(LPVOID pv
)
1578 CLSCTX clsctx
= (CLSCTX
)(DWORD_PTR
)pv
;
1583 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1585 hr
= CoGetClassObject(&CLSID_WineOOPTest
, clsctx
, NULL
, &IID_IClassFactory
,
1590 hr
= IClassFactory_QueryInterface(pcf
, &IID_IMultiQI
, (void **)&pMQI
);
1592 IMultiQI_Release(pMQI
);
1593 IClassFactory_Release(pcf
);
1601 static DWORD CALLBACK
register_class_object_thread(LPVOID pv
)
1606 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1608 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1609 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1616 static DWORD CALLBACK
revoke_class_object_thread(LPVOID pv
)
1618 DWORD cookie
= (DWORD_PTR
)pv
;
1621 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1623 hr
= CoRevokeClassObject(cookie
);
1630 static void test_registered_object_thread_affinity(void)
1638 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1640 /* CLSCTX_INPROC_SERVER */
1642 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1643 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1644 ok_ole_success(hr
, "CoRegisterClassObject");
1646 thread
= CreateThread(NULL
, 0, get_class_object_thread
, (LPVOID
)CLSCTX_INPROC_SERVER
, 0, &tid
);
1647 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1648 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1649 GetExitCodeThread(thread
, &exitcode
);
1651 ok(hr
== REGDB_E_CLASSNOTREG
, "CoGetClassObject on inproc object "
1652 "registered in different thread should return REGDB_E_CLASSNOTREG "
1653 "instead of 0x%08x\n", hr
);
1655 hr
= get_class_object(CLSCTX_INPROC_SERVER
);
1656 ok(hr
== S_OK
, "CoGetClassObject on inproc object registered in same "
1657 "thread should return S_OK instead of 0x%08x\n", hr
);
1659 thread
= CreateThread(NULL
, 0, register_class_object_thread
, NULL
, 0, &tid
);
1660 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1661 ok ( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1662 GetExitCodeThread(thread
, &exitcode
);
1664 ok(hr
== S_OK
, "CoRegisterClassObject with same CLSID but in different thread should return S_OK instead of 0x%08x\n", hr
);
1666 hr
= CoRevokeClassObject(cookie
);
1667 ok_ole_success(hr
, "CoRevokeClassObject");
1669 /* CLSCTX_LOCAL_SERVER */
1671 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1672 CLSCTX_LOCAL_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
1673 ok_ole_success(hr
, "CoRegisterClassObject");
1675 thread
= CreateThread(NULL
, 0, get_class_object_proxy_thread
, (LPVOID
)CLSCTX_LOCAL_SERVER
, 0, &tid
);
1676 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1677 while (MsgWaitForMultipleObjects(1, &thread
, FALSE
, 10000, QS_ALLINPUT
) == WAIT_OBJECT_0
+ 1)
1680 while (PeekMessageA(&msg
, NULL
, 0, 0, PM_REMOVE
))
1682 TranslateMessage(&msg
);
1683 DispatchMessageA(&msg
);
1686 GetExitCodeThread(thread
, &exitcode
);
1688 ok(hr
== S_OK
, "CoGetClassObject on local server object "
1689 "registered in different thread should return S_OK "
1690 "instead of 0x%08x\n", hr
);
1692 hr
= get_class_object(CLSCTX_LOCAL_SERVER
);
1693 ok(hr
== S_OK
, "CoGetClassObject on local server object registered in same "
1694 "thread should return S_OK instead of 0x%08x\n", hr
);
1696 thread
= CreateThread(NULL
, 0, revoke_class_object_thread
, (LPVOID
)(DWORD_PTR
)cookie
, 0, &tid
);
1697 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1698 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1699 GetExitCodeThread(thread
, &exitcode
);
1701 ok(hr
== RPC_E_WRONG_THREAD
|| broken(hr
== S_OK
) /* win8 */, "CoRevokeClassObject called from different "
1702 "thread to where registered should return RPC_E_WRONG_THREAD instead of 0x%08x\n", hr
);
1704 thread
= CreateThread(NULL
, 0, register_class_object_thread
, NULL
, 0, &tid
);
1705 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1706 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1707 GetExitCodeThread(thread
, &exitcode
);
1709 ok(hr
== S_OK
, "CoRegisterClassObject with same CLSID but in different "
1710 "thread should return S_OK instead of 0x%08x\n", hr
);
1712 hr
= CoRevokeClassObject(cookie
);
1713 ok_ole_success(hr
, "CoRevokeClassObject");
1718 static DWORD CALLBACK
free_libraries_thread(LPVOID p
)
1720 CoFreeUnusedLibraries();
1724 static inline BOOL
is_module_loaded(const char *module
)
1726 return GetModuleHandleA(module
) != 0;
1729 static void test_CoFreeUnusedLibraries(void)
1736 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1738 ok(!is_module_loaded("urlmon.dll"), "urlmon.dll shouldn't be loaded\n");
1740 hr
= CoCreateInstance(&CLSID_FileProtocol
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IInternetProtocol
, (void **)&pUnk
);
1741 if (hr
== REGDB_E_CLASSNOTREG
)
1743 skip("IE not installed so can't run CoFreeUnusedLibraries test\n");
1747 ok_ole_success(hr
, "CoCreateInstance");
1749 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1752 broken(pUnk
== NULL
), /* win9x */
1753 "Expected a valid pointer\n");
1755 IUnknown_Release(pUnk
);
1757 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1759 thread
= CreateThread(NULL
, 0, free_libraries_thread
, NULL
, 0, &tid
);
1760 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1761 CloseHandle(thread
);
1763 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1765 CoFreeUnusedLibraries();
1767 ok(!is_module_loaded("urlmon.dll"), "urlmon.dll shouldn't be loaded\n");
1772 static void test_CoGetObjectContext(void)
1776 IComThreadingInfo
*pComThreadingInfo
, *threadinginfo2
;
1777 IContextCallback
*pContextCallback
;
1778 IObjContext
*pObjContext
;
1783 if (!pCoGetObjectContext
)
1785 win_skip("CoGetObjectContext not present\n");
1789 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1790 ok(hr
== CO_E_NOTINITIALIZED
, "CoGetObjectContext should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
1791 ok(pComThreadingInfo
== NULL
, "pComThreadingInfo should have been set to NULL\n");
1793 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1795 test_apt_type(APTTYPE_MAINSTA
, APTTYPEQUALIFIER_NONE
);
1797 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1798 ok_ole_success(hr
, "CoGetObjectContext");
1800 threadinginfo2
= NULL
;
1801 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&threadinginfo2
);
1802 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
1803 ok(pComThreadingInfo
== threadinginfo2
, "got different instance\n");
1804 IComThreadingInfo_Release(threadinginfo2
);
1806 hr
= IComThreadingInfo_GetCurrentLogicalThreadId(pComThreadingInfo
, NULL
);
1807 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1809 id
= id2
= GUID_NULL
;
1810 hr
= IComThreadingInfo_GetCurrentLogicalThreadId(pComThreadingInfo
, &id
);
1811 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1813 hr
= CoGetCurrentLogicalThreadId(&id2
);
1814 ok(IsEqualGUID(&id
, &id2
), "got %s, expected %s\n", wine_dbgstr_guid(&id
), wine_dbgstr_guid(&id2
));
1816 hr
= IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo
, &apttype
);
1817 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentApartmentType");
1818 ok(apttype
== APTTYPE_MAINSTA
, "apartment type should be APTTYPE_MAINSTA instead of %d\n", apttype
);
1820 hr
= IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo
, &thdtype
);
1821 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentThreadType");
1822 ok(thdtype
== THDTYPE_PROCESSMESSAGES
, "thread type should be THDTYPE_PROCESSMESSAGES instead of %d\n", thdtype
);
1824 refs
= IComThreadingInfo_Release(pComThreadingInfo
);
1825 ok(refs
== 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs
);
1827 hr
= pCoGetObjectContext(&IID_IContextCallback
, (void **)&pContextCallback
);
1828 ok_ole_success(hr
, "CoGetObjectContext(ContextCallback)");
1830 refs
= IContextCallback_Release(pContextCallback
);
1831 ok(refs
== 0, "pContextCallback should have 0 refs instead of %d refs\n", refs
);
1835 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
1837 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1838 ok_ole_success(hr
, "CoGetObjectContext");
1840 hr
= IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo
, &apttype
);
1841 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentApartmentType");
1842 ok(apttype
== APTTYPE_MTA
, "apartment type should be APTTYPE_MTA instead of %d\n", apttype
);
1844 hr
= IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo
, &thdtype
);
1845 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentThreadType");
1846 ok(thdtype
== THDTYPE_BLOCKMESSAGES
, "thread type should be THDTYPE_BLOCKMESSAGES instead of %d\n", thdtype
);
1848 refs
= IComThreadingInfo_Release(pComThreadingInfo
);
1849 ok(refs
== 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs
);
1851 hr
= pCoGetObjectContext(&IID_IContextCallback
, (void **)&pContextCallback
);
1852 ok_ole_success(hr
, "CoGetObjectContext(ContextCallback)");
1854 refs
= IContextCallback_Release(pContextCallback
);
1855 ok(refs
== 0, "pContextCallback should have 0 refs instead of %d refs\n", refs
);
1857 hr
= pCoGetObjectContext(&IID_IObjContext
, (void **)&pObjContext
);
1858 ok_ole_success(hr
, "CoGetObjectContext");
1860 refs
= IObjContext_Release(pObjContext
);
1861 ok(refs
== 0, "pObjContext should have 0 refs instead of %d refs\n", refs
);
1867 IUnknown IUnknown_iface
;
1871 static inline Test_CallContext
*impl_from_IUnknown(IUnknown
*iface
)
1873 return CONTAINING_RECORD(iface
, Test_CallContext
, IUnknown_iface
);
1876 static HRESULT WINAPI
Test_CallContext_QueryInterface(
1881 if (ppvObj
== NULL
) return E_POINTER
;
1883 if (IsEqualGUID(riid
, &IID_IUnknown
))
1886 IUnknown_AddRef(iface
);
1891 return E_NOINTERFACE
;
1894 static ULONG WINAPI
Test_CallContext_AddRef(IUnknown
*iface
)
1896 Test_CallContext
*This
= impl_from_IUnknown(iface
);
1897 return InterlockedIncrement(&This
->refs
);
1900 static ULONG WINAPI
Test_CallContext_Release(IUnknown
*iface
)
1902 Test_CallContext
*This
= impl_from_IUnknown(iface
);
1903 ULONG refs
= InterlockedDecrement(&This
->refs
);
1905 HeapFree(GetProcessHeap(), 0, This
);
1909 static const IUnknownVtbl TestCallContext_Vtbl
=
1911 Test_CallContext_QueryInterface
,
1912 Test_CallContext_AddRef
,
1913 Test_CallContext_Release
1916 static void test_CoGetCallContext(void)
1921 Test_CallContext
*test_object
;
1923 if (!pCoSwitchCallContext
)
1925 skip("CoSwitchCallContext not present\n");
1931 test_object
= HeapAlloc(GetProcessHeap(), 0, sizeof(Test_CallContext
));
1932 test_object
->IUnknown_iface
.lpVtbl
= &TestCallContext_Vtbl
;
1933 test_object
->refs
= 1;
1935 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
1936 ok(hr
== RPC_E_CALL_COMPLETE
, "Expected RPC_E_CALL_COMPLETE, got 0x%08x\n", hr
);
1938 pUnk
= (IUnknown
*)0xdeadbeef;
1939 hr
= pCoSwitchCallContext(&test_object
->IUnknown_iface
, &pUnk
);
1940 ok_ole_success(hr
, "CoSwitchCallContext");
1941 ok(pUnk
== NULL
, "expected NULL, got %p\n", pUnk
);
1942 refs
= IUnknown_AddRef(&test_object
->IUnknown_iface
);
1943 ok(refs
== 2, "Expected refcount 2, got %d\n", refs
);
1944 IUnknown_Release(&test_object
->IUnknown_iface
);
1946 pUnk
= (IUnknown
*)0xdeadbeef;
1947 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
1948 ok_ole_success(hr
, "CoGetCallContext");
1949 ok(pUnk
== &test_object
->IUnknown_iface
, "expected %p, got %p\n",
1950 &test_object
->IUnknown_iface
, pUnk
);
1951 refs
= IUnknown_AddRef(&test_object
->IUnknown_iface
);
1952 ok(refs
== 3, "Expected refcount 3, got %d\n", refs
);
1953 IUnknown_Release(&test_object
->IUnknown_iface
);
1954 IUnknown_Release(pUnk
);
1956 pUnk
= (IUnknown
*)0xdeadbeef;
1957 hr
= pCoSwitchCallContext(NULL
, &pUnk
);
1958 ok_ole_success(hr
, "CoSwitchCallContext");
1959 ok(pUnk
== &test_object
->IUnknown_iface
, "expected %p, got %p\n",
1960 &test_object
->IUnknown_iface
, pUnk
);
1961 refs
= IUnknown_AddRef(&test_object
->IUnknown_iface
);
1962 ok(refs
== 2, "Expected refcount 2, got %d\n", refs
);
1963 IUnknown_Release(&test_object
->IUnknown_iface
);
1965 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
1966 ok(hr
== RPC_E_CALL_COMPLETE
, "Expected RPC_E_CALL_COMPLETE, got 0x%08x\n", hr
);
1968 IUnknown_Release(&test_object
->IUnknown_iface
);
1973 static void test_CoGetContextToken(void)
1977 ULONG_PTR token
, token2
;
1980 if (!pCoGetContextToken
)
1982 win_skip("CoGetContextToken not present\n");
1987 hr
= pCoGetContextToken(&token
);
1988 ok(hr
== CO_E_NOTINITIALIZED
, "Expected CO_E_NOTINITIALIZED, got 0x%08x\n", hr
);
1989 ok(token
== 0xdeadbeef, "Expected 0, got 0x%lx\n", token
);
1991 test_apt_type(APTTYPE_CURRENT
, APTTYPEQUALIFIER_NONE
);
1995 test_apt_type(APTTYPE_MAINSTA
, APTTYPEQUALIFIER_NONE
);
1997 hr
= pCoGetContextToken(NULL
);
1998 ok(hr
== E_POINTER
, "Expected E_POINTER, got 0x%08x\n", hr
);
2001 hr
= pCoGetContextToken(&token
);
2002 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2003 ok(token
, "Expected token != 0\n");
2006 hr
= pCoGetContextToken(&token2
);
2007 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2008 ok(token2
== token
, "got different token\n");
2010 refs
= IUnknown_AddRef((IUnknown
*)token
);
2011 ok(refs
== 1, "Expected 1, got %u\n", refs
);
2013 hr
= pCoGetObjectContext(&IID_IObjContext
, (void **)&ctx
);
2014 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2015 ok(ctx
== (IObjContext
*)token
, "Expected interface pointers to be the same\n");
2017 refs
= IObjContext_AddRef(ctx
);
2018 ok(refs
== 3, "Expected 3, got %u\n", refs
);
2020 refs
= IObjContext_Release(ctx
);
2021 ok(refs
== 2, "Expected 2, got %u\n", refs
);
2023 refs
= IUnknown_Release((IUnknown
*)token
);
2024 ok(refs
== 1, "Expected 1, got %u\n", refs
);
2026 /* CoGetContextToken does not add a reference */
2028 hr
= pCoGetContextToken(&token
);
2029 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2030 ok(token
, "Expected token != 0\n");
2031 ok(ctx
== (IObjContext
*)token
, "Expected interface pointers to be the same\n");
2033 refs
= IObjContext_AddRef(ctx
);
2034 ok(refs
== 2, "Expected 1, got %u\n", refs
);
2036 refs
= IObjContext_Release(ctx
);
2037 ok(refs
== 1, "Expected 0, got %u\n", refs
);
2039 refs
= IObjContext_Release(ctx
);
2040 ok(refs
== 0, "Expected 0, got %u\n", refs
);
2045 static void test_TreatAsClass(void)
2049 static GUID deadbeef
= {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
2050 static const char deadbeefA
[] = "{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}";
2051 IInternetProtocol
*pIP
= NULL
;
2052 HKEY clsidkey
, deadbeefkey
;
2055 if (!pCoGetTreatAsClass
)
2057 win_skip("CoGetTreatAsClass not present\n");
2061 hr
= pCoGetTreatAsClass(&deadbeef
,&out
);
2062 ok (hr
== S_FALSE
, "expected S_FALSE got %x\n",hr
);
2063 ok (IsEqualGUID(&out
,&deadbeef
), "expected to get same clsid back\n");
2065 hr
= pCoGetTreatAsClass(NULL
, &out
);
2066 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG got %08x\n", hr
);
2067 ok(IsEqualGUID(&out
, &deadbeef
), "expected no change to the clsid\n");
2069 hr
= pCoGetTreatAsClass(&deadbeef
, NULL
);
2070 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG got %08x\n", hr
);
2072 lr
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "CLSID", 0, KEY_READ
, &clsidkey
);
2073 ok(!lr
, "Couldn't open CLSID key, error %d\n", lr
);
2075 lr
= RegCreateKeyExA(clsidkey
, deadbeefA
, 0, NULL
, 0, KEY_WRITE
, NULL
, &deadbeefkey
, NULL
);
2077 win_skip("CoGetTreatAsClass() tests will be skipped (failed to create a test key, error %d)\n", lr
);
2078 RegCloseKey(clsidkey
);
2082 hr
= pCoTreatAsClass(&deadbeef
, &deadbeef
);
2083 ok(hr
== REGDB_E_WRITEREGDB
, "CoTreatAsClass gave wrong error: %08x\n", hr
);
2085 hr
= pCoTreatAsClass(&deadbeef
, &CLSID_FileProtocol
);
2086 if(hr
== REGDB_E_WRITEREGDB
){
2087 win_skip("Insufficient privileges to use CoTreatAsClass\n");
2090 ok(hr
== S_OK
, "CoTreatAsClass failed: %08x\n", hr
);
2092 hr
= pCoGetTreatAsClass(&deadbeef
, &out
);
2093 ok(hr
== S_OK
, "CoGetTreatAsClass failed: %08x\n",hr
);
2094 ok(IsEqualGUID(&out
, &CLSID_FileProtocol
), "expected to get substituted clsid\n");
2096 OleInitialize(NULL
);
2098 hr
= CoCreateInstance(&deadbeef
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IInternetProtocol
, (void **)&pIP
);
2099 if(hr
== REGDB_E_CLASSNOTREG
)
2101 win_skip("IE not installed so can't test CoCreateInstance\n");
2105 ok(hr
== S_OK
, "CoCreateInstance failed: %08x\n", hr
);
2107 IInternetProtocol_Release(pIP
);
2111 hr
= pCoTreatAsClass(&deadbeef
, &CLSID_NULL
);
2112 ok(hr
== S_OK
, "CoTreatAsClass failed: %08x\n", hr
);
2114 hr
= pCoGetTreatAsClass(&deadbeef
, &out
);
2115 ok(hr
== S_FALSE
, "expected S_FALSE got %08x\n", hr
);
2116 ok(IsEqualGUID(&out
, &deadbeef
), "expected to get same clsid back\n");
2118 /* bizarrely, native's CoTreatAsClass takes some time to take effect in CoCreateInstance */
2121 hr
= CoCreateInstance(&deadbeef
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IInternetProtocol
, (void **)&pIP
);
2122 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance gave wrong error: %08x\n", hr
);
2125 IInternetProtocol_Release(pIP
);
2129 RegCloseKey(deadbeefkey
);
2130 RegDeleteKeyA(clsidkey
, deadbeefA
);
2131 RegCloseKey(clsidkey
);
2134 static void test_CoInitializeEx(void)
2138 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2139 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2141 /* Calling OleInitialize for the first time should yield S_OK even with
2142 * apartment already initialized by previous CoInitialize(Ex) calls. */
2143 hr
= OleInitialize(NULL
);
2144 ok(hr
== S_OK
, "OleInitialize failed with error 0x%08x\n", hr
);
2146 /* Subsequent calls to OleInitialize should return S_FALSE */
2147 hr
= OleInitialize(NULL
);
2148 ok(hr
== S_FALSE
, "Expected S_FALSE, hr = 0x%08x\n", hr
);
2156 static void test_OleInitialize_InitCounting(void)
2160 REFCLSID rclsid
= &CLSID_InternetZoneManager
;
2162 /* 1. OleInitialize fails but OleUninitialize is still called: apartment stays initialized */
2163 hr
= pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
2164 ok(hr
== S_OK
, "CoInitializeEx(COINIT_MULTITHREADED) failed with error 0x%08x\n", hr
);
2166 hr
= OleInitialize(NULL
);
2167 ok(hr
== RPC_E_CHANGED_MODE
, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", RPC_E_CHANGED_MODE
, hr
);
2170 pUnk
= (IUnknown
*)0xdeadbeef;
2171 hr
= CoCreateInstance(rclsid
, NULL
, 0x17, &IID_IUnknown
, (void **)&pUnk
);
2172 ok(hr
== S_OK
, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", S_OK
, hr
);
2173 if (pUnk
) IUnknown_Release(pUnk
);
2177 /* 2. Extra multiple OleUninitialize: apartment stays initialized until CoUninitialize */
2178 hr
= CoInitialize(NULL
);
2179 ok(hr
== S_OK
, "CoInitialize() failed with error 0x%08x\n", hr
);
2181 hr
= OleInitialize(NULL
);
2182 ok(hr
== S_OK
, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", S_OK
, hr
);
2187 pUnk
= (IUnknown
*)0xdeadbeef;
2188 hr
= CoCreateInstance(rclsid
, NULL
, 0x17, &IID_IUnknown
, (void **)&pUnk
);
2189 ok(hr
== S_OK
, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", S_OK
, hr
);
2190 if (pUnk
) IUnknown_Release(pUnk
);
2194 pUnk
= (IUnknown
*)0xdeadbeef;
2195 hr
= CoCreateInstance(rclsid
, NULL
, 0x17, &IID_IUnknown
, (void **)&pUnk
);
2196 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", CO_E_NOTINITIALIZED
, hr
);
2197 if (pUnk
) IUnknown_Release(pUnk
);
2199 /* 3. CoUninitialize does not formally deinit Ole */
2200 hr
= CoInitialize(NULL
);
2201 ok(hr
== S_OK
, "CoInitialize() failed with error 0x%08x\n", hr
);
2203 hr
= OleInitialize(NULL
);
2204 ok(hr
== S_OK
, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", S_OK
, hr
);
2209 pUnk
= (IUnknown
*)0xdeadbeef;
2210 hr
= CoCreateInstance(rclsid
, NULL
, 0x17, &IID_IUnknown
, (void **)&pUnk
);
2211 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", CO_E_NOTINITIALIZED
, hr
);
2212 /* COM is not initialized anymore */
2213 if (pUnk
) IUnknown_Release(pUnk
);
2215 hr
= OleInitialize(NULL
);
2216 ok(hr
== S_FALSE
, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", S_FALSE
, hr
);
2217 /* ... but native OleInit returns S_FALSE as if Ole is considered initialized */
2223 static void test_OleRegGetMiscStatus(void)
2230 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_ICON
, NULL
);
2231 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2233 status
= 0xdeadbeef;
2234 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_ICON
, &status
);
2235 ok(hr
== REGDB_E_CLASSNOTREG
, "got 0x%08x\n", hr
);
2236 ok(status
== 0, "got 0x%08x\n", status
);
2239 hr
= OleRegGetMiscStatus(&CLSID_StdFont
, DVASPECT_ICON
, &status
);
2240 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2241 ok(status
== 0, "got 0x%08x\n", status
);
2243 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
2246 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_ICON
, &status
);
2247 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2248 ok(status
== OLEMISC_RECOMPOSEONRESIZE
, "got 0x%08x\n", status
);
2250 /* context data takes precedence over registration info */
2252 hr
= OleRegGetMiscStatus(&CLSID_StdFont
, DVASPECT_ICON
, &status
);
2253 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2254 ok(status
== OLEMISC_RECOMPOSEONRESIZE
, "got 0x%08x\n", status
);
2256 /* there's no such attribute in context */
2258 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_DOCPRINT
, &status
);
2259 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2260 ok(status
== 0, "got 0x%08x\n", status
);
2262 pDeactivateActCtx(0, cookie
);
2263 pReleaseActCtx(handle
);
2267 static void test_OleRegGetUserType(void)
2269 static const WCHAR stdfont_usertypeW
[] = {'S','t','a','n','d','a','r','d',' ','F','o','n','t',0};
2270 static const WCHAR stdfont2_usertypeW
[] = {'C','L','S','I','D','_','S','t','d','F','o','n','t',0};
2271 static const WCHAR clsidkeyW
[] = {'C','L','S','I','D',0};
2272 static const WCHAR defvalueW
[] = {'D','e','f','a','u','l','t',' ','N','a','m','e',0};
2273 static const WCHAR auxvalue0W
[] = {'A','u','x',' ','N','a','m','e',' ','0',0};
2274 static const WCHAR auxvalue2W
[] = {'A','u','x',' ','N','a','m','e',' ','2',0};
2275 static const WCHAR auxvalue3W
[] = {'A','u','x',' ','N','a','m','e',' ','3',0};
2276 static const WCHAR auxvalue4W
[] = {'A','u','x',' ','N','a','m','e',' ','4',0};
2278 static const char auxvalues
[][16] = {
2286 HKEY clsidhkey
, hkey
, auxhkey
, classkey
;
2287 DWORD form
, ret
, disposition
;
2295 for (form
= 0; form
<= USERCLASSTYPE_APPNAME
+1; form
++) {
2296 hr
= OleRegGetUserType(&CLSID_Testclass
, form
, NULL
);
2297 ok(hr
== E_INVALIDARG
, "form %u: got 0x%08x\n", form
, hr
);
2299 str
= (void*)0xdeadbeef;
2300 hr
= OleRegGetUserType(&CLSID_Testclass
, form
, &str
);
2301 ok(hr
== REGDB_E_CLASSNOTREG
, "form %u: got 0x%08x\n", form
, hr
);
2302 ok(str
== NULL
, "form %u: got %p\n", form
, str
);
2304 /* same string returned for StdFont for all form types */
2306 hr
= OleRegGetUserType(&CLSID_StdFont
, form
, &str
);
2307 ok(hr
== S_OK
, "form %u: got 0x%08x\n", form
, hr
);
2308 ok(!lstrcmpW(str
, stdfont_usertypeW
) || !lstrcmpW(str
, stdfont2_usertypeW
) /* winxp */,
2309 "form %u, got %s\n", form
, wine_dbgstr_w(str
));
2313 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
2315 for (form
= 0; form
<= USERCLASSTYPE_APPNAME
+1; form
++) {
2316 str
= (void*)0xdeadbeef;
2317 hr
= OleRegGetUserType(&CLSID_Testclass
, form
, &str
);
2318 ok(hr
== REGDB_E_CLASSNOTREG
, "form %u: got 0x%08x\n", form
, hr
);
2319 ok(str
== NULL
, "form %u: got %s\n", form
, wine_dbgstr_w(str
));
2321 /* same string returned for StdFont for all form types */
2323 hr
= OleRegGetUserType(&CLSID_StdFont
, form
, &str
);
2324 ok(hr
== S_OK
, "form %u: got 0x%08x\n", form
, hr
);
2325 ok(!lstrcmpW(str
, stdfont_usertypeW
) || !lstrcmpW(str
, stdfont2_usertypeW
) /* winxp */,
2326 "form %u, got %s\n", form
, wine_dbgstr_w(str
));
2330 pDeactivateActCtx(0, cookie
);
2331 pReleaseActCtx(handle
);
2334 /* test using registered CLSID */
2335 StringFromGUID2(&CLSID_non_existent
, clsidW
, ARRAY_SIZE(clsidW
));
2337 ret
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, clsidkeyW
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &clsidhkey
, &disposition
);
2340 ret
= RegCreateKeyExW(clsidhkey
, clsidW
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &classkey
, NULL
);
2342 RegCloseKey(clsidhkey
);
2345 if (ret
== ERROR_ACCESS_DENIED
)
2347 win_skip("Failed to create test key, skipping some of OleRegGetUserType() tests.\n");
2351 ok(!ret
, "failed to create a key, error %d\n", ret
);
2353 ret
= RegSetValueExW(classkey
, NULL
, 0, REG_SZ
, (const BYTE
*)defvalueW
, sizeof(defvalueW
));
2354 ok(!ret
, "got error %d\n", ret
);
2356 ret
= RegCreateKeyExA(classkey
, "AuxUserType", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &auxhkey
, NULL
);
2357 ok(!ret
, "got error %d\n", ret
);
2359 /* populate AuxUserType */
2360 for (i
= 0; i
<= 4; i
++) {
2363 sprintf(name
, "AuxUserType\\%d", i
);
2364 ret
= RegCreateKeyExA(classkey
, name
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
);
2365 ok(!ret
, "got error %d\n", ret
);
2367 ret
= RegSetValueExA(hkey
, NULL
, 0, REG_SZ
, (const BYTE
*)auxvalues
[i
], strlen(auxvalues
[i
]));
2368 ok(!ret
, "got error %d\n", ret
);
2373 hr
= OleRegGetUserType(&CLSID_non_existent
, 0, &str
);
2374 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2375 ok(!lstrcmpW(str
, auxvalue0W
), "got %s\n", wine_dbgstr_w(str
));
2379 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_FULL
, &str
);
2380 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2381 ok(!lstrcmpW(str
, defvalueW
), "got %s\n", wine_dbgstr_w(str
));
2385 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_SHORT
, &str
);
2386 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2387 ok(!lstrcmpW(str
, auxvalue2W
), "got %s\n", wine_dbgstr_w(str
));
2391 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_APPNAME
, &str
);
2392 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2393 ok(!lstrcmpW(str
, auxvalue3W
), "got %s\n", wine_dbgstr_w(str
));
2397 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_APPNAME
+1, &str
);
2398 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2399 ok(!lstrcmpW(str
, auxvalue4W
), "got %s\n", wine_dbgstr_w(str
));
2403 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_APPNAME
+2, &str
);
2404 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2405 ok(!lstrcmpW(str
, defvalueW
), "got %s\n", wine_dbgstr_w(str
));
2408 /* registry cleanup */
2409 for (i
= 0; i
<= 4; i
++)
2412 sprintf(name
, "%d", i
);
2413 RegDeleteKeyA(auxhkey
, name
);
2415 RegCloseKey(auxhkey
);
2416 RegDeleteKeyA(classkey
, "AuxUserType");
2417 RegCloseKey(classkey
);
2418 RegDeleteKeyW(clsidhkey
, clsidW
);
2419 RegCloseKey(clsidhkey
);
2420 if (disposition
== REG_CREATED_NEW_KEY
)
2421 RegDeleteKeyA(HKEY_CLASSES_ROOT
, "CLSID");
2424 static void test_CoCreateGuid(void)
2428 hr
= CoCreateGuid(NULL
);
2429 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2432 static void CALLBACK
apc_test_proc(ULONG_PTR param
)
2437 static DWORD CALLBACK
release_semaphore_thread( LPVOID arg
)
2439 HANDLE handle
= arg
;
2440 if (WaitForSingleObject(handle
, 200) == WAIT_TIMEOUT
)
2441 ReleaseSemaphore(handle
, 1, NULL
);
2445 static DWORD CALLBACK
send_message_thread(LPVOID arg
)
2449 SendMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2453 static DWORD CALLBACK
send_and_post_user_message_thread(void *arg
)
2457 SendMessageA(hwnd
, WM_USER
, 0, 0);
2458 PostMessageA(hwnd
, WM_USER
, 0, 0);
2462 static DWORD CALLBACK
post_message_thread(LPVOID arg
)
2466 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2470 static const char cls_name
[] = "cowait_test_class";
2472 static UINT cowait_msgs
[100], cowait_msgs_first
, cowait_msgs_last
;
2474 static void cowait_msgs_reset(void)
2476 cowait_msgs_first
= cowait_msgs_last
= 0;
2479 #define cowait_msgs_expect_empty() _cowait_msgs_expect_empty(__LINE__)
2480 static void _cowait_msgs_expect_empty(unsigned line
)
2482 while(cowait_msgs_first
< cowait_msgs_last
) {
2483 ok_(__FILE__
,line
)(0, "unexpected message %u\n", cowait_msgs
[cowait_msgs_first
]);
2484 cowait_msgs_first
++;
2486 cowait_msgs_reset();
2489 #define cowait_msgs_expect_notified(a) _cowait_msgs_expect_notified(__LINE__,a)
2490 static void _cowait_msgs_expect_notified(unsigned line
, UINT expected_msg
)
2492 if(cowait_msgs_first
== cowait_msgs_last
) {
2493 ok_(__FILE__
,line
)(0, "expected message %u, received none\n", expected_msg
);
2495 ok_(__FILE__
,line
)(cowait_msgs
[cowait_msgs_first
] == expected_msg
,
2496 "expected message %u, received %u \n",
2497 expected_msg
, cowait_msgs
[cowait_msgs_first
]);
2498 cowait_msgs_first
++;
2502 #define cowait_msgs_expect_queued(a,b) _cowait_msgs_expect_queued(__LINE__,a,b)
2503 static void _cowait_msgs_expect_queued(unsigned line
, HWND hwnd
, UINT expected_msg
)
2508 success
= PeekMessageA(&msg
, hwnd
, expected_msg
, expected_msg
, PM_REMOVE
);
2509 ok_(__FILE__
,line
)(success
, "PeekMessageA failed: %u\n", GetLastError());
2511 ok_(__FILE__
,line
)(msg
.message
== expected_msg
, "unexpected message %u, expected %u\n",
2512 msg
.message
, expected_msg
);
2515 static void flush_messages(void)
2518 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
));
2521 static LRESULT CALLBACK
cowait_window_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2523 if(cowait_msgs_last
< ARRAY_SIZE(cowait_msgs
))
2524 cowait_msgs
[cowait_msgs_last
++] = msg
;
2525 if(msg
== WM_DDE_FIRST
)
2527 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
2530 static DWORD CALLBACK
cowait_unmarshal_thread(void *arg
)
2532 IStream
*stream
= arg
;
2533 IEnumOLEVERB
*enum_verb
;
2541 hr
= IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
2542 ok(hr
== S_OK
, "Seek failed: %08x\n", hr
);
2544 hr
= CoUnmarshalInterface(stream
, &IID_IUnknown
, (void**)&unk
);
2545 ok(hr
== S_OK
, "CoUnmarshalInterface failed: %08x\n", hr
);
2547 hr
= IUnknown_QueryInterface(unk
, &IID_IEnumOLEVERB
, (void**)&enum_verb
);
2548 ok(hr
== S_OK
, "QueryInterface failed: %08x\n", hr
);
2550 IEnumOLEVERB_Release(enum_verb
);
2551 IUnknown_Release(unk
);
2557 static DWORD CALLBACK
test_CoWaitForMultipleHandles_thread(LPVOID arg
)
2559 HANDLE
*handles
= arg
, event
, thread
;
2569 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2570 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2572 hWnd
= CreateWindowExA(0, cls_name
, "Test (thread)", WS_TILEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
2573 ok(hWnd
!= 0, "CreateWindowExA failed %u\n", GetLastError());
2576 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2577 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2578 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2579 ok(index
==0 || index
==0xdeadbeef/* Win 8 */, "expected index 0, got %u\n", index
);
2580 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2581 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2584 PostMessageA(hWnd
, WM_USER
, 0, 0);
2585 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2586 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2587 ok(index
==0 || index
==0xdeadbeef/* Win 8 */, "expected index 0, got %u\n", index
);
2588 success
= PeekMessageA(&msg
, hWnd
, WM_USER
, WM_USER
, PM_REMOVE
);
2589 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2591 /* Even if CoWaitForMultipleHandles does not pump a message it peeks
2594 PostMessageA(NULL
, uMSG
, 0, 0);
2596 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 2, handles
, &index
);
2597 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2598 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2600 /* Make sure message was peeked at */
2601 ret
= MsgWaitForMultipleObjectsEx(0, NULL
, 2, QS_ALLPOSTMESSAGE
, MWMO_ALERTABLE
);
2602 ok(ret
== WAIT_TIMEOUT
, "MsgWaitForMultipleObjects returned %x\n", ret
);
2604 /* But not pumped */
2605 success
= PeekMessageA(&msg
, NULL
, uMSG
, uMSG
, PM_REMOVE
);
2606 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2608 DestroyWindow(hWnd
);
2611 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2612 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2614 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
2615 ok(hr
== S_OK
, "CreateStreamOnHGlobal failed: %08x\n", hr
);
2617 hr
= CoMarshalInterface(stream
, &IID_IUnknown
, &Test_Unknown
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
2618 ok(hr
== S_OK
, "CoMarshalInterface should have returned S_OK instead of 0x%08x\n", hr
);
2620 event
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
2622 PostQuitMessage(66);
2623 PostThreadMessageW(GetCurrentThreadId(), WM_QUIT
, 0, 0);
2625 hr
= CoRegisterMessageFilter(&MessageFilter
, NULL
);
2626 ok(hr
== S_OK
, "CoRegisterMessageFilter failed: %08x\n", hr
);
2628 thread
= CreateThread(NULL
, 0, cowait_unmarshal_thread
, stream
, 0, &tid
);
2629 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2630 hr
= CoWaitForMultipleHandles(0, 50, 1, &event
, &index
);
2631 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2632 index
= WaitForSingleObject(thread
, 200);
2633 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2634 CloseHandle(thread
);
2636 hr
= CoRegisterMessageFilter(NULL
, NULL
);
2637 ok(hr
== S_OK
, "CoRegisterMessageFilter failed: %08x\n", hr
);
2639 IStream_Release(stream
);
2646 static void test_CoWaitForMultipleHandles(void)
2648 HANDLE handles
[2], thread
;
2656 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2657 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2659 memset(&wc
, 0, sizeof(wc
));
2660 wc
.cbSize
= sizeof(wc
);
2661 wc
.style
= CS_VREDRAW
| CS_HREDRAW
;
2662 wc
.hInstance
= GetModuleHandleA(0);
2663 wc
.hCursor
= LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
);
2664 wc
.hbrBackground
= NULL
;
2665 wc
.lpszClassName
= cls_name
;
2666 wc
.lpfnWndProc
= cowait_window_proc
;
2667 success
= RegisterClassExA(&wc
) != 0;
2668 ok(success
, "RegisterClassExA failed %u\n", GetLastError());
2670 hWnd
= CreateWindowExA(0, cls_name
, "Test", WS_TILEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
2671 ok(hWnd
!= 0, "CreateWindowExA failed %u\n", GetLastError());
2672 handles
[0] = CreateSemaphoreA(NULL
, 1, 1, NULL
);
2673 ok(handles
[0] != 0, "CreateSemaphoreA failed %u\n", GetLastError());
2674 handles
[1] = CreateSemaphoreA(NULL
, 1, 1, NULL
);
2675 ok(handles
[1] != 0, "CreateSemaphoreA failed %u\n", GetLastError());
2677 /* test without flags */
2679 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2680 hr
= CoWaitForMultipleHandles(0, 50, 0, handles
, NULL
);
2681 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
2682 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2683 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2686 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2687 hr
= CoWaitForMultipleHandles(0, 50, 0, NULL
, &index
);
2688 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
2689 ok(index
== 0, "expected index 0, got %u\n", index
);
2690 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2691 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2694 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2695 hr
= CoWaitForMultipleHandles(0, 50, 0, handles
, &index
);
2696 ok(hr
== RPC_E_NO_SYNC
, "expected RPC_E_NO_SYNC, got 0x%08x\n", hr
);
2697 ok(index
== 0, "expected index 0, got %u\n", index
);
2698 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2699 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2702 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2703 hr
= CoWaitForMultipleHandles(0, 50, 1, handles
, &index
);
2704 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2705 ok(index
== 0, "expected index 0, got %u\n", index
);
2706 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2707 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2710 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2711 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2712 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2713 ok(index
== 1, "expected index 1, got %u\n", index
);
2714 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2715 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2718 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2719 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2720 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2721 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2722 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2723 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2725 /* test PostMessageA/SendMessageA from a different thread */
2728 thread
= CreateThread(NULL
, 0, post_message_thread
, hWnd
, 0, &tid
);
2729 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2730 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2731 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2732 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2733 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2734 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2735 index
= WaitForSingleObject(thread
, 200);
2736 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2737 CloseHandle(thread
);
2740 thread
= CreateThread(NULL
, 0, send_message_thread
, hWnd
, 0, &tid
);
2741 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2742 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2743 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2744 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2745 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2746 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2747 index
= WaitForSingleObject(thread
, 200);
2748 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2749 CloseHandle(thread
);
2751 ReleaseSemaphore(handles
[0], 1, NULL
);
2752 ReleaseSemaphore(handles
[1], 1, NULL
);
2754 /* test with COWAIT_WAITALL */
2757 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2758 hr
= CoWaitForMultipleHandles(COWAIT_WAITALL
, 50, 2, handles
, &index
);
2759 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2760 ok(index
== 0, "expected index 0, got %u\n", index
);
2761 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2762 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2765 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2766 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2767 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2768 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2769 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2770 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2772 ReleaseSemaphore(handles
[0], 1, NULL
);
2773 ReleaseSemaphore(handles
[1], 1, NULL
);
2775 /* test with COWAIT_ALERTABLE */
2778 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2779 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 1, handles
, &index
);
2780 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2781 ok(index
== 0, "expected index 0, got %u\n", index
);
2782 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2783 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2786 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2787 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 2, handles
, &index
);
2788 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2789 ok(index
== 1, "expected index 1, got %u\n", index
);
2790 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2791 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2794 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2795 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 2, handles
, &index
);
2796 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2797 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2798 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2799 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2802 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2803 success
= QueueUserAPC(apc_test_proc
, GetCurrentThread(), 0);
2804 ok(success
, "QueueUserAPC failed %u\n", GetLastError());
2805 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 2, handles
, &index
);
2806 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2807 ok(index
== WAIT_IO_COMPLETION
, "expected index WAIT_IO_COMPLETION, got %u\n", index
);
2808 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2809 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2811 /* test with COWAIT_INPUTAVAILABLE (semaphores are still locked) */
2814 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2815 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_NOREMOVE
);
2816 ok(success
, "PeekMessageA returned FALSE\n");
2817 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2818 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2819 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2820 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2821 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2824 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2825 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_NOREMOVE
);
2826 ok(success
, "PeekMessageA returned FALSE\n");
2827 thread
= CreateThread(NULL
, 0, release_semaphore_thread
, handles
[1], 0, &tid
);
2828 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2829 hr
= CoWaitForMultipleHandles(COWAIT_INPUTAVAILABLE
, 50, 2, handles
, &index
);
2830 ok(hr
== RPC_S_CALLPENDING
|| broken(hr
== E_INVALIDARG
) || broken(hr
== S_OK
) /* Win 8 */,
2831 "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2832 if (hr
!= S_OK
) ReleaseSemaphore(handles
[1], 1, NULL
);
2833 ok(index
== 0 || broken(index
== 1) /* Win 8 */, "expected index 0, got %u\n", index
);
2834 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2835 ok(!success
|| broken(success
&& hr
== E_INVALIDARG
),
2836 "CoWaitForMultipleHandles didn't pump any messages\n");
2837 index
= WaitForSingleObject(thread
, 200);
2838 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2839 CloseHandle(thread
);
2841 cowait_msgs_reset();
2842 PostMessageA(hWnd
, 0, 0, 0);
2843 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2844 PostMessageA(hWnd
, WM_USER
+1, 0, 0);
2845 PostMessageA(hWnd
, WM_DDE_FIRST
+1, 0, 0);
2846 thread
= CreateThread(NULL
, 0, send_and_post_user_message_thread
, hWnd
, 0, &tid
);
2847 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2849 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2850 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2852 cowait_msgs_expect_notified(WM_DDE_FIRST
);
2853 cowait_msgs_expect_notified(WM_DDE_FIRST
+1);
2854 cowait_msgs_expect_notified(WM_USER
);
2855 cowait_msgs_expect_empty();
2856 cowait_msgs_expect_queued(hWnd
, WM_USER
);
2857 cowait_msgs_expect_queued(hWnd
, WM_USER
+1);
2860 index
= WaitForSingleObject(thread
, 200);
2861 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2862 CloseHandle(thread
);
2864 /* test behaviour of WM_QUIT (semaphores are still locked) */
2866 PostMessageA(hWnd
, WM_QUIT
, 40, 0);
2867 memset(&msg
, 0, sizeof(msg
));
2868 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2869 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2870 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2871 ok(msg
.wParam
== 40, "expected msg.wParam = 40, got %lu\n", msg
.wParam
);
2872 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2873 ok(!success
, "PeekMessageA succeeded\n");
2875 cowait_msgs_reset();
2876 PostMessageA(hWnd
, WM_QUIT
, 40, 0);
2877 PostMessageA(hWnd
, 0, 0, 0);
2878 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2879 PostMessageA(hWnd
, WM_USER
+1, 0, 0);
2880 PostMessageA(hWnd
, WM_DDE_FIRST
+1, 0, 0);
2881 thread
= CreateThread(NULL
, 0, send_and_post_user_message_thread
, hWnd
, 0, &tid
);
2882 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2884 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2885 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2887 cowait_msgs_expect_notified(WM_DDE_FIRST
);
2888 cowait_msgs_expect_notified(WM_DDE_FIRST
+1);
2889 cowait_msgs_expect_notified(WM_USER
);
2890 cowait_msgs_expect_empty();
2891 cowait_msgs_expect_queued(hWnd
, WM_USER
);
2894 index
= WaitForSingleObject(thread
, 200);
2895 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2896 CloseHandle(thread
);
2899 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2900 PostMessageA(hWnd
, WM_QUIT
, 41, 0);
2901 thread
= CreateThread(NULL
, 0, post_message_thread
, hWnd
, 0, &tid
);
2902 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2903 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2904 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2905 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2906 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2908 ok(success
|| broken(!success
) /* Win 2000/XP/8 */, "PeekMessageA failed, error %u\n", GetLastError());
2909 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2910 ok(!success
, "PeekMessageA succeeded\n");
2911 memset(&msg
, 0, sizeof(msg
));
2912 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2914 ok(!success
|| broken(success
) /* Win 2000/XP/8 */, "PeekMessageA succeeded\n");
2917 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2918 ok(msg
.wParam
== 41, "expected msg.wParam = 41, got %lu\n", msg
.wParam
);
2920 index
= WaitForSingleObject(thread
, 200);
2921 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2922 CloseHandle(thread
);
2925 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2926 PostMessageA(hWnd
, WM_QUIT
, 42, 0);
2927 thread
= CreateThread(NULL
, 0, send_message_thread
, hWnd
, 0, &tid
);
2928 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2929 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2930 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2931 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2932 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2933 ok(!success
, "CoWaitForMultipleHandles didn't pump all WM_DDE_FIRST messages\n");
2934 memset(&msg
, 0, sizeof(msg
));
2935 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2936 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2937 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2938 ok(msg
.wParam
== 42, "expected msg.wParam = 42, got %lu\n", msg
.wParam
);
2939 index
= WaitForSingleObject(thread
, 200);
2940 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2941 CloseHandle(thread
);
2943 PostQuitMessage(43);
2944 memset(&msg
, 0, sizeof(msg
));
2945 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2946 ok(success
|| broken(!success
) /* Win 8 */, "PeekMessageA failed, error %u\n", GetLastError());
2948 win_skip("PostQuitMessage didn't queue a WM_QUIT message, skipping tests\n");
2951 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2952 ok(msg
.wParam
== 43, "expected msg.wParam = 43, got %lu\n", msg
.wParam
);
2953 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2954 ok(!success
, "PeekMessageA succeeded\n");
2957 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2958 PostQuitMessage(44);
2959 thread
= CreateThread(NULL
, 0, post_message_thread
, hWnd
, 0, &tid
);
2960 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2961 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2962 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2963 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2964 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2965 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2966 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2967 ok(!success
, "PeekMessageA succeeded\n");
2968 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2969 ok(!success
, "CoWaitForMultipleHandles didn't remove WM_QUIT messages\n");
2970 index
= WaitForSingleObject(thread
, 200);
2971 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2972 CloseHandle(thread
);
2975 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2976 PostQuitMessage(45);
2977 thread
= CreateThread(NULL
, 0, send_message_thread
, hWnd
, 0, &tid
);
2978 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2979 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2980 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2981 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2982 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2983 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2984 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2985 ok(!success
, "PeekMessageA succeeded\n");
2986 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2987 ok(!success
, "CoWaitForMultipleHandles didn't remove WM_QUIT messages\n");
2988 index
= WaitForSingleObject(thread
, 200);
2989 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2990 CloseHandle(thread
);
2993 /* test message pumping when CoWaitForMultipleHandles is called from non main apartment thread */
2994 thread
= CreateThread(NULL
, 0, test_CoWaitForMultipleHandles_thread
, handles
, 0, &tid
);
2995 index
= WaitForSingleObject(thread
, 500);
2996 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2997 CloseHandle(thread
);
3001 /* If COM was not initialized, messages are neither pumped nor peeked at */
3002 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
3003 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
3004 ok(hr
== RPC_S_CALLPENDING
, "got %#x\n", hr
);
3005 success
= MsgWaitForMultipleObjectsEx(0, NULL
, 2, QS_ALLPOSTMESSAGE
, MWMO_ALERTABLE
);
3006 ok(success
== 0, "MsgWaitForMultipleObjects returned %x\n", success
);
3007 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
3008 ok(success
, "PeekMessage failed: %u\n", GetLastError());
3010 /* same in an MTA */
3011 CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
3013 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
3014 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
3015 ok(hr
== RPC_S_CALLPENDING
, "got %#x\n", hr
);
3016 success
= MsgWaitForMultipleObjectsEx(0, NULL
, 2, QS_ALLPOSTMESSAGE
, MWMO_ALERTABLE
);
3017 ok(success
== 0, "MsgWaitForMultipleObjects returned %x\n", success
);
3018 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
3019 ok(success
, "PeekMessage failed: %u\n", GetLastError());
3023 CloseHandle(handles
[0]);
3024 CloseHandle(handles
[1]);
3025 DestroyWindow(hWnd
);
3027 success
= UnregisterClassA(cls_name
, GetModuleHandleA(0));
3028 ok(success
, "UnregisterClass failed %u\n", GetLastError());
3031 static void test_CoGetMalloc(void)
3036 if (0) /* crashes on native */
3037 hr
= CoGetMalloc(0, NULL
);
3039 imalloc
= (void*)0xdeadbeef;
3040 hr
= CoGetMalloc(0, &imalloc
);
3041 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3042 ok(imalloc
== NULL
, "got %p\n", imalloc
);
3044 imalloc
= (void*)0xdeadbeef;
3045 hr
= CoGetMalloc(MEMCTX_SHARED
, &imalloc
);
3046 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3047 ok(imalloc
== NULL
, "got %p\n", imalloc
);
3049 imalloc
= (void*)0xdeadbeef;
3050 hr
= CoGetMalloc(MEMCTX_MACSYSTEM
, &imalloc
);
3051 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3052 ok(imalloc
== NULL
, "got %p\n", imalloc
);
3054 imalloc
= (void*)0xdeadbeef;
3055 hr
= CoGetMalloc(MEMCTX_UNKNOWN
, &imalloc
);
3056 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3057 ok(imalloc
== NULL
, "got %p\n", imalloc
);
3059 imalloc
= (void*)0xdeadbeef;
3060 hr
= CoGetMalloc(MEMCTX_SAME
, &imalloc
);
3061 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3062 ok(imalloc
== NULL
, "got %p\n", imalloc
);
3065 hr
= CoGetMalloc(MEMCTX_TASK
, &imalloc
);
3066 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3067 ok(imalloc
!= NULL
, "got %p\n", imalloc
);
3068 IMalloc_Release(imalloc
);
3071 static void test_CoGetApartmentType(void)
3073 APTTYPEQUALIFIER qualifier
;
3077 if (!pCoGetApartmentType
)
3079 win_skip("CoGetApartmentType not present\n");
3083 hr
= pCoGetApartmentType(NULL
, NULL
);
3084 ok(hr
== E_INVALIDARG
, "CoGetApartmentType succeeded, error: 0x%08x\n", hr
);
3087 hr
= pCoGetApartmentType(&type
, NULL
);
3088 ok(hr
== E_INVALIDARG
, "CoGetApartmentType succeeded, error: 0x%08x\n", hr
);
3089 ok(type
== 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", type
);
3091 qualifier
= 0xdeadbeef;
3092 hr
= pCoGetApartmentType(NULL
, &qualifier
);
3093 ok(hr
== E_INVALIDARG
, "CoGetApartmentType succeeded, error: 0x%08x\n", hr
);
3094 ok(qualifier
== 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", qualifier
);
3097 qualifier
= 0xdeadbeef;
3098 hr
= pCoGetApartmentType(&type
, &qualifier
);
3099 ok(hr
== CO_E_NOTINITIALIZED
, "CoGetApartmentType succeeded, error: 0x%08x\n", hr
);
3100 ok(type
== APTTYPE_CURRENT
, "Expected APTTYPE_CURRENT, got %u\n", type
);
3101 ok(qualifier
== APTTYPEQUALIFIER_NONE
, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier
);
3104 qualifier
= 0xdeadbeef;
3105 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
3106 ok(hr
== S_OK
, "CoInitializeEx failed, error: 0x%08x\n", hr
);
3107 hr
= pCoGetApartmentType(&type
, &qualifier
);
3108 ok(hr
== S_OK
, "CoGetApartmentType failed, error: 0x%08x\n", hr
);
3109 ok(type
== APTTYPE_MAINSTA
, "Expected APTTYPE_MAINSTA, got %u\n", type
);
3110 ok(qualifier
== APTTYPEQUALIFIER_NONE
, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier
);
3114 qualifier
= 0xdeadbeef;
3115 hr
= pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
3116 ok(hr
== S_OK
, "CoInitializeEx failed, error: 0x%08x\n", hr
);
3117 hr
= pCoGetApartmentType(&type
, &qualifier
);
3118 ok(hr
== S_OK
, "CoGetApartmentType failed, error: 0x%08x\n", hr
);
3119 ok(type
== APTTYPE_MTA
, "Expected APTTYPE_MTA, got %u\n", type
);
3120 ok(qualifier
== APTTYPEQUALIFIER_NONE
, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier
);
3124 static HRESULT WINAPI
testspy_QI(IMallocSpy
*iface
, REFIID riid
, void **obj
)
3126 if (IsEqualIID(riid
, &IID_IMallocSpy
) || IsEqualIID(riid
, &IID_IUnknown
))
3129 IMallocSpy_AddRef(iface
);
3133 return E_NOINTERFACE
;
3136 static ULONG WINAPI
testspy_AddRef(IMallocSpy
*iface
)
3141 static ULONG WINAPI
testspy_Release(IMallocSpy
*iface
)
3146 static SIZE_T WINAPI
testspy_PreAlloc(IMallocSpy
*iface
, SIZE_T cb
)
3148 ok(0, "unexpected call\n");
3152 static void* WINAPI
testspy_PostAlloc(IMallocSpy
*iface
, void *ptr
)
3154 ok(0, "unexpected call\n");
3158 static void* WINAPI
testspy_PreFree(IMallocSpy
*iface
, void *ptr
, BOOL spyed
)
3160 ok(0, "unexpected call\n");
3164 static void WINAPI
testspy_PostFree(IMallocSpy
*iface
, BOOL spyed
)
3166 ok(0, "unexpected call\n");
3169 static SIZE_T WINAPI
testspy_PreRealloc(IMallocSpy
*iface
, void *ptr
, SIZE_T cb
, void **newptr
, BOOL spyed
)
3171 ok(0, "unexpected call\n");
3175 static void* WINAPI
testspy_PostRealloc(IMallocSpy
*iface
, void *ptr
, BOOL spyed
)
3177 ok(0, "unexpected call\n");
3181 static void* WINAPI
testspy_PreGetSize(IMallocSpy
*iface
, void *ptr
, BOOL spyed
)
3183 ok(0, "unexpected call\n");
3187 static SIZE_T WINAPI
testspy_PostGetSize(IMallocSpy
*iface
, SIZE_T actual
, BOOL spyed
)
3189 ok(0, "unexpected call\n");
3193 static void* WINAPI
testspy_PreDidAlloc(IMallocSpy
*iface
, void *ptr
, BOOL spyed
)
3195 ok(0, "unexpected call\n");
3199 static int WINAPI
testspy_PostDidAlloc(IMallocSpy
*iface
, void *ptr
, BOOL spyed
, int actual
)
3201 ok(0, "unexpected call\n");
3205 static void WINAPI
testspy_PreHeapMinimize(IMallocSpy
*iface
)
3207 ok(0, "unexpected call\n");
3210 static void WINAPI
testspy_PostHeapMinimize(IMallocSpy
*iface
)
3212 ok(0, "unexpected call\n");
3215 static const IMallocSpyVtbl testspyvtbl
=
3225 testspy_PostRealloc
,
3227 testspy_PostGetSize
,
3228 testspy_PreDidAlloc
,
3229 testspy_PostDidAlloc
,
3230 testspy_PreHeapMinimize
,
3231 testspy_PostHeapMinimize
3234 static IMallocSpy testspy
= { &testspyvtbl
};
3236 static void test_IMallocSpy(void)
3241 hr
= CoRegisterMallocSpy(NULL
);
3242 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3244 hr
= CoRevokeMallocSpy();
3245 ok(hr
== CO_E_OBJNOTREG
, "got 0x%08x\n", hr
);
3247 hr
= CoRegisterMallocSpy(&testspy
);
3248 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3250 hr
= CoRegisterMallocSpy(NULL
);
3251 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3253 hr
= CoRegisterMallocSpy(&testspy
);
3254 ok(hr
== CO_E_OBJISREG
, "got 0x%08x\n", hr
);
3257 hr
= CoGetMalloc(MEMCTX_TASK
, &imalloc
);
3258 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3259 ok(imalloc
!= NULL
, "got %p\n", imalloc
);
3261 IMalloc_Free(imalloc
, NULL
);
3263 IMalloc_Release(imalloc
);
3265 hr
= CoRevokeMallocSpy();
3266 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3268 hr
= CoRevokeMallocSpy();
3269 ok(hr
== CO_E_OBJNOTREG
, "got 0x%08x\n", hr
);
3272 static void test_CoGetCurrentLogicalThreadId(void)
3277 hr
= CoGetCurrentLogicalThreadId(NULL
);
3278 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3281 hr
= CoGetCurrentLogicalThreadId(&id
);
3282 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3283 ok(!IsEqualGUID(&id
, &GUID_NULL
), "got null id\n");
3286 static HRESULT WINAPI
testinitialize_QI(IInitializeSpy
*iface
, REFIID riid
, void **obj
)
3288 if (IsEqualIID(riid
, &IID_IInitializeSpy
) || IsEqualIID(riid
, &IID_IUnknown
))
3291 IInitializeSpy_AddRef(iface
);
3296 return E_NOINTERFACE
;
3299 static ULONG WINAPI
testinitialize_AddRef(IInitializeSpy
*iface
)
3304 static ULONG WINAPI
testinitialize_Release(IInitializeSpy
*iface
)
3309 static HRESULT WINAPI
testinitialize_PreInitialize(IInitializeSpy
*iface
, DWORD coinit
, DWORD aptrefs
)
3311 ok(0, "unexpected call\n");
3315 static HRESULT WINAPI
testinitialize_PostInitialize(IInitializeSpy
*iface
, HRESULT hr
, DWORD coinit
, DWORD aptrefs
)
3317 ok(0, "unexpected call\n");
3321 static HRESULT WINAPI
testinitialize_PreUninitialize(IInitializeSpy
*iface
, DWORD aptrefs
)
3323 ok(0, "unexpected call\n");
3327 static HRESULT WINAPI
testinitialize_PostUninitialize(IInitializeSpy
*iface
, DWORD aptrefs
)
3329 ok(0, "unexpected call\n");
3333 static const IInitializeSpyVtbl testinitializevtbl
=
3336 testinitialize_AddRef
,
3337 testinitialize_Release
,
3338 testinitialize_PreInitialize
,
3339 testinitialize_PostInitialize
,
3340 testinitialize_PreUninitialize
,
3341 testinitialize_PostUninitialize
3344 static IInitializeSpy testinitialize
= { &testinitializevtbl
};
3346 static void test_IInitializeSpy(void)
3348 ULARGE_INTEGER cookie
, cookie1
, cookie2
;
3351 hr
= CoRegisterInitializeSpy(NULL
, NULL
);
3352 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3354 cookie
.QuadPart
= 1;
3355 hr
= CoRegisterInitializeSpy(NULL
, &cookie
);
3356 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3357 ok(cookie
.QuadPart
== 1, "got wrong cookie\n");
3359 hr
= CoRegisterInitializeSpy(&testinitialize
, NULL
);
3360 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3362 cookie
.HighPart
= 0;
3364 hr
= CoRegisterInitializeSpy(&testinitialize
, &cookie
);
3365 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3367 ok(cookie
.HighPart
== GetCurrentThreadId(), "got high part 0x%08x, expected 0x%08x\n", cookie
.HighPart
,
3368 GetCurrentThreadId());
3369 ok(cookie
.LowPart
== 0, "got wrong low part 0x%x\n", cookie
.LowPart
);
3371 /* register same instance one more time */
3372 cookie1
.HighPart
= 0;
3373 cookie1
.LowPart
= 0;
3374 hr
= CoRegisterInitializeSpy(&testinitialize
, &cookie1
);
3376 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3377 ok(cookie1
.HighPart
== GetCurrentThreadId(), "got high part 0x%08x, expected 0x%08x\n", cookie1
.HighPart
,
3378 GetCurrentThreadId());
3379 ok(cookie1
.LowPart
== 1, "got wrong low part 0x%x\n", cookie1
.LowPart
);
3381 cookie2
.HighPart
= 0;
3382 cookie2
.LowPart
= 0;
3383 hr
= CoRegisterInitializeSpy(&testinitialize
, &cookie2
);
3385 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3386 ok(cookie2
.HighPart
== GetCurrentThreadId(), "got high part 0x%08x, expected 0x%08x\n", cookie2
.HighPart
,
3387 GetCurrentThreadId());
3388 ok(cookie2
.LowPart
== 2, "got wrong low part 0x%x\n", cookie2
.LowPart
);
3390 hr
= CoRevokeInitializeSpy(cookie1
);
3392 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3394 hr
= CoRevokeInitializeSpy(cookie1
);
3395 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3397 cookie1
.HighPart
= 0;
3398 cookie1
.LowPart
= 0;
3399 hr
= CoRegisterInitializeSpy(&testinitialize
, &cookie1
);
3401 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3402 ok(cookie1
.HighPart
== GetCurrentThreadId(), "got high part 0x%08x, expected 0x%08x\n", cookie1
.HighPart
,
3403 GetCurrentThreadId());
3404 ok(cookie1
.LowPart
== 1, "got wrong low part 0x%x\n", cookie1
.LowPart
);
3406 hr
= CoRevokeInitializeSpy(cookie
);
3407 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3409 hr
= CoRevokeInitializeSpy(cookie1
);
3411 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3413 hr
= CoRevokeInitializeSpy(cookie2
);
3415 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3418 static HRESULT g_persistfile_qi_ret
;
3419 static HRESULT g_persistfile_load_ret
;
3420 static HRESULT WINAPI
testinstance_QI(IPersistFile
*iface
, REFIID riid
, void **obj
)
3422 if (IsEqualIID(riid
, &IID_IUnknown
)) {
3424 IUnknown_AddRef(iface
);
3428 if (IsEqualIID(riid
, &IID_IPersistFile
)) {
3429 if (SUCCEEDED(g_persistfile_qi_ret
)) {
3431 IUnknown_AddRef(iface
);
3435 return g_persistfile_qi_ret
;
3438 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid
));
3440 return E_NOINTERFACE
;
3443 static ULONG WINAPI
testinstance_AddRef(IPersistFile
*iface
)
3448 static ULONG WINAPI
testinstance_Release(IPersistFile
*iface
)
3453 static HRESULT WINAPI
testinstance_GetClassID(IPersistFile
*iface
, CLSID
*clsid
)
3455 ok(0, "unexpected call\n");
3459 static HRESULT WINAPI
testinstance_IsDirty(IPersistFile
*iface
)
3461 ok(0, "unexpected call\n");
3465 static HRESULT WINAPI
testinstance_Load(IPersistFile
*iface
, LPCOLESTR filename
, DWORD mode
)
3467 return g_persistfile_load_ret
;
3470 static HRESULT WINAPI
testinstance_Save(IPersistFile
*iface
, LPCOLESTR filename
, BOOL remember
)
3475 static HRESULT WINAPI
testinstance_SaveCompleted(IPersistFile
*iface
, LPCOLESTR filename
)
3477 ok(0, "unexpected call\n");
3481 static HRESULT WINAPI
testinstance_GetCurFile(IPersistFile
*iface
, LPOLESTR
*filename
)
3483 ok(0, "unexpected call\n");
3487 static const IPersistFileVtbl testpersistfilevtbl
= {
3489 testinstance_AddRef
,
3490 testinstance_Release
,
3491 testinstance_GetClassID
,
3492 testinstance_IsDirty
,
3495 testinstance_SaveCompleted
,
3496 testinstance_GetCurFile
3499 static IPersistFile testpersistfile
= { &testpersistfilevtbl
};
3501 static HRESULT WINAPI
getinstance_cf_QI(IClassFactory
*iface
, REFIID riid
, void **obj
)
3503 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IClassFactory
)) {
3505 IClassFactory_AddRef(iface
);
3510 return E_NOINTERFACE
;
3513 static ULONG WINAPI
getinstance_cf_AddRef(IClassFactory
*iface
)
3518 static ULONG WINAPI
getinstance_cf_Release(IClassFactory
*iface
)
3523 static HRESULT WINAPI
getinstance_cf_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
,
3524 REFIID riid
, void **obj
)
3526 if (IsEqualIID(riid
, &IID_IUnknown
)) {
3527 *obj
= &testpersistfile
;
3531 ok(0, "unexpected call, riid %s\n", wine_dbgstr_guid(riid
));
3536 static HRESULT WINAPI
getinstance_cf_LockServer(IClassFactory
*iface
, BOOL lock
)
3538 ok(0, "unexpected call\n");
3542 static const IClassFactoryVtbl getinstance_cf_vtbl
= {
3544 getinstance_cf_AddRef
,
3545 getinstance_cf_Release
,
3546 getinstance_cf_CreateInstance
,
3547 getinstance_cf_LockServer
3550 static IClassFactory getinstance_cf
= { &getinstance_cf_vtbl
};
3552 static void test_CoGetInstanceFromFile(void)
3554 static const WCHAR filenameW
[] = {'d','u','m','m','y','p','a','t','h',0};
3555 CLSID
*clsid
= (CLSID
*)&CLSID_testclsid
;
3560 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
3561 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3563 /* CLSID is not specified, file does not exist */
3564 mqi
[0].pIID
= &IID_IUnknown
;
3566 mqi
[0].hr
= E_NOTIMPL
;
3567 hr
= CoGetInstanceFromFile(NULL
, NULL
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3569 ok(hr
== MK_E_CANTOPENFILE
, "got 0x%08x\n", hr
);
3570 ok(mqi
[0].pItf
== NULL
, "got %p\n", mqi
[0].pItf
);
3571 ok(mqi
[0].hr
== E_NOINTERFACE
, "got 0x%08x\n", mqi
[0].hr
);
3573 /* class is not available */
3574 mqi
[0].pIID
= &IID_IUnknown
;
3576 mqi
[0].hr
= E_NOTIMPL
;
3577 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3578 ok(hr
== REGDB_E_CLASSNOTREG
, "got 0x%08x\n", hr
);
3579 ok(mqi
[0].pItf
== NULL
, "got %p\n", mqi
[0].pItf
);
3580 ok(mqi
[0].hr
== REGDB_E_CLASSNOTREG
, "got 0x%08x\n", mqi
[0].hr
);
3582 hr
= CoRegisterClassObject(clsid
, (IUnknown
*)&getinstance_cf
, CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
,
3584 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3586 mqi
[0].pIID
= &IID_IUnknown
;
3587 mqi
[0].pItf
= (void*)0xdeadbeef;
3589 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3591 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3592 ok(mqi
[0].pItf
== (void*)0xdeadbeef, "got %p\n", mqi
[0].pItf
);
3594 ok(mqi
[0].hr
== S_OK
, "got 0x%08x\n", mqi
[0].hr
);
3596 mqi
[0].pIID
= &IID_IUnknown
;
3597 mqi
[0].pItf
= (void*)0xdeadbeef;
3598 mqi
[0].hr
= E_NOTIMPL
;
3599 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3601 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3602 ok(mqi
[0].pItf
== (void*)0xdeadbeef, "got %p\n", mqi
[0].pItf
);
3603 ok(mqi
[0].hr
== E_NOTIMPL
, "got 0x%08x\n", mqi
[0].hr
);
3605 mqi
[0].pIID
= &IID_IUnknown
;
3607 mqi
[0].hr
= E_NOTIMPL
;
3608 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3609 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3610 ok(mqi
[0].pItf
!= NULL
, "got %p\n", mqi
[0].pItf
);
3611 ok(mqi
[0].hr
== S_OK
, "got 0x%08x\n", mqi
[0].hr
);
3613 mqi
[0].pIID
= &IID_IUnknown
;
3616 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3617 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3618 ok(mqi
[0].pItf
!= NULL
, "got %p\n", mqi
[0].pItf
);
3619 ok(mqi
[0].hr
== S_OK
, "got 0x%08x\n", mqi
[0].hr
);
3621 mqi
[0].pIID
= &IID_IUnknown
;
3624 g_persistfile_qi_ret
= S_FALSE
;
3625 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3626 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3627 ok(mqi
[0].pItf
!= NULL
, "got %p\n", mqi
[0].pItf
);
3628 ok(mqi
[0].hr
== S_OK
, "got 0x%08x\n", mqi
[0].hr
);
3629 g_persistfile_qi_ret
= S_OK
;
3631 mqi
[0].pIID
= &IID_IUnknown
;
3634 mqi
[1].pIID
= &IID_IUnknown
;
3637 g_persistfile_qi_ret
= 0x8000efef;
3638 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 2, mqi
);
3639 ok(hr
== 0x8000efef, "got 0x%08x\n", hr
);
3640 ok(mqi
[0].pItf
== NULL
, "got %p\n", mqi
[0].pItf
);
3641 ok(mqi
[0].hr
== 0x8000efef, "got 0x%08x\n", mqi
[0].hr
);
3642 ok(mqi
[1].pItf
== NULL
, "got %p\n", mqi
[1].pItf
);
3643 ok(mqi
[1].hr
== 0x8000efef, "got 0x%08x\n", mqi
[1].hr
);
3644 g_persistfile_qi_ret
= S_OK
;
3646 mqi
[0].pIID
= &IID_IUnknown
;
3649 mqi
[1].pIID
= &IID_IUnknown
;
3652 g_persistfile_load_ret
= 0x8000fefe;
3653 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 2, mqi
);
3654 ok(hr
== 0x8000fefe, "got 0x%08x\n", hr
);
3655 ok(mqi
[0].pItf
== NULL
, "got %p\n", mqi
[0].pItf
);
3656 ok(mqi
[0].hr
== 0x8000fefe, "got 0x%08x\n", mqi
[0].hr
);
3657 ok(mqi
[1].pItf
== NULL
, "got %p\n", mqi
[1].pItf
);
3658 ok(mqi
[1].hr
== 0x8000fefe, "got 0x%08x\n", mqi
[1].hr
);
3659 g_persistfile_load_ret
= S_OK
;
3661 hr
= CoRevokeClassObject(cookie
);
3662 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3667 static void test_GlobalOptions(void)
3669 IGlobalOptions
*global_options
;
3674 hres
= CoCreateInstance(&CLSID_GlobalOptions
, NULL
, CLSCTX_INPROC_SERVER
,
3675 &IID_IGlobalOptions
, (void**)&global_options
);
3676 ok(hres
== S_OK
|| broken(hres
== E_NOINTERFACE
), "CoCreateInstance(CLSID_GlobalOptions) failed: %08x\n", hres
);
3679 win_skip("CLSID_GlobalOptions not available\n");
3684 IGlobalOptions_Release(global_options
);
3686 hres
= CoCreateInstance(&CLSID_GlobalOptions
, (IUnknown
*)0xdeadbeef, CLSCTX_INPROC_SERVER
,
3687 &IID_IGlobalOptions
, (void**)&global_options
);
3688 ok(hres
== E_INVALIDARG
, "CoCreateInstance(CLSID_GlobalOptions) failed: %08x\n", hres
);
3693 static void init_funcs(void)
3695 HMODULE hOle32
= GetModuleHandleA("ole32");
3696 HMODULE hAdvapi32
= GetModuleHandleA("advapi32");
3697 HMODULE hkernel32
= GetModuleHandleA("kernel32");
3699 pCoGetObjectContext
= (void*)GetProcAddress(hOle32
, "CoGetObjectContext");
3700 pCoSwitchCallContext
= (void*)GetProcAddress(hOle32
, "CoSwitchCallContext");
3701 pCoGetTreatAsClass
= (void*)GetProcAddress(hOle32
,"CoGetTreatAsClass");
3702 pCoTreatAsClass
= (void*)GetProcAddress(hOle32
,"CoTreatAsClass");
3703 pCoGetContextToken
= (void*)GetProcAddress(hOle32
, "CoGetContextToken");
3704 pCoGetApartmentType
= (void*)GetProcAddress(hOle32
, "CoGetApartmentType");
3705 pRegDeleteKeyExA
= (void*)GetProcAddress(hAdvapi32
, "RegDeleteKeyExA");
3706 pRegOverridePredefKey
= (void*)GetProcAddress(hAdvapi32
, "RegOverridePredefKey");
3707 pCoInitializeEx
= (void*)GetProcAddress(hOle32
, "CoInitializeEx");
3709 pActivateActCtx
= (void*)GetProcAddress(hkernel32
, "ActivateActCtx");
3710 pCreateActCtxW
= (void*)GetProcAddress(hkernel32
, "CreateActCtxW");
3711 pDeactivateActCtx
= (void*)GetProcAddress(hkernel32
, "DeactivateActCtx");
3712 pIsWow64Process
= (void*)GetProcAddress(hkernel32
, "IsWow64Process");
3713 pReleaseActCtx
= (void*)GetProcAddress(hkernel32
, "ReleaseActCtx");
3716 static DWORD CALLBACK
implicit_mta_proc(void *param
)
3718 IComThreadingInfo
*threading_info
;
3725 test_apt_type(APTTYPE_MTA
, APTTYPEQUALIFIER_IMPLICIT_MTA
);
3727 hr
= CoCreateInstance(&CLSID_InternetZoneManager
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&unk
);
3728 ok_ole_success(hr
, "CoCreateInstance");
3729 IUnknown_Release(unk
);
3731 hr
= CoGetClassObject(&CLSID_InternetZoneManager
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&unk
);
3732 ok_ole_success(hr
, "CoGetClassObject");
3733 IUnknown_Release(unk
);
3735 hr
= CoGetObjectContext(&IID_IComThreadingInfo
, (void **)&threading_info
);
3736 ok_ole_success(hr
, "CoGetObjectContext");
3737 IComThreadingInfo_Release(threading_info
);
3739 hr
= CoGetContextToken(&token
);
3740 ok_ole_success(hr
, "CoGetContextToken");
3742 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
3743 ok_ole_success(hr
, "CoRegisterPSClsid");
3745 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
3746 ok_ole_success(hr
, "CoGetPSClsid");
3748 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
3749 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
3750 ok_ole_success(hr
, "CoRegisterClassObject");
3752 hr
= CoRevokeClassObject(cookie
);
3753 ok_ole_success(hr
, "CoRevokeClassObject");
3755 hr
= CoRegisterMessageFilter(NULL
, NULL
);
3756 ok(hr
== CO_E_NOT_SUPPORTED
, "got %#x\n", hr
);
3758 hr
= CoLockObjectExternal((IUnknown
*)&Test_Unknown
, TRUE
, TRUE
);
3759 ok_ole_success(hr
, "CoLockObjectExternal");
3761 hr
= CoDisconnectObject((IUnknown
*)&Test_Unknown
, 0);
3762 ok_ole_success(hr
, "CoDisconnectObject");
3767 /* Some COM functions (perhaps even all of them?) can make use of an "implicit"
3768 * multi-threaded apartment created by another thread in the same process. */
3769 static void test_implicit_mta(void)
3773 CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
3775 thread
= CreateThread(NULL
, 0, implicit_mta_proc
, NULL
, 0, NULL
);
3776 ok(!WaitForSingleObject(thread
, 1000), "wait failed\n");
3785 if (!pCoInitializeEx
)
3787 trace("You need DCOM95 installed to run this test\n");
3791 if (!pCreateActCtxW
)
3792 win_skip("Activation contexts are not supported, some tests will be skipped.\n");
3794 test_ProgIDFromCLSID();
3795 test_CLSIDFromProgID();
3796 test_CLSIDFromString();
3797 test_IIDFromString();
3798 test_StringFromGUID2();
3799 test_CoCreateInstance();
3801 test_CoGetClassObject();
3802 test_CoCreateInstanceEx();
3803 test_CoRegisterMessageFilter();
3804 test_CoRegisterPSClsid();
3805 test_CoGetPSClsid();
3806 test_CoUnmarshalInterface();
3807 test_CoGetInterfaceAndReleaseStream();
3808 test_CoMarshalInterface();
3809 test_CoMarshalInterThreadInterfaceInStream();
3810 test_CoRegisterClassObject();
3811 test_registered_object_thread_affinity();
3812 test_CoFreeUnusedLibraries();
3813 test_CoGetObjectContext();
3814 test_CoGetCallContext();
3815 test_CoGetContextToken();
3816 test_TreatAsClass();
3817 test_CoInitializeEx();
3818 test_OleInitialize_InitCounting();
3819 test_OleRegGetMiscStatus();
3820 test_CoCreateGuid();
3821 test_CoWaitForMultipleHandles();
3823 test_OleRegGetUserType();
3824 test_CoGetApartmentType();
3826 test_CoGetCurrentLogicalThreadId();
3827 test_IInitializeSpy();
3828 test_CoGetInstanceFromFile();
3829 test_GlobalOptions();
3830 test_implicit_mta();