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
27 extern const IID GUID_NULL
;
29 #define DEFINE_EXPECT(func) \
30 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
32 #define SET_EXPECT(func) \
33 expect_ ## func = TRUE
35 #define CHECK_EXPECT2(func) \
37 ok(expect_ ##func, "unexpected call " #func "\n"); \
38 called_ ## func = TRUE; \
41 #define CHECK_EXPECT(func) \
43 CHECK_EXPECT2(func); \
44 expect_ ## func = FALSE; \
47 #define CHECK_CALLED(func) \
49 ok(called_ ## func, "expected " #func "\n"); \
50 expect_ ## func = called_ ## func = FALSE; \
53 DEFINE_EXPECT(CreateStub
);
55 /* functions that are not present on all versions of Windows */
56 static HRESULT (WINAPI
* pCoInitializeEx
)(LPVOID lpReserved
, DWORD dwCoInit
);
57 static HRESULT (WINAPI
* pCoGetObjectContext
)(REFIID riid
, LPVOID
*ppv
);
58 static HRESULT (WINAPI
* pCoSwitchCallContext
)(IUnknown
*pObject
, IUnknown
**ppOldObject
);
59 static HRESULT (WINAPI
* pCoGetTreatAsClass
)(REFCLSID clsidOld
, LPCLSID pClsidNew
);
60 static HRESULT (WINAPI
* pCoTreatAsClass
)(REFCLSID clsidOld
, REFCLSID pClsidNew
);
61 static HRESULT (WINAPI
* pCoGetContextToken
)(ULONG_PTR
*token
);
62 static HRESULT (WINAPI
* pCoGetApartmentType
)(APTTYPE
*type
, APTTYPEQUALIFIER
*qualifier
);
63 static LONG (WINAPI
* pRegDeleteKeyExA
)(HKEY
, LPCSTR
, REGSAM
, DWORD
);
64 static LONG (WINAPI
* pRegOverridePredefKey
)(HKEY key
, HKEY override
);
66 static BOOL (WINAPI
*pActivateActCtx
)(HANDLE
,ULONG_PTR
*);
67 static HANDLE (WINAPI
*pCreateActCtxW
)(PCACTCTXW
);
68 static BOOL (WINAPI
*pDeactivateActCtx
)(DWORD
,ULONG_PTR
);
69 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
, LPBOOL
);
70 static void (WINAPI
*pReleaseActCtx
)(HANDLE
);
72 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
73 #define ok_more_than_one_lock() ok(cLocks > 0, "Number of locks should be > 0, but actually is %d\n", cLocks)
74 #define ok_no_locks() ok(cLocks == 0, "Number of locks should be 0, but actually is %d\n", cLocks)
76 static const CLSID CLSID_non_existent
= { 0x12345678, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
77 static const CLSID CLSID_StdFont
= { 0x0be35203, 0x8f91, 0x11ce, { 0x9d, 0xe3, 0x00, 0xaa, 0x00, 0x4b, 0xb8, 0x51 } };
78 static const GUID IID_Testiface
= { 0x22222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
79 static const GUID IID_Testiface2
= { 0x32222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
80 static const GUID IID_Testiface3
= { 0x42222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
81 static const GUID IID_Testiface4
= { 0x52222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
82 static const GUID IID_Testiface5
= { 0x62222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
83 static const GUID IID_Testiface6
= { 0x72222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
84 static const GUID IID_TestPS
= { 0x66666666, 0x8888, 0x7777, { 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 } };
86 DEFINE_GUID(CLSID_InProcFreeMarshaler
, 0x0000033a,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
87 DEFINE_GUID(CLSID_testclsid
, 0xacd014c7,0x9535,0x4fac,0x8b,0x53,0xa4,0x8c,0xa7,0xf4,0xd7,0x26);
88 DEFINE_GUID(CLSID_GlobalOptions
, 0x0000034b,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
90 static const WCHAR stdfont
[] = {'S','t','d','F','o','n','t',0};
91 static const WCHAR wszNonExistent
[] = {'N','o','n','E','x','i','s','t','e','n','t',0};
92 static const WCHAR wszCLSID_StdFont
[] =
94 '{','0','b','e','3','5','2','0','3','-','8','f','9','1','-','1','1','c','e','-',
95 '9','d','e','3','-','0','0','a','a','0','0','4','b','b','8','5','1','}',0
97 static const WCHAR progidW
[] = {'P','r','o','g','I','d','.','P','r','o','g','I','d',0};
98 static const WCHAR cf_brokenW
[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-',
99 'c','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}','a',0};
101 DEFINE_GUID(IID_IWineTest
, 0x5201163f, 0x8164, 0x4fd0, 0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd);
102 DEFINE_GUID(CLSID_WineOOPTest
, 0x5201163f, 0x8164, 0x4fd0, 0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd);
106 static void LockModule(void)
108 InterlockedIncrement(&cLocks
);
111 static void UnlockModule(void)
113 InterlockedDecrement(&cLocks
);
116 static HRESULT WINAPI
Test_IClassFactory_QueryInterface(
117 LPCLASSFACTORY iface
,
121 if (ppvObj
== NULL
) return E_POINTER
;
123 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
124 IsEqualGUID(riid
, &IID_IClassFactory
))
127 IClassFactory_AddRef(iface
);
132 return E_NOINTERFACE
;
135 static ULONG WINAPI
Test_IClassFactory_AddRef(LPCLASSFACTORY iface
)
138 return 2; /* non-heap-based object */
141 static ULONG WINAPI
Test_IClassFactory_Release(LPCLASSFACTORY iface
)
144 return 1; /* non-heap-based object */
147 static IID create_instance_iid
;
148 static HRESULT WINAPI
Test_IClassFactory_CreateInstance(
149 LPCLASSFACTORY iface
,
155 create_instance_iid
= *riid
;
156 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
157 return E_NOINTERFACE
;
160 static HRESULT WINAPI
Test_IClassFactory_LockServer(
161 LPCLASSFACTORY iface
,
167 static const IClassFactoryVtbl TestClassFactory_Vtbl
=
169 Test_IClassFactory_QueryInterface
,
170 Test_IClassFactory_AddRef
,
171 Test_IClassFactory_Release
,
172 Test_IClassFactory_CreateInstance
,
173 Test_IClassFactory_LockServer
176 static IClassFactory Test_ClassFactory
= { &TestClassFactory_Vtbl
};
178 static WCHAR manifest_path
[MAX_PATH
];
180 static BOOL
create_manifest_file(const char *filename
, const char *manifest
)
185 WCHAR path
[MAX_PATH
];
187 MultiByteToWideChar( CP_ACP
, 0, filename
, -1, path
, MAX_PATH
);
188 GetFullPathNameW(path
, sizeof(manifest_path
)/sizeof(WCHAR
), manifest_path
, NULL
);
190 manifest_len
= strlen(manifest
);
191 file
= CreateFileW(path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
192 FILE_ATTRIBUTE_NORMAL
, NULL
);
193 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed: %u\n", GetLastError());
194 if(file
== INVALID_HANDLE_VALUE
)
196 WriteFile(file
, manifest
, manifest_len
, &size
, NULL
);
202 static HANDLE
activate_context(const char *manifest
, ULONG_PTR
*cookie
)
204 WCHAR path
[MAX_PATH
];
209 if (!pCreateActCtxW
) return NULL
;
211 create_manifest_file("file.manifest", manifest
);
213 MultiByteToWideChar( CP_ACP
, 0, "file.manifest", -1, path
, MAX_PATH
);
214 memset(&actctx
, 0, sizeof(ACTCTXW
));
215 actctx
.cbSize
= sizeof(ACTCTXW
);
216 actctx
.lpSource
= path
;
218 handle
= pCreateActCtxW(&actctx
);
219 ok(handle
!= INVALID_HANDLE_VALUE
|| broken(handle
== INVALID_HANDLE_VALUE
) /* some old XP/2k3 versions */,
220 "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
221 if (handle
== INVALID_HANDLE_VALUE
)
223 win_skip("activation context generation failed, some tests will be skipped\n");
227 ok(actctx
.cbSize
== sizeof(ACTCTXW
), "actctx.cbSize=%d\n", actctx
.cbSize
);
228 ok(actctx
.dwFlags
== 0, "actctx.dwFlags=%d\n", actctx
.dwFlags
);
229 ok(actctx
.lpSource
== path
, "actctx.lpSource=%p\n", actctx
.lpSource
);
230 ok(actctx
.wProcessorArchitecture
== 0, "actctx.wProcessorArchitecture=%d\n", actctx
.wProcessorArchitecture
);
231 ok(actctx
.wLangId
== 0, "actctx.wLangId=%d\n", actctx
.wLangId
);
232 ok(actctx
.lpAssemblyDirectory
== NULL
, "actctx.lpAssemblyDirectory=%p\n", actctx
.lpAssemblyDirectory
);
233 ok(actctx
.lpResourceName
== NULL
, "actctx.lpResourceName=%p\n", actctx
.lpResourceName
);
234 ok(actctx
.lpApplicationName
== NULL
, "actctx.lpApplicationName=%p\n", actctx
.lpApplicationName
);
235 ok(actctx
.hModule
== NULL
, "actctx.hModule=%p\n", actctx
.hModule
);
237 DeleteFileA("file.manifest");
241 ret
= pActivateActCtx(handle
, cookie
);
242 ok(ret
, "ActivateActCtx failed: %u\n", GetLastError());
248 static const char actctx_manifest
[] =
249 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
250 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\""
251 " publicKeyToken=\"6595b6414666f1df\" />"
252 "<file name=\"testlib.dll\">"
254 " clsid=\"{0000033a-0000-0000-c000-000000000046}\""
255 " progid=\"FTMarshal\""
258 " clsid=\"{5201163f-8164-4fd0-a1a2-5d5a3654d3bd}\""
259 " progid=\"WineOOPTest\""
261 " <comClass description=\"Test com class\""
262 " clsid=\"{12345678-1234-1234-1234-56789abcdef0}\""
263 " progid=\"ProgId.ProgId\""
264 " miscStatusIcon=\"recomposeonresize\""
266 " <comClass description=\"CustomFont Description\" clsid=\"{0be35203-8f91-11ce-9de3-00aa004bb851}\""
267 " progid=\"CustomFont\""
268 " miscStatusIcon=\"recomposeonresize\""
269 " miscStatusContent=\"insideout\""
271 " <comClass description=\"StdFont Description\" clsid=\"{0be35203-8f91-11ce-9de3-00aa004bb852}\""
272 " progid=\"StdFont\""
274 " <comClass clsid=\"{62222222-1234-1234-1234-56789abcdef0}\" >"
275 " <progid>ProgId.ProgId.1</progid>"
277 " <comInterfaceProxyStub "
279 " iid=\"{22222222-1234-1234-1234-56789abcdef0}\""
280 " proxyStubClsid32=\"{66666666-8888-7777-6666-555555555555}\""
283 " <comInterfaceExternalProxyStub "
284 " name=\"Iifaceps2\""
285 " iid=\"{32222222-1234-1234-1234-56789abcdef0}\""
287 " <comInterfaceExternalProxyStub "
288 " name=\"Iifaceps3\""
289 " iid=\"{42222222-1234-1234-1234-56789abcdef0}\""
290 " proxyStubClsid32=\"{66666666-8888-7777-6666-555555555555}\""
292 " <comInterfaceExternalProxyStub "
293 " name=\"Iifaceps4\""
294 " iid=\"{52222222-1234-1234-1234-56789abcdef0}\""
295 " proxyStubClsid32=\"{00000000-0000-0000-0000-000000000000}\""
298 " clsid=\"{72222222-1234-1234-1234-56789abcdef0}\""
301 " <progid>clrprogid.1</progid>"
305 DEFINE_GUID(CLSID_Testclass
, 0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0);
307 static void test_ProgIDFromCLSID(void)
309 ULONG_PTR cookie
= 0;
314 hr
= ProgIDFromCLSID(&CLSID_StdFont
, &progid
);
315 ok(hr
== S_OK
, "ProgIDFromCLSID failed with error 0x%08x\n", hr
);
318 ok(!lstrcmpiW(progid
, stdfont
), "Didn't get expected prog ID\n");
319 CoTaskMemFree(progid
);
322 progid
= (LPWSTR
)0xdeadbeef;
323 hr
= ProgIDFromCLSID(&CLSID_non_existent
, &progid
);
324 ok(hr
== REGDB_E_CLASSNOTREG
, "ProgIDFromCLSID returned %08x\n", hr
);
325 ok(progid
== NULL
, "ProgIDFromCLSID returns with progid %p\n", progid
);
327 hr
= ProgIDFromCLSID(&CLSID_StdFont
, NULL
);
328 ok(hr
== E_INVALIDARG
, "ProgIDFromCLSID should return E_INVALIDARG instead of 0x%08x\n", hr
);
330 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
332 static const WCHAR customfontW
[] = {'C','u','s','t','o','m','F','o','n','t',0};
334 hr
= ProgIDFromCLSID(&CLSID_non_existent
, &progid
);
335 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
336 ok(!lstrcmpiW(progid
, progidW
), "got %s\n", wine_dbgstr_w(progid
));
337 CoTaskMemFree(progid
);
339 /* try something registered and redirected */
341 hr
= ProgIDFromCLSID(&CLSID_StdFont
, &progid
);
342 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
343 ok(!lstrcmpiW(progid
, customfontW
), "got wrong progid %s\n", wine_dbgstr_w(progid
));
344 CoTaskMemFree(progid
);
346 /* classes without default progid, progid list is not used */
347 progid
= (void *)0xdeadbeef;
348 hr
= ProgIDFromCLSID(&IID_Testiface5
, &progid
);
349 ok(hr
== REGDB_E_CLASSNOTREG
&& progid
== NULL
, "got 0x%08x, progid %p\n", hr
, progid
);
351 progid
= (void *)0xdeadbeef;
352 hr
= ProgIDFromCLSID(&IID_Testiface6
, &progid
);
353 ok(hr
== REGDB_E_CLASSNOTREG
&& progid
== NULL
, "got 0x%08x, progid %p\n", hr
, progid
);
355 pDeactivateActCtx(0, cookie
);
356 pReleaseActCtx(handle
);
360 static void test_CLSIDFromProgID(void)
362 ULONG_PTR cookie
= 0;
365 HRESULT hr
= CLSIDFromProgID(stdfont
, &clsid
);
366 ok(hr
== S_OK
, "CLSIDFromProgID failed with error 0x%08x\n", hr
);
367 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
369 hr
= CLSIDFromString(stdfont
, &clsid
);
370 ok_ole_success(hr
, "CLSIDFromString");
371 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
373 /* test some failure cases */
375 hr
= CLSIDFromProgID(wszNonExistent
, NULL
);
376 ok(hr
== E_INVALIDARG
, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
378 hr
= CLSIDFromProgID(NULL
, &clsid
);
379 ok(hr
== E_INVALIDARG
, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
381 memset(&clsid
, 0xcc, sizeof(clsid
));
382 hr
= CLSIDFromProgID(wszNonExistent
, &clsid
);
383 ok(hr
== CO_E_CLASSSTRING
, "CLSIDFromProgID on nonexistent ProgID should have returned CO_E_CLASSSTRING instead of 0x%08x\n", hr
);
384 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "CLSIDFromProgID should have set clsid to all-zeros on failure\n");
386 /* fails without proper context */
387 memset(&clsid
, 0xcc, sizeof(clsid
));
388 hr
= CLSIDFromProgID(progidW
, &clsid
);
389 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
390 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "wrong clsid\n");
392 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
396 memset(&clsid
, 0xcc, sizeof(clsid
));
397 hr
= CLSIDFromProgID(wszNonExistent
, &clsid
);
398 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
399 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "should have zero CLSID on failure\n");
401 /* CLSIDFromString() doesn't check activation context */
402 hr
= CLSIDFromString(progidW
, &clsid
);
403 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
406 hr
= CLSIDFromProgID(progidW
, &clsid
);
407 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
408 /* it returns generated CLSID here */
409 ok(!IsEqualCLSID(&clsid
, &CLSID_non_existent
) && !IsEqualCLSID(&clsid
, &CLSID_NULL
),
410 "got wrong clsid %s\n", wine_dbgstr_guid(&clsid
));
412 /* duplicate progid present in context - returns generated guid here too */
414 hr
= CLSIDFromProgID(stdfont
, &clsid
);
415 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
416 clsid1
= CLSID_StdFont
;
417 /* that's where it differs from StdFont */
418 clsid1
.Data4
[7] = 0x52;
419 ok(!IsEqualCLSID(&clsid
, &CLSID_StdFont
) && !IsEqualCLSID(&clsid
, &CLSID_NULL
) && !IsEqualCLSID(&clsid
, &clsid1
),
420 "got %s\n", wine_dbgstr_guid(&clsid
));
422 pDeactivateActCtx(0, cookie
);
423 pReleaseActCtx(handle
);
427 static void test_CLSIDFromString(void)
430 WCHAR wszCLSID_Broken
[50];
433 HRESULT hr
= CLSIDFromString(wszCLSID_StdFont
, &clsid
);
434 ok_ole_success(hr
, "CLSIDFromString");
435 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
437 memset(&clsid
, 0xab, sizeof(clsid
));
438 hr
= CLSIDFromString(NULL
, &clsid
);
439 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
440 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "clsid wasn't equal to CLSID_NULL\n");
442 /* string is longer, but starts with a valid CLSID */
443 memset(&clsid
, 0, sizeof(clsid
));
444 hr
= CLSIDFromString(cf_brokenW
, &clsid
);
445 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
446 ok(IsEqualCLSID(&clsid
, &IID_IClassFactory
), "got %s\n", wine_dbgstr_guid(&clsid
));
448 lstrcpyW(wszCLSID_Broken
, wszCLSID_StdFont
);
449 for(i
= lstrlenW(wszCLSID_StdFont
); i
< 49; i
++)
450 wszCLSID_Broken
[i
] = 'A';
451 wszCLSID_Broken
[i
] = '\0';
453 memset(&clsid
, 0, sizeof(CLSID
));
454 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
455 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
456 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
458 wszCLSID_Broken
[lstrlenW(wszCLSID_StdFont
)-1] = 'A';
459 memset(&clsid
, 0, sizeof(CLSID
));
460 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
461 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
462 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
464 wszCLSID_Broken
[lstrlenW(wszCLSID_StdFont
)] = '\0';
465 memset(&clsid
, 0, sizeof(CLSID
));
466 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
467 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
468 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
470 wszCLSID_Broken
[lstrlenW(wszCLSID_StdFont
)-1] = '\0';
471 memset(&clsid
, 0, sizeof(CLSID
));
472 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
473 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
474 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
476 memset(&clsid
, 0xcc, sizeof(CLSID
));
477 hr
= CLSIDFromString(wszCLSID_Broken
+1, &clsid
);
478 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
479 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "clsid wasn't equal to CLSID_NULL\n");
481 wszCLSID_Broken
[9] = '*';
482 memset(&clsid
, 0xcc, sizeof(CLSID
));
483 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
484 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
485 ok(clsid
.Data1
== CLSID_StdFont
.Data1
, "Got %08x\n", clsid
.Data1
);
486 ok(clsid
.Data2
== 0xcccc, "Got %04x\n", clsid
.Data2
);
488 wszCLSID_Broken
[3] = '*';
489 memset(&clsid
, 0xcc, sizeof(CLSID
));
490 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
491 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
492 ok(clsid
.Data1
== 0xb, "Got %08x\n", clsid
.Data1
);
493 ok(clsid
.Data2
== 0xcccc, "Got %04x\n", clsid
.Data2
);
495 wszCLSID_Broken
[3] = '\0';
496 memset(&clsid
, 0xcc, sizeof(CLSID
));
497 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
498 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
499 ok(clsid
.Data1
== 0xb, "Got %08x\n", clsid
.Data1
);
500 ok(clsid
.Data2
== 0xcccc, "Got %04x\n", clsid
.Data2
);
503 static void test_IIDFromString(void)
505 static const WCHAR cfW
[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-',
506 'c','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
507 static const WCHAR brokenW
[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-',
508 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
509 static const WCHAR broken2W
[] = {'{','0','0','0','0','0','0','0','1','=','0','0','0','0','-','0','0','0','0','-',
510 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
511 static const WCHAR broken3W
[] = {'b','r','o','k','e','n','0','0','1','=','0','0','0','0','-','0','0','0','0','-',
512 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
516 hr
= IIDFromString(wszCLSID_StdFont
, &iid
);
517 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
518 ok(IsEqualIID(&iid
, &CLSID_StdFont
), "got iid %s\n", wine_dbgstr_guid(&iid
));
520 memset(&iid
, 0xab, sizeof(iid
));
521 hr
= IIDFromString(NULL
, &iid
);
522 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
523 ok(IsEqualIID(&iid
, &CLSID_NULL
), "got iid %s\n", wine_dbgstr_guid(&iid
));
525 hr
= IIDFromString(cfW
, &iid
);
526 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
527 ok(IsEqualIID(&iid
, &IID_IClassFactory
), "got iid %s\n", wine_dbgstr_guid(&iid
));
529 /* string starts with a valid IID but is longer */
530 memset(&iid
, 0xab, sizeof(iid
));
531 hr
= IIDFromString(cf_brokenW
, &iid
);
532 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
533 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
535 /* invalid IID in a valid format */
536 memset(&iid
, 0xab, sizeof(iid
));
537 hr
= IIDFromString(brokenW
, &iid
);
538 ok(hr
== CO_E_IIDSTRING
, "got 0x%08x\n", hr
);
539 ok(iid
.Data1
== 0x00000001, "Got %08x\n", iid
.Data1
);
541 memset(&iid
, 0xab, sizeof(iid
));
542 hr
= IIDFromString(broken2W
, &iid
);
543 ok(hr
== CO_E_IIDSTRING
, "got 0x%08x\n", hr
);
544 ok(iid
.Data1
== 0x00000001, "Got %08x\n", iid
.Data1
);
546 /* format is broken, but string length is okay */
547 memset(&iid
, 0xab, sizeof(iid
));
548 hr
= IIDFromString(broken3W
, &iid
);
549 ok(hr
== CO_E_IIDSTRING
, "got 0x%08x\n", hr
);
550 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
553 memset(&iid
, 0xab, sizeof(iid
));
554 hr
= IIDFromString(wszNonExistent
, &iid
);
555 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
556 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
559 memset(&iid
, 0xab, sizeof(iid
));
560 hr
= IIDFromString(stdfont
, &iid
);
561 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
562 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
565 static void test_StringFromGUID2(void)
570 /* invalid pointer */
571 SetLastError(0xdeadbeef);
572 len
= StringFromGUID2(NULL
,str
,50);
573 ok(len
== 0, "len: %d (expected 0)\n", len
);
574 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %x\n", GetLastError());
576 /* Test corner cases for buffer size */
577 len
= StringFromGUID2(&CLSID_StdFont
,str
,50);
578 ok(len
== 39, "len: %d (expected 39)\n", len
);
579 ok(!lstrcmpiW(str
, wszCLSID_StdFont
),"string wasn't equal for CLSID_StdFont\n");
581 memset(str
,0,sizeof str
);
582 len
= StringFromGUID2(&CLSID_StdFont
,str
,39);
583 ok(len
== 39, "len: %d (expected 39)\n", len
);
584 ok(!lstrcmpiW(str
, wszCLSID_StdFont
),"string wasn't equal for CLSID_StdFont\n");
586 len
= StringFromGUID2(&CLSID_StdFont
,str
,38);
587 ok(len
== 0, "len: %d (expected 0)\n", len
);
589 len
= StringFromGUID2(&CLSID_StdFont
,str
,30);
590 ok(len
== 0, "len: %d (expected 0)\n", len
);
598 static DWORD CALLBACK
ole_initialize_thread(LPVOID pv
)
601 struct info
*info
= pv
;
603 hr
= pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
605 SetEvent(info
->wait
);
606 WaitForSingleObject(info
->stop
, 10000);
612 #define test_apt_type(t, q, t_t, t_q) _test_apt_type(t, q, t_t, t_q, __LINE__)
613 static void _test_apt_type(APTTYPE expected_type
, APTTYPEQUALIFIER expected_qualifier
, BOOL todo_type
,
614 BOOL todo_qualifier
, int line
)
616 APTTYPEQUALIFIER qualifier
= ~0u;
620 if (!pCoGetApartmentType
)
623 hr
= pCoGetApartmentType(&type
, &qualifier
);
624 ok_(__FILE__
, line
)(hr
== S_OK
|| hr
== CO_E_NOTINITIALIZED
, "Unexpected return code: 0x%08x\n", hr
);
625 todo_wine_if(todo_type
)
626 ok_(__FILE__
, line
)(type
== expected_type
, "Wrong apartment type %d, expected %d\n", type
, expected_type
);
627 todo_wine_if(todo_qualifier
)
628 ok_(__FILE__
, line
)(qualifier
== expected_qualifier
, "Wrong apartment qualifier %d, expected %d\n", qualifier
,
632 static void test_CoCreateInstance(void)
639 REFCLSID rclsid
= &CLSID_InternetZoneManager
;
641 pUnk
= (IUnknown
*)0xdeadbeef;
642 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
643 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
644 ok(pUnk
== NULL
, "CoCreateInstance should have changed the passed in pointer to NULL, instead of %p\n", pUnk
);
648 /* test errors returned for non-registered clsids */
649 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
650 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered inproc server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
651 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_INPROC_HANDLER
, &IID_IUnknown
, (void **)&pUnk
);
652 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered inproc handler should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
653 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_LOCAL_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
654 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered local server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
655 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_REMOTE_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
656 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered remote server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
658 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
659 if(hr
== REGDB_E_CLASSNOTREG
)
661 skip("IE not installed so can't test CoCreateInstance\n");
666 ok_ole_success(hr
, "CoCreateInstance");
667 if(pUnk
) IUnknown_Release(pUnk
);
670 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
671 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
673 /* show that COM doesn't have to be initialized for multi-threaded apartments if another
674 thread has already done so */
676 test_apt_type(APTTYPE_CURRENT
, APTTYPEQUALIFIER_NONE
, FALSE
, FALSE
);
678 info
.wait
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
679 ok(info
.wait
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
681 info
.stop
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
682 ok(info
.stop
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
684 thread
= CreateThread(NULL
, 0, ole_initialize_thread
, &info
, 0, &tid
);
685 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
687 ok( !WaitForSingleObject(info
.wait
, 10000 ), "wait timed out\n" );
689 test_apt_type(APTTYPE_MTA
, APTTYPEQUALIFIER_IMPLICIT_MTA
, TRUE
, TRUE
);
691 pUnk
= (IUnknown
*)0xdeadbeef;
692 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
693 ok(hr
== S_OK
, "CoCreateInstance should have returned S_OK instead of 0x%08x\n", hr
);
694 if (pUnk
) IUnknown_Release(pUnk
);
697 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
699 GetExitCodeThread(thread
, &exitcode
);
701 ok(hr
== S_OK
, "thread should have returned S_OK instead of 0x%08x\n", hr
);
704 CloseHandle(info
.wait
);
705 CloseHandle(info
.stop
);
707 test_apt_type(APTTYPE_CURRENT
, APTTYPEQUALIFIER_NONE
, FALSE
, FALSE
);
710 static void test_CoGetClassObject(void)
713 HANDLE thread
, handle
;
718 REFCLSID rclsid
= &CLSID_InternetZoneManager
;
722 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
723 ok(hr
== CO_E_NOTINITIALIZED
, "CoGetClassObject should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
724 ok(pUnk
== NULL
, "CoGetClassObject should have changed the passed in pointer to NULL, instead of %p\n", pUnk
);
726 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, NULL
);
727 ok(hr
== E_INVALIDARG
||
728 broken(hr
== CO_E_NOTINITIALIZED
), /* win9x */
729 "CoGetClassObject should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
731 /* show that COM doesn't have to be initialized for multi-threaded apartments if another
732 thread has already done so */
734 test_apt_type(APTTYPE_CURRENT
, APTTYPEQUALIFIER_NONE
, FALSE
, FALSE
);
736 info
.wait
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
737 ok(info
.wait
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
739 info
.stop
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
740 ok(info
.stop
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
742 thread
= CreateThread(NULL
, 0, ole_initialize_thread
, &info
, 0, &tid
);
743 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
745 ok( !WaitForSingleObject(info
.wait
, 10000), "wait timed out\n" );
747 test_apt_type(APTTYPE_MTA
, APTTYPEQUALIFIER_IMPLICIT_MTA
, TRUE
, TRUE
);
749 pUnk
= (IUnknown
*)0xdeadbeef;
750 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
751 if(hr
== REGDB_E_CLASSNOTREG
)
752 skip("IE not installed so can't test CoGetClassObject\n");
755 ok(hr
== S_OK
, "CoGetClassObject should have returned S_OK instead of 0x%08x\n", hr
);
756 if (pUnk
) IUnknown_Release(pUnk
);
760 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
762 GetExitCodeThread(thread
, &exitcode
);
764 ok(hr
== S_OK
, "thread should have returned S_OK instead of 0x%08x\n", hr
);
767 CloseHandle(info
.wait
);
768 CloseHandle(info
.stop
);
770 test_apt_type(APTTYPE_CURRENT
, APTTYPEQUALIFIER_NONE
, FALSE
, FALSE
);
772 if (!pRegOverridePredefKey
)
774 win_skip("RegOverridePredefKey not available\n");
778 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
780 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
783 IUnknown_Release(pUnk
);
785 res
= RegCreateKeyExA(HKEY_CURRENT_USER
, "Software\\Classes", 0, NULL
, 0,
786 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
);
787 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
789 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, hkey
);
790 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
792 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
793 ok(hr
== S_OK
, "CoGetClassObject should have returned S_OK instead of 0x%08x\n", hr
);
795 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, NULL
);
796 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
798 if (hr
== S_OK
) IUnknown_Release(pUnk
);
802 hr
= CoGetClassObject(&CLSID_InProcFreeMarshaler
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
803 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
804 IUnknown_Release(pUnk
);
806 /* context redefines FreeMarshaler CLSID */
807 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
809 hr
= CoGetClassObject(&CLSID_InProcFreeMarshaler
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
810 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
811 IUnknown_Release(pUnk
);
813 pDeactivateActCtx(0, cookie
);
814 pReleaseActCtx(handle
);
820 static void test_CoCreateInstanceEx(void)
822 MULTI_QI qi_res
= { &IID_IMoniker
};
828 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
829 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
830 ok_ole_success(hr
, "CoRegisterClassObject");
832 create_instance_iid
= IID_NULL
;
833 hr
= CoCreateInstanceEx(&CLSID_WineOOPTest
, NULL
, CLSCTX_INPROC_SERVER
, NULL
, 1, &qi_res
);
834 ok(hr
== E_NOINTERFACE
, "CoCreateInstanceEx failed: %08x\n", hr
);
835 ok(IsEqualGUID(&create_instance_iid
, qi_res
.pIID
), "Unexpected CreateInstance iid %s\n",
836 wine_dbgstr_guid(&create_instance_iid
));
838 hr
= CoRevokeClassObject(cookie
);
839 ok_ole_success(hr
, "CoRevokeClassObject");
844 static ATOM
register_dummy_class(void)
852 GetModuleHandleA(NULL
),
854 LoadCursorA(NULL
, (LPSTR
)IDC_ARROW
),
855 (HBRUSH
)(COLOR_BTNFACE
+1),
860 return RegisterClassA(&wc
);
863 static void test_ole_menu(void)
868 hwndFrame
= CreateWindowA((LPCSTR
)MAKEINTATOM(register_dummy_class()), "Test", 0, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, NULL
, NULL
, NULL
, NULL
);
869 hr
= OleSetMenuDescriptor(NULL
, hwndFrame
, NULL
, NULL
, NULL
);
870 todo_wine
ok_ole_success(hr
, "OleSetMenuDescriptor");
872 DestroyWindow(hwndFrame
);
876 static HRESULT WINAPI
MessageFilter_QueryInterface(IMessageFilter
*iface
, REFIID riid
, void ** ppvObj
)
878 if (ppvObj
== NULL
) return E_POINTER
;
880 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
881 IsEqualGUID(riid
, &IID_IClassFactory
))
884 IMessageFilter_AddRef(iface
);
888 return E_NOINTERFACE
;
891 static ULONG WINAPI
MessageFilter_AddRef(IMessageFilter
*iface
)
893 return 2; /* non-heap object */
896 static ULONG WINAPI
MessageFilter_Release(IMessageFilter
*iface
)
898 return 1; /* non-heap object */
901 static DWORD WINAPI
MessageFilter_HandleInComingCall(
902 IMessageFilter
*iface
,
904 HTASK threadIDCaller
,
906 LPINTERFACEINFO lpInterfaceInfo
)
908 trace("HandleInComingCall\n");
909 return SERVERCALL_ISHANDLED
;
912 static DWORD WINAPI
MessageFilter_RetryRejectedCall(
913 IMessageFilter
*iface
,
914 HTASK threadIDCallee
,
918 trace("RetryRejectedCall\n");
922 static DWORD WINAPI
MessageFilter_MessagePending(
923 IMessageFilter
*iface
,
924 HTASK threadIDCallee
,
928 trace("MessagePending\n");
929 return PENDINGMSG_WAITNOPROCESS
;
932 static const IMessageFilterVtbl MessageFilter_Vtbl
=
934 MessageFilter_QueryInterface
,
935 MessageFilter_AddRef
,
936 MessageFilter_Release
,
937 MessageFilter_HandleInComingCall
,
938 MessageFilter_RetryRejectedCall
,
939 MessageFilter_MessagePending
942 static IMessageFilter MessageFilter
= { &MessageFilter_Vtbl
};
944 static void test_CoRegisterMessageFilter(void)
947 IMessageFilter
*prev_filter
;
949 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
950 ok(hr
== CO_E_NOT_SUPPORTED
,
951 "CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08x\n",
954 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
955 prev_filter
= (IMessageFilter
*)0xdeadbeef;
956 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
957 ok(hr
== CO_E_NOT_SUPPORTED
,
958 "CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08x\n",
960 ok(prev_filter
== (IMessageFilter
*)0xdeadbeef,
961 "prev_filter should have been set to %p\n", prev_filter
);
964 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
966 hr
= CoRegisterMessageFilter(NULL
, NULL
);
967 ok_ole_success(hr
, "CoRegisterMessageFilter");
969 prev_filter
= (IMessageFilter
*)0xdeadbeef;
970 hr
= CoRegisterMessageFilter(NULL
, &prev_filter
);
971 ok_ole_success(hr
, "CoRegisterMessageFilter");
972 ok(prev_filter
== NULL
, "prev_filter should have been set to NULL instead of %p\n", prev_filter
);
974 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
975 ok_ole_success(hr
, "CoRegisterMessageFilter");
976 ok(prev_filter
== NULL
, "prev_filter should have been set to NULL instead of %p\n", prev_filter
);
978 hr
= CoRegisterMessageFilter(NULL
, NULL
);
979 ok_ole_success(hr
, "CoRegisterMessageFilter");
984 static IUnknown Test_Unknown
;
986 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
988 return IUnknown_QueryInterface(&Test_Unknown
, riid
, ppv
);
991 static ULONG WINAPI
EnumOLEVERB_AddRef(IEnumOLEVERB
*iface
)
996 static ULONG WINAPI
EnumOLEVERB_Release(IEnumOLEVERB
*iface
)
1001 static HRESULT WINAPI
EnumOLEVERB_Next(IEnumOLEVERB
*iface
, ULONG celt
, OLEVERB
*rgelt
, ULONG
*fetched
)
1003 ok(0, "unexpected call\n");
1007 static HRESULT WINAPI
EnumOLEVERB_Skip(IEnumOLEVERB
*iface
, ULONG celt
)
1009 ok(0, "unexpected call\n");
1013 static HRESULT WINAPI
EnumOLEVERB_Reset(IEnumOLEVERB
*iface
)
1015 ok(0, "unexpected call\n");
1019 static HRESULT WINAPI
EnumOLEVERB_Clone(IEnumOLEVERB
*iface
, IEnumOLEVERB
**ppenum
)
1021 ok(0, "unexpected call\n");
1025 static const IEnumOLEVERBVtbl EnumOLEVERBVtbl
= {
1026 EnumOLEVERB_QueryInterface
,
1028 EnumOLEVERB_Release
,
1035 static IEnumOLEVERB EnumOLEVERB
= { &EnumOLEVERBVtbl
};
1037 static HRESULT WINAPI
Test_IUnknown_QueryInterface(
1042 if (ppvObj
== NULL
) return E_POINTER
;
1044 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IWineTest
)) {
1046 }else if(IsEqualIID(riid
, &IID_IEnumOLEVERB
)) {
1047 *ppvObj
= &EnumOLEVERB
;
1050 return E_NOINTERFACE
;
1053 IUnknown_AddRef((IUnknown
*)*ppvObj
);
1057 static ULONG WINAPI
Test_IUnknown_AddRef(IUnknown
*iface
)
1059 return 2; /* non-heap-based object */
1062 static ULONG WINAPI
Test_IUnknown_Release(IUnknown
*iface
)
1064 return 1; /* non-heap-based object */
1067 static const IUnknownVtbl TestUnknown_Vtbl
=
1069 Test_IUnknown_QueryInterface
,
1070 Test_IUnknown_AddRef
,
1071 Test_IUnknown_Release
,
1074 static IUnknown Test_Unknown
= { &TestUnknown_Vtbl
};
1076 static IPSFactoryBuffer
*ps_factory_buffer
;
1078 static HRESULT WINAPI
PSFactoryBuffer_QueryInterface(
1079 IPSFactoryBuffer
* This
,
1080 /* [in] */ REFIID riid
,
1081 /* [iid_is][out] */ void **ppvObject
)
1083 if (IsEqualIID(riid
, &IID_IUnknown
) ||
1084 IsEqualIID(riid
, &IID_IPSFactoryBuffer
))
1087 IPSFactoryBuffer_AddRef(This
);
1090 return E_NOINTERFACE
;
1093 static ULONG WINAPI
PSFactoryBuffer_AddRef(
1094 IPSFactoryBuffer
* This
)
1099 static ULONG WINAPI
PSFactoryBuffer_Release(
1100 IPSFactoryBuffer
* This
)
1105 static HRESULT WINAPI
PSFactoryBuffer_CreateProxy(
1106 IPSFactoryBuffer
* This
,
1107 /* [in] */ IUnknown
*pUnkOuter
,
1108 /* [in] */ REFIID riid
,
1109 /* [out] */ IRpcProxyBuffer
**ppProxy
,
1110 /* [out] */ void **ppv
)
1115 static HRESULT WINAPI
PSFactoryBuffer_CreateStub(
1116 IPSFactoryBuffer
* This
,
1117 /* [in] */ REFIID riid
,
1118 /* [unique][in] */ IUnknown
*pUnkServer
,
1119 /* [out] */ IRpcStubBuffer
**ppStub
)
1121 CHECK_EXPECT(CreateStub
);
1123 ok(pUnkServer
== (IUnknown
*)&Test_Unknown
, "unexpected pUnkServer %p\n", pUnkServer
);
1124 if(!ps_factory_buffer
)
1127 return IPSFactoryBuffer_CreateStub(ps_factory_buffer
, &IID_IEnumOLEVERB
, pUnkServer
, ppStub
);
1130 static IPSFactoryBufferVtbl PSFactoryBufferVtbl
=
1132 PSFactoryBuffer_QueryInterface
,
1133 PSFactoryBuffer_AddRef
,
1134 PSFactoryBuffer_Release
,
1135 PSFactoryBuffer_CreateProxy
,
1136 PSFactoryBuffer_CreateStub
1139 static IPSFactoryBuffer PSFactoryBuffer
= { &PSFactoryBufferVtbl
};
1141 static const CLSID CLSID_WineTestPSFactoryBuffer
=
1146 {0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd}
1147 }; /* 52011640-8164-4fd0-a1a2-5d5a3654d3bd */
1149 static DWORD CALLBACK
register_ps_clsid_thread(void *context
)
1154 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1156 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1157 ok_ole_success(hr
, "CoGetPSClsid");
1158 ok(IsEqualGUID(&clsid
, &CLSID_WineTestPSFactoryBuffer
), "expected %s, got %s\n",
1159 wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer
), wine_dbgstr_guid(&clsid
));
1161 /* test registering a PSClsid in an apartment which is then destroyed */
1162 hr
= CoRegisterPSClsid(&IID_TestPS
, &clsid
);
1163 ok_ole_success(hr
, "CoRegisterPSClsid");
1170 static void test_CoRegisterPSClsid(void)
1173 DWORD dwRegistrationKey
;
1179 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
1180 ok(hr
== CO_E_NOTINITIALIZED
, "CoRegisterPSClsid should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
1182 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1184 hr
= CoRegisterClassObject(&CLSID_WineTestPSFactoryBuffer
, (IUnknown
*)&PSFactoryBuffer
,
1185 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &dwRegistrationKey
);
1186 ok_ole_success(hr
, "CoRegisterClassObject");
1188 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
1189 ok_ole_success(hr
, "CoRegisterPSClsid");
1191 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1192 ok_ole_success(hr
, "CoGetPSClsid");
1193 ok(IsEqualGUID(&clsid
, &CLSID_WineTestPSFactoryBuffer
), "expected %s, got %s\n",
1194 wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer
), wine_dbgstr_guid(&clsid
));
1196 thread
= CreateThread(NULL
, 0, register_ps_clsid_thread
, NULL
, 0, &tid
);
1197 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1198 ok(!WaitForSingleObject(thread
, 10000), "wait timed out\n");
1199 CloseHandle(thread
);
1201 hr
= CoGetPSClsid(&IID_TestPS
, &clsid
);
1202 ok_ole_success(hr
, "CoGetPSClsid");
1203 ok(IsEqualGUID(&clsid
, &CLSID_WineTestPSFactoryBuffer
), "expected %s, got %s\n",
1204 wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer
), wine_dbgstr_guid(&clsid
));
1206 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
1207 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1209 SET_EXPECT(CreateStub
);
1210 hr
= CoMarshalInterface(stream
, &IID_IWineTest
, &Test_Unknown
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1211 ok(hr
== E_NOTIMPL
, "CoMarshalInterface should have returned E_NOTIMPL instead of 0x%08x\n", hr
);
1212 CHECK_CALLED(CreateStub
);
1214 hr
= CoGetPSClsid(&IID_IEnumOLEVERB
, &clsid
);
1215 ok_ole_success(hr
, "CoGetPSClsid");
1217 hr
= CoGetClassObject(&clsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IPSFactoryBuffer
, (void **)&ps_factory_buffer
);
1218 ok_ole_success(hr
, "CoGetClassObject");
1220 hr
= CoRegisterPSClsid(&IID_IEnumOLEVERB
, &CLSID_WineTestPSFactoryBuffer
);
1221 ok_ole_success(hr
, "CoRegisterPSClsid");
1223 SET_EXPECT(CreateStub
);
1224 hr
= CoMarshalInterface(stream
, &IID_IEnumOLEVERB
, (IUnknown
*)&EnumOLEVERB
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1225 ok(hr
== S_OK
, "CoMarshalInterface should have returned S_OK instead of 0x%08x\n", hr
);
1226 CHECK_CALLED(CreateStub
);
1228 hr
= CoMarshalInterface(stream
, &IID_IEnumOLEVERB
, &Test_Unknown
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1229 ok(hr
== S_OK
, "CoMarshalInterface should have returned S_OK instead of 0x%08x\n", hr
);
1231 IStream_Release(stream
);
1232 IPSFactoryBuffer_Release(ps_factory_buffer
);
1233 ps_factory_buffer
= NULL
;
1235 hr
= CoRevokeClassObject(dwRegistrationKey
);
1236 ok_ole_success(hr
, "CoRevokeClassObject");
1240 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1242 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1243 ok(hr
== REGDB_E_IIDNOTREG
, "CoGetPSClsid should have returned REGDB_E_IIDNOTREG instead of 0x%08x\n", hr
);
1245 hr
= CoGetPSClsid(&IID_TestPS
, &clsid
);
1246 ok(hr
== REGDB_E_IIDNOTREG
, "CoGetPSClsid should have returned REGDB_E_IIDNOTREG instead of 0x%08x\n", hr
);
1250 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
1252 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
1253 ok_ole_success(hr
, "CoRegisterPSClsid");
1255 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1256 ok_ole_success(hr
, "CoGetPSClsid");
1257 ok(IsEqualGUID(&clsid
, &CLSID_WineTestPSFactoryBuffer
), "expected %s, got %s\n",
1258 wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer
), wine_dbgstr_guid(&clsid
));
1260 thread
= CreateThread(NULL
, 0, register_ps_clsid_thread
, NULL
, 0, &tid
);
1261 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1262 ok(!WaitForSingleObject(thread
, 10000), "wait timed out\n");
1263 CloseHandle(thread
);
1265 hr
= CoGetPSClsid(&IID_TestPS
, &clsid
);
1266 ok_ole_success(hr
, "CoGetPSClsid");
1267 ok(IsEqualGUID(&clsid
, &CLSID_WineTestPSFactoryBuffer
), "expected %s, got %s\n",
1268 wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer
), wine_dbgstr_guid(&clsid
));
1273 static void test_CoGetPSClsid(void)
1281 const BOOL is_win64
= (sizeof(void*) != sizeof(int));
1282 BOOL is_wow64
= FALSE
;
1284 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1285 ok(hr
== CO_E_NOTINITIALIZED
,
1286 "CoGetPSClsid should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n",
1289 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1291 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1292 ok_ole_success(hr
, "CoGetPSClsid");
1294 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1295 ok(hr
== REGDB_E_IIDNOTREG
,
1296 "CoGetPSClsid for random IID returned 0x%08x instead of REGDB_E_IIDNOTREG\n",
1299 hr
= CoGetPSClsid(&IID_IClassFactory
, NULL
);
1300 ok(hr
== E_INVALIDARG
,
1301 "CoGetPSClsid for null clsid returned 0x%08x instead of E_INVALIDARG\n",
1304 if (!pRegOverridePredefKey
)
1306 win_skip("RegOverridePredefKey not available\n");
1310 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1311 ok_ole_success(hr
, "CoGetPSClsid");
1313 res
= RegCreateKeyExA(HKEY_CURRENT_USER
, "Software\\Classes", 0, NULL
, 0,
1314 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
);
1315 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1317 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, hkey
);
1318 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
1320 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1321 ok_ole_success(hr
, "CoGetPSClsid");
1323 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, NULL
);
1324 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
1328 /* not registered CLSID */
1329 hr
= CoGetPSClsid(&IID_Testiface
, &clsid
);
1330 ok(hr
== REGDB_E_IIDNOTREG
, "got 0x%08x\n", hr
);
1332 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
1334 memset(&clsid
, 0, sizeof(clsid
));
1335 hr
= CoGetPSClsid(&IID_Testiface
, &clsid
);
1336 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1337 ok(IsEqualGUID(&clsid
, &IID_Testiface
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1339 memset(&clsid
, 0, sizeof(clsid
));
1340 hr
= CoGetPSClsid(&IID_Testiface2
, &clsid
);
1341 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1342 ok(IsEqualGUID(&clsid
, &IID_Testiface2
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1344 memset(&clsid
, 0, sizeof(clsid
));
1345 hr
= CoGetPSClsid(&IID_Testiface3
, &clsid
);
1346 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1347 ok(IsEqualGUID(&clsid
, &IID_TestPS
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1349 memset(&clsid
, 0xaa, sizeof(clsid
));
1350 hr
= CoGetPSClsid(&IID_Testiface4
, &clsid
);
1351 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1352 ok(IsEqualGUID(&clsid
, &GUID_NULL
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1354 /* register same interface and try to get CLSID back */
1355 hr
= CoRegisterPSClsid(&IID_Testiface
, &IID_Testiface4
);
1356 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1357 memset(&clsid
, 0, sizeof(clsid
));
1358 hr
= CoGetPSClsid(&IID_Testiface
, &clsid
);
1359 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1360 ok(IsEqualGUID(&clsid
, &IID_Testiface4
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1362 pDeactivateActCtx(0, cookie
);
1363 pReleaseActCtx(handle
);
1366 if (pRegDeleteKeyExA
&&
1368 (pIsWow64Process
&& pIsWow64Process(GetCurrentProcess(), &is_wow64
) && is_wow64
)))
1370 static GUID IID_DeadBeef
= {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
1371 static const char clsidDeadBeef
[] = "{deadbeef-dead-beef-dead-beefdeadbeef}";
1372 static const char clsidA
[] = "{66666666-8888-7777-6666-555555555555}";
1373 HKEY hkey_iface
, hkey_psclsid
;
1374 REGSAM opposite
= is_win64
? KEY_WOW64_32KEY
: KEY_WOW64_64KEY
;
1376 hr
= CoGetPSClsid(&IID_DeadBeef
, &clsid
);
1377 ok(hr
== REGDB_E_IIDNOTREG
, "got 0x%08x\n", hr
);
1379 res
= RegCreateKeyExA(HKEY_CLASSES_ROOT
, "Interface",
1380 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
, NULL
, &hkey_iface
, NULL
);
1381 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1382 res
= RegCreateKeyExA(hkey_iface
, clsidDeadBeef
,
1383 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
, NULL
, &hkey
, NULL
);
1384 if (res
== ERROR_ACCESS_DENIED
)
1386 win_skip("Failed to create a key, skipping some of CoGetPSClsid() tests\n");
1390 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1391 res
= RegCreateKeyExA(hkey
, "ProxyStubClsid32",
1392 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
, NULL
, &hkey_psclsid
, NULL
);
1393 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1394 res
= RegSetValueExA(hkey_psclsid
, NULL
, 0, REG_SZ
, (const BYTE
*)clsidA
, strlen(clsidA
)+1);
1395 ok(!res
, "RegSetValueEx returned %d\n", res
);
1396 RegCloseKey(hkey_psclsid
);
1398 hr
= CoGetPSClsid(&IID_DeadBeef
, &clsid
);
1399 ok_ole_success(hr
, "CoGetPSClsid");
1400 ok(IsEqualGUID(&clsid
, &IID_TestPS
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1402 res
= pRegDeleteKeyExA(hkey
, "ProxyStubClsid32", opposite
, 0);
1403 ok(!res
, "RegDeleteKeyEx returned %d\n", res
);
1405 res
= pRegDeleteKeyExA(hkey_iface
, clsidDeadBeef
, opposite
, 0);
1406 ok(!res
, "RegDeleteKeyEx returned %d\n", res
);
1409 RegCloseKey(hkey_iface
);
1415 /* basic test, mainly for invalid arguments. see marshal.c for more */
1416 static void test_CoUnmarshalInterface(void)
1422 hr
= CoUnmarshalInterface(NULL
, &IID_IUnknown
, (void **)&pProxy
);
1423 ok(hr
== E_INVALIDARG
, "CoUnmarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1425 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
1426 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1428 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, (void **)&pProxy
);
1430 ok(hr
== CO_E_NOTINITIALIZED
, "CoUnmarshalInterface should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
1432 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1434 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, (void **)&pProxy
);
1435 ok(hr
== STG_E_READFAULT
, "CoUnmarshalInterface should have returned STG_E_READFAULT instead of 0x%08x\n", hr
);
1439 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, NULL
);
1440 ok(hr
== E_INVALIDARG
, "CoUnmarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1442 IStream_Release(pStream
);
1445 static void test_CoGetInterfaceAndReleaseStream(void)
1450 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1452 hr
= CoGetInterfaceAndReleaseStream(NULL
, &IID_IUnknown
, (void**)&pUnk
);
1453 ok(hr
== E_INVALIDARG
, "hr %08x\n", hr
);
1458 /* basic test, mainly for invalid arguments. see marshal.c for more */
1459 static void test_CoMarshalInterface(void)
1463 static const LARGE_INTEGER llZero
;
1465 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1467 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
1468 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1470 hr
= CoMarshalInterface(pStream
, &IID_IUnknown
, NULL
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1471 ok(hr
== E_INVALIDARG
, "CoMarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1473 hr
= CoMarshalInterface(NULL
, &IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1474 ok(hr
== E_INVALIDARG
, "CoMarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1476 hr
= CoMarshalInterface(pStream
, &IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1477 ok_ole_success(hr
, "CoMarshalInterface");
1479 /* stream not rewound */
1480 hr
= CoReleaseMarshalData(pStream
);
1481 ok(hr
== STG_E_READFAULT
, "CoReleaseMarshalData should have returned STG_E_READFAULT instead of 0x%08x\n", hr
);
1483 hr
= IStream_Seek(pStream
, llZero
, STREAM_SEEK_SET
, NULL
);
1484 ok_ole_success(hr
, "IStream_Seek");
1486 hr
= CoReleaseMarshalData(pStream
);
1487 ok_ole_success(hr
, "CoReleaseMarshalData");
1489 IStream_Release(pStream
);
1494 static void test_CoMarshalInterThreadInterfaceInStream(void)
1498 IClassFactory
*pProxy
;
1500 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1504 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, NULL
);
1505 ok(hr
== E_INVALIDARG
, "CoMarshalInterThreadInterfaceInStream should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1507 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, NULL
, &pStream
);
1508 ok(hr
== E_INVALIDARG
, "CoMarshalInterThreadInterfaceInStream should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1512 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, &pStream
);
1513 ok_ole_success(hr
, "CoMarshalInterThreadInterfaceInStream");
1515 ok_more_than_one_lock();
1517 hr
= CoUnmarshalInterface(pStream
, &IID_IClassFactory
, (void **)&pProxy
);
1518 ok_ole_success(hr
, "CoUnmarshalInterface");
1520 IClassFactory_Release(pProxy
);
1521 IStream_Release(pStream
);
1528 static void test_CoRegisterClassObject(void)
1530 ULONG_PTR ctxcookie
;
1536 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1538 /* CLSCTX_INPROC_SERVER */
1539 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1540 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1541 ok_ole_success(hr
, "CoRegisterClassObject");
1542 hr
= CoRevokeClassObject(cookie
);
1543 ok_ole_success(hr
, "CoRevokeClassObject");
1545 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1546 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
1547 ok_ole_success(hr
, "CoRegisterClassObject");
1548 hr
= CoRevokeClassObject(cookie
);
1549 ok_ole_success(hr
, "CoRevokeClassObject");
1551 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1552 CLSCTX_INPROC_SERVER
, REGCLS_MULTI_SEPARATE
, &cookie
);
1553 ok_ole_success(hr
, "CoRegisterClassObject");
1554 hr
= CoRevokeClassObject(cookie
);
1555 ok_ole_success(hr
, "CoRevokeClassObject");
1557 /* CLSCTX_LOCAL_SERVER */
1558 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1559 CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1560 ok_ole_success(hr
, "CoRegisterClassObject");
1561 hr
= CoRevokeClassObject(cookie
);
1562 ok_ole_success(hr
, "CoRevokeClassObject");
1564 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1565 CLSCTX_LOCAL_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
1566 ok_ole_success(hr
, "CoRegisterClassObject");
1567 hr
= CoRevokeClassObject(cookie
);
1568 ok_ole_success(hr
, "CoRevokeClassObject");
1570 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1571 CLSCTX_LOCAL_SERVER
, REGCLS_MULTI_SEPARATE
, &cookie
);
1572 ok_ole_success(hr
, "CoRegisterClassObject");
1573 hr
= CoRevokeClassObject(cookie
);
1574 ok_ole_success(hr
, "CoRevokeClassObject");
1576 /* CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER */
1577 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1578 CLSCTX_INPROC_SERVER
|CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1579 ok_ole_success(hr
, "CoRegisterClassObject");
1580 hr
= CoRevokeClassObject(cookie
);
1581 ok_ole_success(hr
, "CoRevokeClassObject");
1583 /* test whether an object that doesn't support IClassFactory can be
1584 * registered for CLSCTX_LOCAL_SERVER */
1585 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, &Test_Unknown
,
1586 CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1587 ok_ole_success(hr
, "CoRegisterClassObject");
1588 hr
= CoRevokeClassObject(cookie
);
1589 ok_ole_success(hr
, "CoRevokeClassObject");
1591 /* test whether registered class becomes invalid when apartment is destroyed */
1592 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1593 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1594 ok_ole_success(hr
, "CoRegisterClassObject");
1597 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1599 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
,
1600 &IID_IClassFactory
, (void **)&pcf
);
1601 ok(hr
== REGDB_E_CLASSNOTREG
, "object registered in an apartment shouldn't accessible after it is destroyed\n");
1603 /* crashes with at least win9x DCOM! */
1605 CoRevokeClassObject(cookie
);
1607 /* test that object is accessible */
1608 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
, CLSCTX_INPROC_SERVER
,
1609 REGCLS_MULTIPLEUSE
, &cookie
);
1610 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1612 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&pcf
);
1613 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1614 IClassFactory_Release(pcf
);
1616 /* context now contains CLSID_WineOOPTest, test if registered one could still be used */
1617 if ((handle
= activate_context(actctx_manifest
, &ctxcookie
)))
1619 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&pcf
);
1621 ok(hr
== HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND
), "got 0x%08x\n", hr
);
1623 pDeactivateActCtx(0, ctxcookie
);
1624 pReleaseActCtx(handle
);
1627 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&pcf
);
1628 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1629 IClassFactory_Release(pcf
);
1631 hr
= CoRevokeClassObject(cookie
);
1632 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1637 static HRESULT
get_class_object(CLSCTX clsctx
)
1642 hr
= CoGetClassObject(&CLSID_WineOOPTest
, clsctx
, NULL
, &IID_IClassFactory
,
1646 IClassFactory_Release(pcf
);
1651 static DWORD CALLBACK
get_class_object_thread(LPVOID pv
)
1653 CLSCTX clsctx
= (CLSCTX
)(DWORD_PTR
)pv
;
1656 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1658 hr
= get_class_object(clsctx
);
1665 static DWORD CALLBACK
get_class_object_proxy_thread(LPVOID pv
)
1667 CLSCTX clsctx
= (CLSCTX
)(DWORD_PTR
)pv
;
1672 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1674 hr
= CoGetClassObject(&CLSID_WineOOPTest
, clsctx
, NULL
, &IID_IClassFactory
,
1679 hr
= IClassFactory_QueryInterface(pcf
, &IID_IMultiQI
, (void **)&pMQI
);
1681 IMultiQI_Release(pMQI
);
1682 IClassFactory_Release(pcf
);
1690 static DWORD CALLBACK
register_class_object_thread(LPVOID pv
)
1695 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1697 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1698 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1705 static DWORD CALLBACK
revoke_class_object_thread(LPVOID pv
)
1707 DWORD cookie
= (DWORD_PTR
)pv
;
1710 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1712 hr
= CoRevokeClassObject(cookie
);
1719 static void test_registered_object_thread_affinity(void)
1727 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1729 /* CLSCTX_INPROC_SERVER */
1731 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1732 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1733 ok_ole_success(hr
, "CoRegisterClassObject");
1735 thread
= CreateThread(NULL
, 0, get_class_object_thread
, (LPVOID
)CLSCTX_INPROC_SERVER
, 0, &tid
);
1736 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1737 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1738 GetExitCodeThread(thread
, &exitcode
);
1740 ok(hr
== REGDB_E_CLASSNOTREG
, "CoGetClassObject on inproc object "
1741 "registered in different thread should return REGDB_E_CLASSNOTREG "
1742 "instead of 0x%08x\n", hr
);
1744 hr
= get_class_object(CLSCTX_INPROC_SERVER
);
1745 ok(hr
== S_OK
, "CoGetClassObject on inproc object registered in same "
1746 "thread should return S_OK instead of 0x%08x\n", hr
);
1748 thread
= CreateThread(NULL
, 0, register_class_object_thread
, NULL
, 0, &tid
);
1749 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1750 ok ( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1751 GetExitCodeThread(thread
, &exitcode
);
1753 ok(hr
== S_OK
, "CoRegisterClassObject with same CLSID but in different thread should return S_OK instead of 0x%08x\n", hr
);
1755 hr
= CoRevokeClassObject(cookie
);
1756 ok_ole_success(hr
, "CoRevokeClassObject");
1758 /* CLSCTX_LOCAL_SERVER */
1760 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1761 CLSCTX_LOCAL_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
1762 ok_ole_success(hr
, "CoRegisterClassObject");
1764 thread
= CreateThread(NULL
, 0, get_class_object_proxy_thread
, (LPVOID
)CLSCTX_LOCAL_SERVER
, 0, &tid
);
1765 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1766 while (MsgWaitForMultipleObjects(1, &thread
, FALSE
, 10000, QS_ALLINPUT
) == WAIT_OBJECT_0
+ 1)
1769 while (PeekMessageA(&msg
, NULL
, 0, 0, PM_REMOVE
))
1771 TranslateMessage(&msg
);
1772 DispatchMessageA(&msg
);
1775 GetExitCodeThread(thread
, &exitcode
);
1777 ok(hr
== S_OK
, "CoGetClassObject on local server object "
1778 "registered in different thread should return S_OK "
1779 "instead of 0x%08x\n", hr
);
1781 hr
= get_class_object(CLSCTX_LOCAL_SERVER
);
1782 ok(hr
== S_OK
, "CoGetClassObject on local server object registered in same "
1783 "thread should return S_OK instead of 0x%08x\n", hr
);
1785 thread
= CreateThread(NULL
, 0, revoke_class_object_thread
, (LPVOID
)(DWORD_PTR
)cookie
, 0, &tid
);
1786 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1787 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1788 GetExitCodeThread(thread
, &exitcode
);
1790 ok(hr
== RPC_E_WRONG_THREAD
|| broken(hr
== S_OK
) /* win8 */, "CoRevokeClassObject called from different "
1791 "thread to where registered should return RPC_E_WRONG_THREAD instead of 0x%08x\n", hr
);
1793 thread
= CreateThread(NULL
, 0, register_class_object_thread
, NULL
, 0, &tid
);
1794 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1795 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1796 GetExitCodeThread(thread
, &exitcode
);
1798 ok(hr
== S_OK
, "CoRegisterClassObject with same CLSID but in different "
1799 "thread should return S_OK instead of 0x%08x\n", hr
);
1801 hr
= CoRevokeClassObject(cookie
);
1802 ok_ole_success(hr
, "CoRevokeClassObject");
1807 static DWORD CALLBACK
free_libraries_thread(LPVOID p
)
1809 CoFreeUnusedLibraries();
1813 static inline BOOL
is_module_loaded(const char *module
)
1815 return GetModuleHandleA(module
) != 0;
1818 static void test_CoFreeUnusedLibraries(void)
1825 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1827 ok(!is_module_loaded("urlmon.dll"), "urlmon.dll shouldn't be loaded\n");
1829 hr
= CoCreateInstance(&CLSID_FileProtocol
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IInternetProtocol
, (void **)&pUnk
);
1830 if (hr
== REGDB_E_CLASSNOTREG
)
1832 skip("IE not installed so can't run CoFreeUnusedLibraries test\n");
1836 ok_ole_success(hr
, "CoCreateInstance");
1838 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1841 broken(pUnk
== NULL
), /* win9x */
1842 "Expected a valid pointer\n");
1844 IUnknown_Release(pUnk
);
1846 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1848 thread
= CreateThread(NULL
, 0, free_libraries_thread
, NULL
, 0, &tid
);
1849 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1850 CloseHandle(thread
);
1852 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1854 CoFreeUnusedLibraries();
1856 ok(!is_module_loaded("urlmon.dll"), "urlmon.dll shouldn't be loaded\n");
1861 static void test_CoGetObjectContext(void)
1865 IComThreadingInfo
*pComThreadingInfo
, *threadinginfo2
;
1866 IContextCallback
*pContextCallback
;
1867 IObjContext
*pObjContext
;
1872 DWORD tid
, exitcode
;
1875 if (!pCoGetObjectContext
)
1877 win_skip("CoGetObjectContext not present\n");
1881 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1882 ok(hr
== CO_E_NOTINITIALIZED
, "CoGetObjectContext should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
1883 ok(pComThreadingInfo
== NULL
, "pComThreadingInfo should have been set to NULL\n");
1885 /* show that COM doesn't have to be initialized for multi-threaded apartments if another
1886 thread has already done so */
1888 test_apt_type(APTTYPE_CURRENT
, APTTYPEQUALIFIER_NONE
, FALSE
, FALSE
);
1890 info
.wait
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
1891 ok(info
.wait
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
1893 info
.stop
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
1894 ok(info
.stop
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
1896 thread
= CreateThread(NULL
, 0, ole_initialize_thread
, &info
, 0, &tid
);
1897 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1899 ok( !WaitForSingleObject(info
.wait
, 10000), "wait timed out\n" );
1901 test_apt_type(APTTYPE_MTA
, APTTYPEQUALIFIER_IMPLICIT_MTA
, TRUE
, TRUE
);
1903 pComThreadingInfo
= NULL
;
1904 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1905 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
1907 threadinginfo2
= NULL
;
1908 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&threadinginfo2
);
1909 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
1910 ok(pComThreadingInfo
== threadinginfo2
, "got different instance\n");
1911 IComThreadingInfo_Release(threadinginfo2
);
1913 hr
= IComThreadingInfo_GetCurrentLogicalThreadId(pComThreadingInfo
, NULL
);
1914 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1916 id
= id2
= GUID_NULL
;
1917 hr
= IComThreadingInfo_GetCurrentLogicalThreadId(pComThreadingInfo
, &id
);
1918 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1920 hr
= CoGetCurrentLogicalThreadId(&id2
);
1921 ok(IsEqualGUID(&id
, &id2
), "got %s, expected %s\n", wine_dbgstr_guid(&id
), wine_dbgstr_guid(&id2
));
1923 IComThreadingInfo_Release(pComThreadingInfo
);
1925 SetEvent(info
.stop
);
1926 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1928 GetExitCodeThread(thread
, &exitcode
);
1930 ok(hr
== S_OK
, "thread should have returned S_OK instead of 0x%08x\n", hr
);
1932 CloseHandle(thread
);
1933 CloseHandle(info
.wait
);
1934 CloseHandle(info
.stop
);
1936 test_apt_type(APTTYPE_CURRENT
, APTTYPEQUALIFIER_NONE
, FALSE
, FALSE
);
1938 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1940 test_apt_type(APTTYPE_MAINSTA
, APTTYPEQUALIFIER_NONE
, FALSE
, FALSE
);
1942 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1943 ok_ole_success(hr
, "CoGetObjectContext");
1945 hr
= IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo
, &apttype
);
1946 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentApartmentType");
1947 ok(apttype
== APTTYPE_MAINSTA
, "apartment type should be APTTYPE_MAINSTA instead of %d\n", apttype
);
1949 hr
= IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo
, &thdtype
);
1950 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentThreadType");
1951 ok(thdtype
== THDTYPE_PROCESSMESSAGES
, "thread type should be THDTYPE_PROCESSMESSAGES instead of %d\n", thdtype
);
1953 refs
= IComThreadingInfo_Release(pComThreadingInfo
);
1954 ok(refs
== 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs
);
1956 hr
= pCoGetObjectContext(&IID_IContextCallback
, (void **)&pContextCallback
);
1957 ok_ole_success(hr
, "CoGetObjectContext(ContextCallback)");
1959 refs
= IContextCallback_Release(pContextCallback
);
1960 ok(refs
== 0, "pContextCallback should have 0 refs instead of %d refs\n", refs
);
1964 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
1966 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1967 ok_ole_success(hr
, "CoGetObjectContext");
1969 hr
= IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo
, &apttype
);
1970 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentApartmentType");
1971 ok(apttype
== APTTYPE_MTA
, "apartment type should be APTTYPE_MTA instead of %d\n", apttype
);
1973 hr
= IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo
, &thdtype
);
1974 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentThreadType");
1975 ok(thdtype
== THDTYPE_BLOCKMESSAGES
, "thread type should be THDTYPE_BLOCKMESSAGES instead of %d\n", thdtype
);
1977 refs
= IComThreadingInfo_Release(pComThreadingInfo
);
1978 ok(refs
== 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs
);
1980 hr
= pCoGetObjectContext(&IID_IContextCallback
, (void **)&pContextCallback
);
1981 ok_ole_success(hr
, "CoGetObjectContext(ContextCallback)");
1983 refs
= IContextCallback_Release(pContextCallback
);
1984 ok(refs
== 0, "pContextCallback should have 0 refs instead of %d refs\n", refs
);
1986 hr
= pCoGetObjectContext(&IID_IObjContext
, (void **)&pObjContext
);
1987 ok_ole_success(hr
, "CoGetObjectContext");
1989 refs
= IObjContext_Release(pObjContext
);
1990 ok(refs
== 0, "pObjContext should have 0 refs instead of %d refs\n", refs
);
1996 IUnknown IUnknown_iface
;
2000 static inline Test_CallContext
*impl_from_IUnknown(IUnknown
*iface
)
2002 return CONTAINING_RECORD(iface
, Test_CallContext
, IUnknown_iface
);
2005 static HRESULT WINAPI
Test_CallContext_QueryInterface(
2010 if (ppvObj
== NULL
) return E_POINTER
;
2012 if (IsEqualGUID(riid
, &IID_IUnknown
))
2015 IUnknown_AddRef(iface
);
2020 return E_NOINTERFACE
;
2023 static ULONG WINAPI
Test_CallContext_AddRef(IUnknown
*iface
)
2025 Test_CallContext
*This
= impl_from_IUnknown(iface
);
2026 return InterlockedIncrement(&This
->refs
);
2029 static ULONG WINAPI
Test_CallContext_Release(IUnknown
*iface
)
2031 Test_CallContext
*This
= impl_from_IUnknown(iface
);
2032 ULONG refs
= InterlockedDecrement(&This
->refs
);
2034 HeapFree(GetProcessHeap(), 0, This
);
2038 static const IUnknownVtbl TestCallContext_Vtbl
=
2040 Test_CallContext_QueryInterface
,
2041 Test_CallContext_AddRef
,
2042 Test_CallContext_Release
2045 static void test_CoGetCallContext(void)
2050 Test_CallContext
*test_object
;
2052 if (!pCoSwitchCallContext
)
2054 skip("CoSwitchCallContext not present\n");
2060 test_object
= HeapAlloc(GetProcessHeap(), 0, sizeof(Test_CallContext
));
2061 test_object
->IUnknown_iface
.lpVtbl
= &TestCallContext_Vtbl
;
2062 test_object
->refs
= 1;
2064 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
2065 ok(hr
== RPC_E_CALL_COMPLETE
, "Expected RPC_E_CALL_COMPLETE, got 0x%08x\n", hr
);
2067 pUnk
= (IUnknown
*)0xdeadbeef;
2068 hr
= pCoSwitchCallContext(&test_object
->IUnknown_iface
, &pUnk
);
2069 ok_ole_success(hr
, "CoSwitchCallContext");
2070 ok(pUnk
== NULL
, "expected NULL, got %p\n", pUnk
);
2071 refs
= IUnknown_AddRef(&test_object
->IUnknown_iface
);
2072 ok(refs
== 2, "Expected refcount 2, got %d\n", refs
);
2073 IUnknown_Release(&test_object
->IUnknown_iface
);
2075 pUnk
= (IUnknown
*)0xdeadbeef;
2076 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
2077 ok_ole_success(hr
, "CoGetCallContext");
2078 ok(pUnk
== &test_object
->IUnknown_iface
, "expected %p, got %p\n",
2079 &test_object
->IUnknown_iface
, pUnk
);
2080 refs
= IUnknown_AddRef(&test_object
->IUnknown_iface
);
2081 ok(refs
== 3, "Expected refcount 3, got %d\n", refs
);
2082 IUnknown_Release(&test_object
->IUnknown_iface
);
2083 IUnknown_Release(pUnk
);
2085 pUnk
= (IUnknown
*)0xdeadbeef;
2086 hr
= pCoSwitchCallContext(NULL
, &pUnk
);
2087 ok_ole_success(hr
, "CoSwitchCallContext");
2088 ok(pUnk
== &test_object
->IUnknown_iface
, "expected %p, got %p\n",
2089 &test_object
->IUnknown_iface
, pUnk
);
2090 refs
= IUnknown_AddRef(&test_object
->IUnknown_iface
);
2091 ok(refs
== 2, "Expected refcount 2, got %d\n", refs
);
2092 IUnknown_Release(&test_object
->IUnknown_iface
);
2094 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
2095 ok(hr
== RPC_E_CALL_COMPLETE
, "Expected RPC_E_CALL_COMPLETE, got 0x%08x\n", hr
);
2097 IUnknown_Release(&test_object
->IUnknown_iface
);
2102 static void test_CoGetContextToken(void)
2106 ULONG_PTR token
, token2
;
2110 DWORD tid
, exitcode
;
2112 if (!pCoGetContextToken
)
2114 win_skip("CoGetContextToken not present\n");
2119 hr
= pCoGetContextToken(&token
);
2120 ok(hr
== CO_E_NOTINITIALIZED
, "Expected CO_E_NOTINITIALIZED, got 0x%08x\n", hr
);
2121 ok(token
== 0xdeadbeef, "Expected 0, got 0x%lx\n", token
);
2123 /* show that COM doesn't have to be initialized for multi-threaded apartments if another
2124 thread has already done so */
2126 test_apt_type(APTTYPE_CURRENT
, APTTYPEQUALIFIER_NONE
, FALSE
, FALSE
);
2128 info
.wait
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
2129 ok(info
.wait
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
2131 info
.stop
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
2132 ok(info
.stop
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
2134 thread
= CreateThread(NULL
, 0, ole_initialize_thread
, &info
, 0, &tid
);
2135 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
2137 ok( !WaitForSingleObject(info
.wait
, 10000), "wait timed out\n" );
2139 test_apt_type(APTTYPE_MTA
, APTTYPEQUALIFIER_IMPLICIT_MTA
, TRUE
, TRUE
);
2142 hr
= pCoGetContextToken(&token
);
2143 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2146 hr
= pCoGetContextToken(&token2
);
2147 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2148 ok(token
== token2
, "got different token\n");
2150 SetEvent(info
.stop
);
2151 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
2153 GetExitCodeThread(thread
, &exitcode
);
2155 ok(hr
== S_OK
, "thread should have returned S_OK instead of 0x%08x\n", hr
);
2157 CloseHandle(thread
);
2158 CloseHandle(info
.wait
);
2159 CloseHandle(info
.stop
);
2161 test_apt_type(APTTYPE_CURRENT
, APTTYPEQUALIFIER_NONE
, FALSE
, FALSE
);
2165 test_apt_type(APTTYPE_MAINSTA
, APTTYPEQUALIFIER_NONE
, FALSE
, FALSE
);
2167 hr
= pCoGetContextToken(NULL
);
2168 ok(hr
== E_POINTER
, "Expected E_POINTER, got 0x%08x\n", hr
);
2171 hr
= pCoGetContextToken(&token
);
2172 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2173 ok(token
, "Expected token != 0\n");
2176 hr
= pCoGetContextToken(&token2
);
2177 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2178 ok(token2
== token
, "got different token\n");
2180 refs
= IUnknown_AddRef((IUnknown
*)token
);
2181 ok(refs
== 1, "Expected 1, got %u\n", refs
);
2183 hr
= pCoGetObjectContext(&IID_IObjContext
, (void **)&ctx
);
2184 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2185 ok(ctx
== (IObjContext
*)token
, "Expected interface pointers to be the same\n");
2187 refs
= IObjContext_AddRef(ctx
);
2188 ok(refs
== 3, "Expected 3, got %u\n", refs
);
2190 refs
= IObjContext_Release(ctx
);
2191 ok(refs
== 2, "Expected 2, got %u\n", refs
);
2193 refs
= IUnknown_Release((IUnknown
*)token
);
2194 ok(refs
== 1, "Expected 1, got %u\n", refs
);
2196 /* CoGetContextToken does not add a reference */
2198 hr
= pCoGetContextToken(&token
);
2199 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2200 ok(token
, "Expected token != 0\n");
2201 ok(ctx
== (IObjContext
*)token
, "Expected interface pointers to be the same\n");
2203 refs
= IObjContext_AddRef(ctx
);
2204 ok(refs
== 2, "Expected 1, got %u\n", refs
);
2206 refs
= IObjContext_Release(ctx
);
2207 ok(refs
== 1, "Expected 0, got %u\n", refs
);
2209 refs
= IObjContext_Release(ctx
);
2210 ok(refs
== 0, "Expected 0, got %u\n", refs
);
2215 static void test_TreatAsClass(void)
2219 static GUID deadbeef
= {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
2220 static const char deadbeefA
[] = "{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}";
2221 IInternetProtocol
*pIP
= NULL
;
2222 HKEY clsidkey
, deadbeefkey
;
2225 if (!pCoGetTreatAsClass
)
2227 win_skip("CoGetTreatAsClass not present\n");
2231 hr
= pCoGetTreatAsClass(&deadbeef
,&out
);
2232 ok (hr
== S_FALSE
, "expected S_FALSE got %x\n",hr
);
2233 ok (IsEqualGUID(&out
,&deadbeef
), "expected to get same clsid back\n");
2235 hr
= pCoGetTreatAsClass(NULL
, &out
);
2236 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG got %08x\n", hr
);
2237 ok(IsEqualGUID(&out
, &deadbeef
), "expected no change to the clsid\n");
2239 hr
= pCoGetTreatAsClass(&deadbeef
, NULL
);
2240 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG got %08x\n", hr
);
2242 lr
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "CLSID", 0, KEY_READ
, &clsidkey
);
2243 ok(!lr
, "Couldn't open CLSID key, error %d\n", lr
);
2245 lr
= RegCreateKeyExA(clsidkey
, deadbeefA
, 0, NULL
, 0, KEY_WRITE
, NULL
, &deadbeefkey
, NULL
);
2247 win_skip("CoGetTreatAsClass() tests will be skipped (failed to create a test key, error %d)\n", lr
);
2248 RegCloseKey(clsidkey
);
2252 hr
= pCoTreatAsClass(&deadbeef
, &deadbeef
);
2253 ok(hr
== REGDB_E_WRITEREGDB
, "CoTreatAsClass gave wrong error: %08x\n", hr
);
2255 hr
= pCoTreatAsClass(&deadbeef
, &CLSID_FileProtocol
);
2256 if(hr
== REGDB_E_WRITEREGDB
){
2257 win_skip("Insufficient privileges to use CoTreatAsClass\n");
2260 ok(hr
== S_OK
, "CoTreatAsClass failed: %08x\n", hr
);
2262 hr
= pCoGetTreatAsClass(&deadbeef
, &out
);
2263 ok(hr
== S_OK
, "CoGetTreatAsClass failed: %08x\n",hr
);
2264 ok(IsEqualGUID(&out
, &CLSID_FileProtocol
), "expected to get substituted clsid\n");
2266 OleInitialize(NULL
);
2268 hr
= CoCreateInstance(&deadbeef
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IInternetProtocol
, (void **)&pIP
);
2269 if(hr
== REGDB_E_CLASSNOTREG
)
2271 win_skip("IE not installed so can't test CoCreateInstance\n");
2275 ok(hr
== S_OK
, "CoCreateInstance failed: %08x\n", hr
);
2277 IInternetProtocol_Release(pIP
);
2281 hr
= pCoTreatAsClass(&deadbeef
, &CLSID_NULL
);
2282 ok(hr
== S_OK
, "CoTreatAsClass failed: %08x\n", hr
);
2284 hr
= pCoGetTreatAsClass(&deadbeef
, &out
);
2285 ok(hr
== S_FALSE
, "expected S_FALSE got %08x\n", hr
);
2286 ok(IsEqualGUID(&out
, &deadbeef
), "expected to get same clsid back\n");
2288 /* bizarrely, native's CoTreatAsClass takes some time to take effect in CoCreateInstance */
2291 hr
= CoCreateInstance(&deadbeef
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IInternetProtocol
, (void **)&pIP
);
2292 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance gave wrong error: %08x\n", hr
);
2295 IInternetProtocol_Release(pIP
);
2299 RegCloseKey(deadbeefkey
);
2300 RegDeleteKeyA(clsidkey
, deadbeefA
);
2301 RegCloseKey(clsidkey
);
2304 static void test_CoInitializeEx(void)
2308 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2309 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2311 /* Calling OleInitialize for the first time should yield S_OK even with
2312 * apartment already initialized by previous CoInitialize(Ex) calls. */
2313 hr
= OleInitialize(NULL
);
2314 ok(hr
== S_OK
, "OleInitialize failed with error 0x%08x\n", hr
);
2316 /* Subsequent calls to OleInitialize should return S_FALSE */
2317 hr
= OleInitialize(NULL
);
2318 ok(hr
== S_FALSE
, "Expected S_FALSE, hr = 0x%08x\n", hr
);
2326 static void test_OleInitialize_InitCounting(void)
2330 REFCLSID rclsid
= &CLSID_InternetZoneManager
;
2332 /* 1. OleInitialize fails but OleUninitialize is still called: apartment stays initialized */
2333 hr
= pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
2334 ok(hr
== S_OK
, "CoInitializeEx(COINIT_MULTITHREADED) failed with error 0x%08x\n", hr
);
2336 hr
= OleInitialize(NULL
);
2337 ok(hr
== RPC_E_CHANGED_MODE
, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", RPC_E_CHANGED_MODE
, hr
);
2340 pUnk
= (IUnknown
*)0xdeadbeef;
2341 hr
= CoCreateInstance(rclsid
, NULL
, 0x17, &IID_IUnknown
, (void **)&pUnk
);
2342 ok(hr
== S_OK
, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", S_OK
, hr
);
2343 if (pUnk
) IUnknown_Release(pUnk
);
2347 /* 2. Extra multiple OleUninitialize: apartment stays initialized until CoUninitialize */
2348 hr
= CoInitialize(NULL
);
2349 ok(hr
== S_OK
, "CoInitialize() failed with error 0x%08x\n", hr
);
2351 hr
= OleInitialize(NULL
);
2352 ok(hr
== S_OK
, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", S_OK
, hr
);
2357 pUnk
= (IUnknown
*)0xdeadbeef;
2358 hr
= CoCreateInstance(rclsid
, NULL
, 0x17, &IID_IUnknown
, (void **)&pUnk
);
2359 ok(hr
== S_OK
, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", S_OK
, hr
);
2360 if (pUnk
) IUnknown_Release(pUnk
);
2364 pUnk
= (IUnknown
*)0xdeadbeef;
2365 hr
= CoCreateInstance(rclsid
, NULL
, 0x17, &IID_IUnknown
, (void **)&pUnk
);
2366 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", CO_E_NOTINITIALIZED
, hr
);
2367 if (pUnk
) IUnknown_Release(pUnk
);
2369 /* 3. CoUninitialize does not formally deinit Ole */
2370 hr
= CoInitialize(NULL
);
2371 ok(hr
== S_OK
, "CoInitialize() failed with error 0x%08x\n", hr
);
2373 hr
= OleInitialize(NULL
);
2374 ok(hr
== S_OK
, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", S_OK
, hr
);
2379 pUnk
= (IUnknown
*)0xdeadbeef;
2380 hr
= CoCreateInstance(rclsid
, NULL
, 0x17, &IID_IUnknown
, (void **)&pUnk
);
2381 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", CO_E_NOTINITIALIZED
, hr
);
2382 /* COM is not initialized anymore */
2383 if (pUnk
) IUnknown_Release(pUnk
);
2385 hr
= OleInitialize(NULL
);
2386 ok(hr
== S_FALSE
, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", S_FALSE
, hr
);
2387 /* ... but native OleInit returns S_FALSE as if Ole is considered initialized */
2393 static void test_OleRegGetMiscStatus(void)
2400 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_ICON
, NULL
);
2401 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2403 status
= 0xdeadbeef;
2404 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_ICON
, &status
);
2405 ok(hr
== REGDB_E_CLASSNOTREG
, "got 0x%08x\n", hr
);
2406 ok(status
== 0, "got 0x%08x\n", status
);
2409 hr
= OleRegGetMiscStatus(&CLSID_StdFont
, DVASPECT_ICON
, &status
);
2410 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2411 ok(status
== 0, "got 0x%08x\n", status
);
2413 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
2416 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_ICON
, &status
);
2417 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2418 ok(status
== OLEMISC_RECOMPOSEONRESIZE
, "got 0x%08x\n", status
);
2420 /* context data takes precedence over registration info */
2422 hr
= OleRegGetMiscStatus(&CLSID_StdFont
, DVASPECT_ICON
, &status
);
2423 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2424 ok(status
== OLEMISC_RECOMPOSEONRESIZE
, "got 0x%08x\n", status
);
2426 /* there's no such attribute in context */
2428 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_DOCPRINT
, &status
);
2429 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2430 ok(status
== 0, "got 0x%08x\n", status
);
2432 pDeactivateActCtx(0, cookie
);
2433 pReleaseActCtx(handle
);
2437 static void test_OleRegGetUserType(void)
2439 static const WCHAR stdfont_usertypeW
[] = {'S','t','a','n','d','a','r','d',' ','F','o','n','t',0};
2440 static const WCHAR stdfont2_usertypeW
[] = {'C','L','S','I','D','_','S','t','d','F','o','n','t',0};
2441 static const WCHAR clsidkeyW
[] = {'C','L','S','I','D',0};
2442 static const WCHAR defvalueW
[] = {'D','e','f','a','u','l','t',' ','N','a','m','e',0};
2443 static const WCHAR auxvalue0W
[] = {'A','u','x',' ','N','a','m','e',' ','0',0};
2444 static const WCHAR auxvalue2W
[] = {'A','u','x',' ','N','a','m','e',' ','2',0};
2445 static const WCHAR auxvalue3W
[] = {'A','u','x',' ','N','a','m','e',' ','3',0};
2446 static const WCHAR auxvalue4W
[] = {'A','u','x',' ','N','a','m','e',' ','4',0};
2448 static const char auxvalues
[][16] = {
2456 HKEY clsidhkey
, hkey
, auxhkey
, classkey
;
2457 DWORD form
, ret
, disposition
;
2465 for (form
= 0; form
<= USERCLASSTYPE_APPNAME
+1; form
++) {
2466 hr
= OleRegGetUserType(&CLSID_Testclass
, form
, NULL
);
2467 ok(hr
== E_INVALIDARG
, "form %u: got 0x%08x\n", form
, hr
);
2469 str
= (void*)0xdeadbeef;
2470 hr
= OleRegGetUserType(&CLSID_Testclass
, form
, &str
);
2471 ok(hr
== REGDB_E_CLASSNOTREG
, "form %u: got 0x%08x\n", form
, hr
);
2472 ok(str
== NULL
, "form %u: got %p\n", form
, str
);
2474 /* same string returned for StdFont for all form types */
2476 hr
= OleRegGetUserType(&CLSID_StdFont
, form
, &str
);
2477 ok(hr
== S_OK
, "form %u: got 0x%08x\n", form
, hr
);
2478 ok(!lstrcmpW(str
, stdfont_usertypeW
) || !lstrcmpW(str
, stdfont2_usertypeW
) /* winxp */,
2479 "form %u, got %s\n", form
, wine_dbgstr_w(str
));
2483 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
2485 for (form
= 0; form
<= USERCLASSTYPE_APPNAME
+1; form
++) {
2486 str
= (void*)0xdeadbeef;
2487 hr
= OleRegGetUserType(&CLSID_Testclass
, form
, &str
);
2488 ok(hr
== REGDB_E_CLASSNOTREG
, "form %u: got 0x%08x\n", form
, hr
);
2489 ok(str
== NULL
, "form %u: got %s\n", form
, wine_dbgstr_w(str
));
2491 /* same string returned for StdFont for all form types */
2493 hr
= OleRegGetUserType(&CLSID_StdFont
, form
, &str
);
2494 ok(hr
== S_OK
, "form %u: got 0x%08x\n", form
, hr
);
2495 ok(!lstrcmpW(str
, stdfont_usertypeW
) || !lstrcmpW(str
, stdfont2_usertypeW
) /* winxp */,
2496 "form %u, got %s\n", form
, wine_dbgstr_w(str
));
2500 pDeactivateActCtx(0, cookie
);
2501 pReleaseActCtx(handle
);
2504 /* test using registered CLSID */
2505 StringFromGUID2(&CLSID_non_existent
, clsidW
, sizeof(clsidW
)/sizeof(clsidW
[0]));
2507 ret
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, clsidkeyW
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &clsidhkey
, &disposition
);
2510 ret
= RegCreateKeyExW(clsidhkey
, clsidW
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &classkey
, NULL
);
2512 RegCloseKey(clsidhkey
);
2515 if (ret
== ERROR_ACCESS_DENIED
)
2517 win_skip("Failed to create test key, skipping some of OleRegGetUserType() tests.\n");
2521 ok(!ret
, "failed to create a key, error %d\n", ret
);
2523 ret
= RegSetValueExW(classkey
, NULL
, 0, REG_SZ
, (const BYTE
*)defvalueW
, sizeof(defvalueW
));
2524 ok(!ret
, "got error %d\n", ret
);
2526 ret
= RegCreateKeyExA(classkey
, "AuxUserType", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &auxhkey
, NULL
);
2527 ok(!ret
, "got error %d\n", ret
);
2529 /* populate AuxUserType */
2530 for (i
= 0; i
<= 4; i
++) {
2533 sprintf(name
, "AuxUserType\\%d", i
);
2534 ret
= RegCreateKeyExA(classkey
, name
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
);
2535 ok(!ret
, "got error %d\n", ret
);
2537 ret
= RegSetValueExA(hkey
, NULL
, 0, REG_SZ
, (const BYTE
*)auxvalues
[i
], strlen(auxvalues
[i
]));
2538 ok(!ret
, "got error %d\n", ret
);
2543 hr
= OleRegGetUserType(&CLSID_non_existent
, 0, &str
);
2544 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2545 ok(!lstrcmpW(str
, auxvalue0W
), "got %s\n", wine_dbgstr_w(str
));
2549 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_FULL
, &str
);
2550 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2551 ok(!lstrcmpW(str
, defvalueW
), "got %s\n", wine_dbgstr_w(str
));
2555 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_SHORT
, &str
);
2556 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2557 ok(!lstrcmpW(str
, auxvalue2W
), "got %s\n", wine_dbgstr_w(str
));
2561 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_APPNAME
, &str
);
2562 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2563 ok(!lstrcmpW(str
, auxvalue3W
), "got %s\n", wine_dbgstr_w(str
));
2567 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_APPNAME
+1, &str
);
2568 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2569 ok(!lstrcmpW(str
, auxvalue4W
), "got %s\n", wine_dbgstr_w(str
));
2573 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_APPNAME
+2, &str
);
2574 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2575 ok(!lstrcmpW(str
, defvalueW
), "got %s\n", wine_dbgstr_w(str
));
2578 /* registry cleanup */
2579 for (i
= 0; i
<= 4; i
++)
2582 sprintf(name
, "%d", i
);
2583 RegDeleteKeyA(auxhkey
, name
);
2585 RegCloseKey(auxhkey
);
2586 RegDeleteKeyA(classkey
, "AuxUserType");
2587 RegCloseKey(classkey
);
2588 RegDeleteKeyW(clsidhkey
, clsidW
);
2589 RegCloseKey(clsidhkey
);
2590 if (disposition
== REG_CREATED_NEW_KEY
)
2591 RegDeleteKeyA(HKEY_CLASSES_ROOT
, "CLSID");
2594 static void test_CoCreateGuid(void)
2598 hr
= CoCreateGuid(NULL
);
2599 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2602 static void CALLBACK
apc_test_proc(ULONG_PTR param
)
2607 static DWORD CALLBACK
release_semaphore_thread( LPVOID arg
)
2609 HANDLE handle
= arg
;
2610 if (WaitForSingleObject(handle
, 200) == WAIT_TIMEOUT
)
2611 ReleaseSemaphore(handle
, 1, NULL
);
2615 static DWORD CALLBACK
send_message_thread(LPVOID arg
)
2619 SendMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2623 static DWORD CALLBACK
post_message_thread(LPVOID arg
)
2627 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2631 static const char cls_name
[] = "cowait_test_class";
2632 static DWORD CALLBACK
test_CoWaitForMultipleHandles_thread(LPVOID arg
)
2634 HANDLE
*handles
= arg
;
2641 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2642 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2644 hWnd
= CreateWindowExA(0, cls_name
, "Test (thread)", WS_TILEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
2645 ok(hWnd
!= 0, "CreateWindowExA failed %u\n", GetLastError());
2648 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2649 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2650 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2651 ok(index
==0 || index
==0xdeadbeef/* Win 8 */, "expected index 0, got %u\n", index
);
2652 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2653 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2656 PostMessageA(hWnd
, WM_USER
, 0, 0);
2657 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2658 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2659 ok(index
==0 || index
==0xdeadbeef/* Win 8 */, "expected index 0, got %u\n", index
);
2660 success
= PeekMessageA(&msg
, hWnd
, WM_USER
, WM_USER
, PM_REMOVE
);
2661 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2663 DestroyWindow(hWnd
);
2668 static void test_CoWaitForMultipleHandles(void)
2670 HANDLE handles
[2], thread
;
2678 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2679 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2681 memset(&wc
, 0, sizeof(wc
));
2682 wc
.cbSize
= sizeof(wc
);
2683 wc
.style
= CS_VREDRAW
| CS_HREDRAW
;
2684 wc
.hInstance
= GetModuleHandleA(0);
2685 wc
.hCursor
= LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
);
2686 wc
.hbrBackground
= NULL
;
2687 wc
.lpszClassName
= cls_name
;
2688 wc
.lpfnWndProc
= DefWindowProcA
;
2689 success
= RegisterClassExA(&wc
) != 0;
2690 ok(success
, "RegisterClassExA failed %u\n", GetLastError());
2692 hWnd
= CreateWindowExA(0, cls_name
, "Test", WS_TILEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
2693 ok(hWnd
!= 0, "CreateWindowExA failed %u\n", GetLastError());
2694 handles
[0] = CreateSemaphoreA(NULL
, 1, 1, NULL
);
2695 ok(handles
[0] != 0, "CreateSemaphoreA failed %u\n", GetLastError());
2696 handles
[1] = CreateSemaphoreA(NULL
, 1, 1, NULL
);
2697 ok(handles
[1] != 0, "CreateSemaphoreA failed %u\n", GetLastError());
2699 /* test without flags */
2701 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2702 hr
= CoWaitForMultipleHandles(0, 50, 0, handles
, NULL
);
2703 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
2704 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2705 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2708 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2709 hr
= CoWaitForMultipleHandles(0, 50, 0, NULL
, &index
);
2710 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
2711 ok(index
== 0, "expected index 0, got %u\n", index
);
2712 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2713 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2716 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2717 hr
= CoWaitForMultipleHandles(0, 50, 0, handles
, &index
);
2718 ok(hr
== RPC_E_NO_SYNC
, "expected RPC_E_NO_SYNC, got 0x%08x\n", hr
);
2719 ok(index
== 0, "expected index 0, got %u\n", index
);
2720 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2721 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2724 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2725 hr
= CoWaitForMultipleHandles(0, 50, 1, handles
, &index
);
2726 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2727 ok(index
== 0, "expected index 0, got %u\n", index
);
2728 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2729 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2732 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2733 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2734 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2735 ok(index
== 1, "expected index 1, got %u\n", index
);
2736 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2737 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2740 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2741 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2742 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2743 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2744 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2745 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2747 /* test PostMessageA/SendMessageA from a different thread */
2750 thread
= CreateThread(NULL
, 0, post_message_thread
, hWnd
, 0, &tid
);
2751 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2752 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2753 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2754 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2755 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2756 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2757 index
= WaitForSingleObject(thread
, 200);
2758 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2759 CloseHandle(thread
);
2762 thread
= CreateThread(NULL
, 0, send_message_thread
, hWnd
, 0, &tid
);
2763 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2764 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2765 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2766 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2767 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2768 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2769 index
= WaitForSingleObject(thread
, 200);
2770 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2771 CloseHandle(thread
);
2773 ReleaseSemaphore(handles
[0], 1, NULL
);
2774 ReleaseSemaphore(handles
[1], 1, NULL
);
2776 /* test with COWAIT_WAITALL */
2779 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2780 hr
= CoWaitForMultipleHandles(COWAIT_WAITALL
, 50, 2, handles
, &index
);
2781 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2782 ok(index
== 0, "expected index 0, got %u\n", index
);
2783 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2784 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2787 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2788 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2789 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2790 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2791 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2792 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2794 ReleaseSemaphore(handles
[0], 1, NULL
);
2795 ReleaseSemaphore(handles
[1], 1, NULL
);
2797 /* test with COWAIT_ALERTABLE */
2800 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2801 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 1, handles
, &index
);
2802 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2803 ok(index
== 0, "expected index 0, got %u\n", index
);
2804 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2805 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2808 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2809 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 2, handles
, &index
);
2810 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2811 ok(index
== 1, "expected index 1, got %u\n", index
);
2812 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2813 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2816 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2817 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 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
= QueueUserAPC(apc_test_proc
, GetCurrentThread(), 0);
2826 ok(success
, "QueueUserAPC failed %u\n", GetLastError());
2827 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 2, handles
, &index
);
2828 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2829 ok(index
== WAIT_IO_COMPLETION
, "expected index WAIT_IO_COMPLETION, got %u\n", index
);
2830 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2831 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2833 /* test with COWAIT_INPUTAVAILABLE (semaphores are still locked) */
2836 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2837 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_NOREMOVE
);
2838 ok(success
, "PeekMessageA returned FALSE\n");
2839 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2840 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2841 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2842 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2843 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2846 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2847 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_NOREMOVE
);
2848 ok(success
, "PeekMessageA returned FALSE\n");
2849 thread
= CreateThread(NULL
, 0, release_semaphore_thread
, handles
[1], 0, &tid
);
2850 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2851 hr
= CoWaitForMultipleHandles(COWAIT_INPUTAVAILABLE
, 50, 2, handles
, &index
);
2852 ok(hr
== RPC_S_CALLPENDING
|| broken(hr
== E_INVALIDARG
) || broken(hr
== S_OK
) /* Win 8 */,
2853 "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2854 if (hr
!= S_OK
) ReleaseSemaphore(handles
[1], 1, NULL
);
2855 ok(index
== 0 || broken(index
== 1) /* Win 8 */, "expected index 0, got %u\n", index
);
2856 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2857 ok(!success
|| broken(success
&& hr
== E_INVALIDARG
),
2858 "CoWaitForMultipleHandles didn't pump any messages\n");
2859 index
= WaitForSingleObject(thread
, 200);
2860 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2861 CloseHandle(thread
);
2863 /* test behaviour of WM_QUIT (semaphores are still locked) */
2865 PostMessageA(hWnd
, WM_QUIT
, 40, 0);
2866 memset(&msg
, 0, sizeof(msg
));
2867 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2868 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2869 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2870 ok(msg
.wParam
== 40, "expected msg.wParam = 40, got %lu\n", msg
.wParam
);
2871 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2872 ok(!success
, "PeekMessageA succeeded\n");
2875 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2876 PostMessageA(hWnd
, WM_QUIT
, 41, 0);
2877 thread
= CreateThread(NULL
, 0, post_message_thread
, hWnd
, 0, &tid
);
2878 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2879 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2880 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2881 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2882 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2884 ok(success
|| broken(!success
) /* Win 2000/XP/8 */, "PeekMessageA failed, error %u\n", GetLastError());
2885 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2886 ok(!success
, "PeekMessageA succeeded\n");
2887 memset(&msg
, 0, sizeof(msg
));
2888 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2890 ok(!success
|| broken(success
) /* Win 2000/XP/8 */, "PeekMessageA succeeded\n");
2893 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2894 ok(msg
.wParam
== 41, "expected msg.wParam = 41, got %lu\n", msg
.wParam
);
2896 index
= WaitForSingleObject(thread
, 200);
2897 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2898 CloseHandle(thread
);
2901 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2902 PostMessageA(hWnd
, WM_QUIT
, 42, 0);
2903 thread
= CreateThread(NULL
, 0, send_message_thread
, hWnd
, 0, &tid
);
2904 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2905 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2906 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2907 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2908 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2909 ok(!success
, "CoWaitForMultipleHandles didn't pump all WM_DDE_FIRST messages\n");
2910 memset(&msg
, 0, sizeof(msg
));
2911 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2912 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2913 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2914 ok(msg
.wParam
== 42, "expected msg.wParam = 42, got %lu\n", msg
.wParam
);
2915 index
= WaitForSingleObject(thread
, 200);
2916 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2917 CloseHandle(thread
);
2919 PostQuitMessage(43);
2920 memset(&msg
, 0, sizeof(msg
));
2921 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2922 ok(success
|| broken(!success
) /* Win 8 */, "PeekMessageA failed, error %u\n", GetLastError());
2924 win_skip("PostQuitMessage didn't queue a WM_QUIT message, skipping tests\n");
2927 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2928 ok(msg
.wParam
== 43, "expected msg.wParam = 43, got %lu\n", msg
.wParam
);
2929 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2930 ok(!success
, "PeekMessageA succeeded\n");
2933 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2934 PostQuitMessage(44);
2935 thread
= CreateThread(NULL
, 0, post_message_thread
, hWnd
, 0, &tid
);
2936 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2937 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2938 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2939 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2940 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2941 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2942 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2944 ok(!success
, "PeekMessageA succeeded\n");
2945 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2947 ok(!success
, "CoWaitForMultipleHandles didn't remove WM_QUIT messages\n");
2948 index
= WaitForSingleObject(thread
, 200);
2949 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2950 CloseHandle(thread
);
2953 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2954 PostQuitMessage(45);
2955 thread
= CreateThread(NULL
, 0, send_message_thread
, hWnd
, 0, &tid
);
2956 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2957 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2958 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2959 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2960 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2961 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2962 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2964 ok(!success
, "PeekMessageA succeeded\n");
2965 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2966 ok(!success
, "CoWaitForMultipleHandles didn't remove WM_QUIT messages\n");
2967 index
= WaitForSingleObject(thread
, 200);
2968 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2969 CloseHandle(thread
);
2972 /* test message pumping when CoWaitForMultipleHandles is called from non main apartment thread */
2973 thread
= CreateThread(NULL
, 0, test_CoWaitForMultipleHandles_thread
, handles
, 0, &tid
);
2974 index
= WaitForSingleObject(thread
, 500);
2975 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2976 CloseHandle(thread
);
2978 CloseHandle(handles
[0]);
2979 CloseHandle(handles
[1]);
2980 DestroyWindow(hWnd
);
2982 success
= UnregisterClassA(cls_name
, GetModuleHandleA(0));
2983 ok(success
, "UnregisterClass failed %u\n", GetLastError());
2988 static void test_CoGetMalloc(void)
2993 if (0) /* crashes on native */
2994 hr
= CoGetMalloc(0, NULL
);
2996 imalloc
= (void*)0xdeadbeef;
2997 hr
= CoGetMalloc(0, &imalloc
);
2998 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2999 ok(imalloc
== NULL
, "got %p\n", imalloc
);
3001 imalloc
= (void*)0xdeadbeef;
3002 hr
= CoGetMalloc(MEMCTX_SHARED
, &imalloc
);
3003 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3004 ok(imalloc
== NULL
, "got %p\n", imalloc
);
3006 imalloc
= (void*)0xdeadbeef;
3007 hr
= CoGetMalloc(MEMCTX_MACSYSTEM
, &imalloc
);
3008 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3009 ok(imalloc
== NULL
, "got %p\n", imalloc
);
3011 imalloc
= (void*)0xdeadbeef;
3012 hr
= CoGetMalloc(MEMCTX_UNKNOWN
, &imalloc
);
3013 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3014 ok(imalloc
== NULL
, "got %p\n", imalloc
);
3016 imalloc
= (void*)0xdeadbeef;
3017 hr
= CoGetMalloc(MEMCTX_SAME
, &imalloc
);
3018 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3019 ok(imalloc
== NULL
, "got %p\n", imalloc
);
3022 hr
= CoGetMalloc(MEMCTX_TASK
, &imalloc
);
3023 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3024 ok(imalloc
!= NULL
, "got %p\n", imalloc
);
3025 IMalloc_Release(imalloc
);
3028 static void test_CoGetApartmentType(void)
3030 APTTYPEQUALIFIER qualifier
;
3034 if (!pCoGetApartmentType
)
3036 win_skip("CoGetApartmentType not present\n");
3040 hr
= pCoGetApartmentType(NULL
, NULL
);
3041 ok(hr
== E_INVALIDARG
, "CoGetApartmentType succeeded, error: 0x%08x\n", hr
);
3044 hr
= pCoGetApartmentType(&type
, NULL
);
3045 ok(hr
== E_INVALIDARG
, "CoGetApartmentType succeeded, error: 0x%08x\n", hr
);
3046 ok(type
== 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", type
);
3048 qualifier
= 0xdeadbeef;
3049 hr
= pCoGetApartmentType(NULL
, &qualifier
);
3050 ok(hr
== E_INVALIDARG
, "CoGetApartmentType succeeded, error: 0x%08x\n", hr
);
3051 ok(qualifier
== 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", qualifier
);
3054 qualifier
= 0xdeadbeef;
3055 hr
= pCoGetApartmentType(&type
, &qualifier
);
3056 ok(hr
== CO_E_NOTINITIALIZED
, "CoGetApartmentType succeeded, error: 0x%08x\n", hr
);
3057 ok(type
== APTTYPE_CURRENT
, "Expected APTTYPE_CURRENT, got %u\n", type
);
3058 ok(qualifier
== APTTYPEQUALIFIER_NONE
, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier
);
3061 qualifier
= 0xdeadbeef;
3062 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
3063 ok(hr
== S_OK
, "CoInitializeEx failed, error: 0x%08x\n", hr
);
3064 hr
= pCoGetApartmentType(&type
, &qualifier
);
3065 ok(hr
== S_OK
, "CoGetApartmentType failed, error: 0x%08x\n", hr
);
3066 ok(type
== APTTYPE_MAINSTA
, "Expected APTTYPE_MAINSTA, got %u\n", type
);
3067 ok(qualifier
== APTTYPEQUALIFIER_NONE
, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier
);
3071 qualifier
= 0xdeadbeef;
3072 hr
= pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
3073 ok(hr
== S_OK
, "CoInitializeEx failed, error: 0x%08x\n", hr
);
3074 hr
= pCoGetApartmentType(&type
, &qualifier
);
3075 ok(hr
== S_OK
, "CoGetApartmentType failed, error: 0x%08x\n", hr
);
3076 ok(type
== APTTYPE_MTA
, "Expected APTTYPE_MTA, got %u\n", type
);
3077 ok(qualifier
== APTTYPEQUALIFIER_NONE
, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier
);
3081 static HRESULT WINAPI
testspy_QI(IMallocSpy
*iface
, REFIID riid
, void **obj
)
3083 if (IsEqualIID(riid
, &IID_IMallocSpy
) || IsEqualIID(riid
, &IID_IUnknown
))
3086 IMallocSpy_AddRef(iface
);
3090 return E_NOINTERFACE
;
3093 static ULONG WINAPI
testspy_AddRef(IMallocSpy
*iface
)
3098 static ULONG WINAPI
testspy_Release(IMallocSpy
*iface
)
3103 static SIZE_T WINAPI
testspy_PreAlloc(IMallocSpy
*iface
, SIZE_T cb
)
3105 ok(0, "unexpected call\n");
3109 static void* WINAPI
testspy_PostAlloc(IMallocSpy
*iface
, void *ptr
)
3111 ok(0, "unexpected call\n");
3115 static void* WINAPI
testspy_PreFree(IMallocSpy
*iface
, void *ptr
, BOOL spyed
)
3117 ok(0, "unexpected call\n");
3121 static void WINAPI
testspy_PostFree(IMallocSpy
*iface
, BOOL spyed
)
3123 ok(0, "unexpected call\n");
3126 static SIZE_T WINAPI
testspy_PreRealloc(IMallocSpy
*iface
, void *ptr
, SIZE_T cb
, void **newptr
, BOOL spyed
)
3128 ok(0, "unexpected call\n");
3132 static void* WINAPI
testspy_PostRealloc(IMallocSpy
*iface
, void *ptr
, BOOL spyed
)
3134 ok(0, "unexpected call\n");
3138 static void* WINAPI
testspy_PreGetSize(IMallocSpy
*iface
, void *ptr
, BOOL spyed
)
3140 ok(0, "unexpected call\n");
3144 static SIZE_T WINAPI
testspy_PostGetSize(IMallocSpy
*iface
, SIZE_T actual
, BOOL spyed
)
3146 ok(0, "unexpected call\n");
3150 static void* WINAPI
testspy_PreDidAlloc(IMallocSpy
*iface
, void *ptr
, BOOL spyed
)
3152 ok(0, "unexpected call\n");
3156 static int WINAPI
testspy_PostDidAlloc(IMallocSpy
*iface
, void *ptr
, BOOL spyed
, int actual
)
3158 ok(0, "unexpected call\n");
3162 static void WINAPI
testspy_PreHeapMinimize(IMallocSpy
*iface
)
3164 ok(0, "unexpected call\n");
3167 static void WINAPI
testspy_PostHeapMinimize(IMallocSpy
*iface
)
3169 ok(0, "unexpected call\n");
3172 static const IMallocSpyVtbl testspyvtbl
=
3182 testspy_PostRealloc
,
3184 testspy_PostGetSize
,
3185 testspy_PreDidAlloc
,
3186 testspy_PostDidAlloc
,
3187 testspy_PreHeapMinimize
,
3188 testspy_PostHeapMinimize
3191 static IMallocSpy testspy
= { &testspyvtbl
};
3193 static void test_IMallocSpy(void)
3198 hr
= CoRegisterMallocSpy(NULL
);
3199 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3201 hr
= CoRevokeMallocSpy();
3202 ok(hr
== CO_E_OBJNOTREG
, "got 0x%08x\n", hr
);
3204 hr
= CoRegisterMallocSpy(&testspy
);
3205 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3207 hr
= CoRegisterMallocSpy(NULL
);
3208 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3210 hr
= CoRegisterMallocSpy(&testspy
);
3211 ok(hr
== CO_E_OBJISREG
, "got 0x%08x\n", hr
);
3214 hr
= CoGetMalloc(MEMCTX_TASK
, &imalloc
);
3215 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3216 ok(imalloc
!= NULL
, "got %p\n", imalloc
);
3218 IMalloc_Free(imalloc
, NULL
);
3220 IMalloc_Release(imalloc
);
3222 hr
= CoRevokeMallocSpy();
3223 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3225 hr
= CoRevokeMallocSpy();
3226 ok(hr
== CO_E_OBJNOTREG
, "got 0x%08x\n", hr
);
3229 static void test_CoGetCurrentLogicalThreadId(void)
3234 hr
= CoGetCurrentLogicalThreadId(NULL
);
3235 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3238 hr
= CoGetCurrentLogicalThreadId(&id
);
3239 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3240 ok(!IsEqualGUID(&id
, &GUID_NULL
), "got null id\n");
3243 static HRESULT WINAPI
testinitialize_QI(IInitializeSpy
*iface
, REFIID riid
, void **obj
)
3245 if (IsEqualIID(riid
, &IID_IInitializeSpy
) || IsEqualIID(riid
, &IID_IUnknown
))
3248 IInitializeSpy_AddRef(iface
);
3253 return E_NOINTERFACE
;
3256 static ULONG WINAPI
testinitialize_AddRef(IInitializeSpy
*iface
)
3261 static ULONG WINAPI
testinitialize_Release(IInitializeSpy
*iface
)
3266 static HRESULT WINAPI
testinitialize_PreInitialize(IInitializeSpy
*iface
, DWORD coinit
, DWORD aptrefs
)
3268 ok(0, "unexpected call\n");
3272 static HRESULT WINAPI
testinitialize_PostInitialize(IInitializeSpy
*iface
, HRESULT hr
, DWORD coinit
, DWORD aptrefs
)
3274 ok(0, "unexpected call\n");
3278 static HRESULT WINAPI
testinitialize_PreUninitialize(IInitializeSpy
*iface
, DWORD aptrefs
)
3280 ok(0, "unexpected call\n");
3284 static HRESULT WINAPI
testinitialize_PostUninitialize(IInitializeSpy
*iface
, DWORD aptrefs
)
3286 ok(0, "unexpected call\n");
3290 static const IInitializeSpyVtbl testinitializevtbl
=
3293 testinitialize_AddRef
,
3294 testinitialize_Release
,
3295 testinitialize_PreInitialize
,
3296 testinitialize_PostInitialize
,
3297 testinitialize_PreUninitialize
,
3298 testinitialize_PostUninitialize
3301 static IInitializeSpy testinitialize
= { &testinitializevtbl
};
3303 static void test_IInitializeSpy(void)
3305 ULARGE_INTEGER cookie
, cookie1
, cookie2
;
3308 hr
= CoRegisterInitializeSpy(NULL
, NULL
);
3309 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3311 cookie
.QuadPart
= 1;
3312 hr
= CoRegisterInitializeSpy(NULL
, &cookie
);
3313 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3314 ok(cookie
.QuadPart
== 1, "got wrong cookie\n");
3316 hr
= CoRegisterInitializeSpy(&testinitialize
, NULL
);
3317 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3319 cookie
.HighPart
= 0;
3321 hr
= CoRegisterInitializeSpy(&testinitialize
, &cookie
);
3322 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3324 ok(cookie
.HighPart
== GetCurrentThreadId(), "got high part 0x%08x, expected 0x%08x\n", cookie
.HighPart
,
3325 GetCurrentThreadId());
3326 ok(cookie
.LowPart
== 0, "got wrong low part 0x%x\n", cookie
.LowPart
);
3328 /* register same instance one more time */
3329 cookie1
.HighPart
= 0;
3330 cookie1
.LowPart
= 0;
3331 hr
= CoRegisterInitializeSpy(&testinitialize
, &cookie1
);
3333 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3334 ok(cookie1
.HighPart
== GetCurrentThreadId(), "got high part 0x%08x, expected 0x%08x\n", cookie1
.HighPart
,
3335 GetCurrentThreadId());
3336 ok(cookie1
.LowPart
== 1, "got wrong low part 0x%x\n", cookie1
.LowPart
);
3338 cookie2
.HighPart
= 0;
3339 cookie2
.LowPart
= 0;
3340 hr
= CoRegisterInitializeSpy(&testinitialize
, &cookie2
);
3342 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3343 ok(cookie2
.HighPart
== GetCurrentThreadId(), "got high part 0x%08x, expected 0x%08x\n", cookie2
.HighPart
,
3344 GetCurrentThreadId());
3345 ok(cookie2
.LowPart
== 2, "got wrong low part 0x%x\n", cookie2
.LowPart
);
3347 hr
= CoRevokeInitializeSpy(cookie1
);
3349 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3351 hr
= CoRevokeInitializeSpy(cookie1
);
3352 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3354 cookie1
.HighPart
= 0;
3355 cookie1
.LowPart
= 0;
3356 hr
= CoRegisterInitializeSpy(&testinitialize
, &cookie1
);
3358 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3359 ok(cookie1
.HighPart
== GetCurrentThreadId(), "got high part 0x%08x, expected 0x%08x\n", cookie1
.HighPart
,
3360 GetCurrentThreadId());
3361 ok(cookie1
.LowPart
== 1, "got wrong low part 0x%x\n", cookie1
.LowPart
);
3363 hr
= CoRevokeInitializeSpy(cookie
);
3364 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3366 hr
= CoRevokeInitializeSpy(cookie1
);
3368 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3370 hr
= CoRevokeInitializeSpy(cookie2
);
3372 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3375 static HRESULT g_persistfile_qi_ret
;
3376 static HRESULT g_persistfile_load_ret
;
3377 static HRESULT WINAPI
testinstance_QI(IPersistFile
*iface
, REFIID riid
, void **obj
)
3379 if (IsEqualIID(riid
, &IID_IUnknown
)) {
3381 IUnknown_AddRef(iface
);
3385 if (IsEqualIID(riid
, &IID_IPersistFile
)) {
3386 if (SUCCEEDED(g_persistfile_qi_ret
)) {
3388 IUnknown_AddRef(iface
);
3392 return g_persistfile_qi_ret
;
3395 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid
));
3397 return E_NOINTERFACE
;
3400 static ULONG WINAPI
testinstance_AddRef(IPersistFile
*iface
)
3405 static ULONG WINAPI
testinstance_Release(IPersistFile
*iface
)
3410 static HRESULT WINAPI
testinstance_GetClassID(IPersistFile
*iface
, CLSID
*clsid
)
3412 ok(0, "unexpected call\n");
3416 static HRESULT WINAPI
testinstance_IsDirty(IPersistFile
*iface
)
3418 ok(0, "unexpected call\n");
3422 static HRESULT WINAPI
testinstance_Load(IPersistFile
*iface
, LPCOLESTR filename
, DWORD mode
)
3424 return g_persistfile_load_ret
;
3427 static HRESULT WINAPI
testinstance_Save(IPersistFile
*iface
, LPCOLESTR filename
, BOOL remember
)
3432 static HRESULT WINAPI
testinstance_SaveCompleted(IPersistFile
*iface
, LPCOLESTR filename
)
3434 ok(0, "unexpected call\n");
3438 static HRESULT WINAPI
testinstance_GetCurFile(IPersistFile
*iface
, LPOLESTR
*filename
)
3440 ok(0, "unexpected call\n");
3444 static const IPersistFileVtbl testpersistfilevtbl
= {
3446 testinstance_AddRef
,
3447 testinstance_Release
,
3448 testinstance_GetClassID
,
3449 testinstance_IsDirty
,
3452 testinstance_SaveCompleted
,
3453 testinstance_GetCurFile
3456 static IPersistFile testpersistfile
= { &testpersistfilevtbl
};
3458 static HRESULT WINAPI
getinstance_cf_QI(IClassFactory
*iface
, REFIID riid
, void **obj
)
3460 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IClassFactory
)) {
3462 IClassFactory_AddRef(iface
);
3467 return E_NOINTERFACE
;
3470 static ULONG WINAPI
getinstance_cf_AddRef(IClassFactory
*iface
)
3475 static ULONG WINAPI
getinstance_cf_Release(IClassFactory
*iface
)
3480 static HRESULT WINAPI
getinstance_cf_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
,
3481 REFIID riid
, void **obj
)
3483 if (IsEqualIID(riid
, &IID_IUnknown
)) {
3484 *obj
= &testpersistfile
;
3488 ok(0, "unexpected call, riid %s\n", wine_dbgstr_guid(riid
));
3493 static HRESULT WINAPI
getinstance_cf_LockServer(IClassFactory
*iface
, BOOL lock
)
3495 ok(0, "unexpected call\n");
3499 static const IClassFactoryVtbl getinstance_cf_vtbl
= {
3501 getinstance_cf_AddRef
,
3502 getinstance_cf_Release
,
3503 getinstance_cf_CreateInstance
,
3504 getinstance_cf_LockServer
3507 static IClassFactory getinstance_cf
= { &getinstance_cf_vtbl
};
3509 static void test_CoGetInstanceFromFile(void)
3511 static const WCHAR filenameW
[] = {'d','u','m','m','y','p','a','t','h',0};
3512 CLSID
*clsid
= (CLSID
*)&CLSID_testclsid
;
3517 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
3518 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3520 /* CLSID is not specified, file does not exist */
3521 mqi
[0].pIID
= &IID_IUnknown
;
3523 mqi
[0].hr
= E_NOTIMPL
;
3524 hr
= CoGetInstanceFromFile(NULL
, NULL
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3526 ok(hr
== MK_E_CANTOPENFILE
, "got 0x%08x\n", hr
);
3527 ok(mqi
[0].pItf
== NULL
, "got %p\n", mqi
[0].pItf
);
3528 ok(mqi
[0].hr
== E_NOINTERFACE
, "got 0x%08x\n", mqi
[0].hr
);
3530 /* class is not available */
3531 mqi
[0].pIID
= &IID_IUnknown
;
3533 mqi
[0].hr
= E_NOTIMPL
;
3534 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3535 ok(hr
== REGDB_E_CLASSNOTREG
, "got 0x%08x\n", hr
);
3536 ok(mqi
[0].pItf
== NULL
, "got %p\n", mqi
[0].pItf
);
3537 ok(mqi
[0].hr
== REGDB_E_CLASSNOTREG
, "got 0x%08x\n", mqi
[0].hr
);
3539 hr
= CoRegisterClassObject(clsid
, (IUnknown
*)&getinstance_cf
, CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
,
3541 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3543 mqi
[0].pIID
= &IID_IUnknown
;
3544 mqi
[0].pItf
= (void*)0xdeadbeef;
3546 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3548 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3549 ok(mqi
[0].pItf
== (void*)0xdeadbeef, "got %p\n", mqi
[0].pItf
);
3551 ok(mqi
[0].hr
== S_OK
, "got 0x%08x\n", mqi
[0].hr
);
3553 mqi
[0].pIID
= &IID_IUnknown
;
3554 mqi
[0].pItf
= (void*)0xdeadbeef;
3555 mqi
[0].hr
= E_NOTIMPL
;
3556 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3558 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3559 ok(mqi
[0].pItf
== (void*)0xdeadbeef, "got %p\n", mqi
[0].pItf
);
3560 ok(mqi
[0].hr
== E_NOTIMPL
, "got 0x%08x\n", mqi
[0].hr
);
3562 mqi
[0].pIID
= &IID_IUnknown
;
3564 mqi
[0].hr
= E_NOTIMPL
;
3565 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3566 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3567 ok(mqi
[0].pItf
!= NULL
, "got %p\n", mqi
[0].pItf
);
3568 ok(mqi
[0].hr
== S_OK
, "got 0x%08x\n", mqi
[0].hr
);
3570 mqi
[0].pIID
= &IID_IUnknown
;
3573 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3574 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3575 ok(mqi
[0].pItf
!= NULL
, "got %p\n", mqi
[0].pItf
);
3576 ok(mqi
[0].hr
== S_OK
, "got 0x%08x\n", mqi
[0].hr
);
3578 mqi
[0].pIID
= &IID_IUnknown
;
3581 g_persistfile_qi_ret
= S_FALSE
;
3582 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3583 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3584 ok(mqi
[0].pItf
!= NULL
, "got %p\n", mqi
[0].pItf
);
3585 ok(mqi
[0].hr
== S_OK
, "got 0x%08x\n", mqi
[0].hr
);
3586 g_persistfile_qi_ret
= S_OK
;
3588 mqi
[0].pIID
= &IID_IUnknown
;
3591 mqi
[1].pIID
= &IID_IUnknown
;
3594 g_persistfile_qi_ret
= 0x8000efef;
3595 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 2, mqi
);
3596 ok(hr
== 0x8000efef, "got 0x%08x\n", hr
);
3597 ok(mqi
[0].pItf
== NULL
, "got %p\n", mqi
[0].pItf
);
3598 ok(mqi
[0].hr
== 0x8000efef, "got 0x%08x\n", mqi
[0].hr
);
3599 ok(mqi
[1].pItf
== NULL
, "got %p\n", mqi
[1].pItf
);
3600 ok(mqi
[1].hr
== 0x8000efef, "got 0x%08x\n", mqi
[1].hr
);
3601 g_persistfile_qi_ret
= S_OK
;
3603 mqi
[0].pIID
= &IID_IUnknown
;
3606 mqi
[1].pIID
= &IID_IUnknown
;
3609 g_persistfile_load_ret
= 0x8000fefe;
3610 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 2, mqi
);
3611 ok(hr
== 0x8000fefe, "got 0x%08x\n", hr
);
3612 ok(mqi
[0].pItf
== NULL
, "got %p\n", mqi
[0].pItf
);
3613 ok(mqi
[0].hr
== 0x8000fefe, "got 0x%08x\n", mqi
[0].hr
);
3614 ok(mqi
[1].pItf
== NULL
, "got %p\n", mqi
[1].pItf
);
3615 ok(mqi
[1].hr
== 0x8000fefe, "got 0x%08x\n", mqi
[1].hr
);
3616 g_persistfile_load_ret
= S_OK
;
3618 hr
= CoRevokeClassObject(cookie
);
3619 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3624 static void test_GlobalOptions(void)
3626 IGlobalOptions
*global_options
;
3631 hres
= CoCreateInstance(&CLSID_GlobalOptions
, NULL
, CLSCTX_INPROC_SERVER
,
3632 &IID_IGlobalOptions
, (void**)&global_options
);
3633 ok(hres
== S_OK
|| broken(hres
== E_NOINTERFACE
), "CoCreateInstance(CLSID_GlobalOptions) failed: %08x\n", hres
);
3636 win_skip("CLSID_GlobalOptions not available\n");
3641 IGlobalOptions_Release(global_options
);
3643 hres
= CoCreateInstance(&CLSID_GlobalOptions
, (IUnknown
*)0xdeadbeef, CLSCTX_INPROC_SERVER
,
3644 &IID_IGlobalOptions
, (void**)&global_options
);
3645 ok(hres
== E_INVALIDARG
, "CoCreateInstance(CLSID_GlobalOptions) failed: %08x\n", hres
);
3650 static void init_funcs(void)
3652 HMODULE hOle32
= GetModuleHandleA("ole32");
3653 HMODULE hAdvapi32
= GetModuleHandleA("advapi32");
3654 HMODULE hkernel32
= GetModuleHandleA("kernel32");
3656 pCoGetObjectContext
= (void*)GetProcAddress(hOle32
, "CoGetObjectContext");
3657 pCoSwitchCallContext
= (void*)GetProcAddress(hOle32
, "CoSwitchCallContext");
3658 pCoGetTreatAsClass
= (void*)GetProcAddress(hOle32
,"CoGetTreatAsClass");
3659 pCoTreatAsClass
= (void*)GetProcAddress(hOle32
,"CoTreatAsClass");
3660 pCoGetContextToken
= (void*)GetProcAddress(hOle32
, "CoGetContextToken");
3661 pCoGetApartmentType
= (void*)GetProcAddress(hOle32
, "CoGetApartmentType");
3662 pRegDeleteKeyExA
= (void*)GetProcAddress(hAdvapi32
, "RegDeleteKeyExA");
3663 pRegOverridePredefKey
= (void*)GetProcAddress(hAdvapi32
, "RegOverridePredefKey");
3664 pCoInitializeEx
= (void*)GetProcAddress(hOle32
, "CoInitializeEx");
3666 pActivateActCtx
= (void*)GetProcAddress(hkernel32
, "ActivateActCtx");
3667 pCreateActCtxW
= (void*)GetProcAddress(hkernel32
, "CreateActCtxW");
3668 pDeactivateActCtx
= (void*)GetProcAddress(hkernel32
, "DeactivateActCtx");
3669 pIsWow64Process
= (void*)GetProcAddress(hkernel32
, "IsWow64Process");
3670 pReleaseActCtx
= (void*)GetProcAddress(hkernel32
, "ReleaseActCtx");
3677 if (!pCoInitializeEx
)
3679 trace("You need DCOM95 installed to run this test\n");
3683 if (!pCreateActCtxW
)
3684 win_skip("Activation contexts are not supported, some tests will be skipped.\n");
3686 test_ProgIDFromCLSID();
3687 test_CLSIDFromProgID();
3688 test_CLSIDFromString();
3689 test_IIDFromString();
3690 test_StringFromGUID2();
3691 test_CoCreateInstance();
3693 test_CoGetClassObject();
3694 test_CoCreateInstanceEx();
3695 test_CoRegisterMessageFilter();
3696 test_CoRegisterPSClsid();
3697 test_CoGetPSClsid();
3698 test_CoUnmarshalInterface();
3699 test_CoGetInterfaceAndReleaseStream();
3700 test_CoMarshalInterface();
3701 test_CoMarshalInterThreadInterfaceInStream();
3702 test_CoRegisterClassObject();
3703 test_registered_object_thread_affinity();
3704 test_CoFreeUnusedLibraries();
3705 test_CoGetObjectContext();
3706 test_CoGetCallContext();
3707 test_CoGetContextToken();
3708 test_TreatAsClass();
3709 test_CoInitializeEx();
3710 test_OleInitialize_InitCounting();
3711 test_OleRegGetMiscStatus();
3712 test_CoCreateGuid();
3713 test_CoWaitForMultipleHandles();
3715 test_OleRegGetUserType();
3716 test_CoGetApartmentType();
3718 test_CoGetCurrentLogicalThreadId();
3719 test_IInitializeSpy();
3720 test_CoGetInstanceFromFile();
3721 test_GlobalOptions();