2 * Component Object Tests
4 * Copyright 2005 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #define USE_COM_CONTEXT_DEF
35 #include "urlmon.h" /* for CLSID_FileProtocol */
41 #include "wine/test.h"
47 #define DEFINE_EXPECT(func) \
48 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
50 #define SET_EXPECT(func) \
51 expect_ ## func = TRUE
53 #define CHECK_EXPECT2(func) \
55 ok(expect_ ##func, "unexpected call " #func "\n"); \
56 called_ ## func = TRUE; \
59 #define CHECK_EXPECT(func) \
61 CHECK_EXPECT2(func); \
62 expect_ ## func = FALSE; \
65 #define CHECK_CALLED(func) \
67 ok(called_ ## func, "expected " #func "\n"); \
68 expect_ ## func = called_ ## func = FALSE; \
71 DEFINE_EXPECT(CreateStub
);
73 /* functions that are not present on all versions of Windows */
74 static HRESULT (WINAPI
* pCoInitializeEx
)(LPVOID lpReserved
, DWORD dwCoInit
);
75 static HRESULT (WINAPI
* pCoGetObjectContext
)(REFIID riid
, LPVOID
*ppv
);
76 static HRESULT (WINAPI
* pCoSwitchCallContext
)(IUnknown
*pObject
, IUnknown
**ppOldObject
);
77 static HRESULT (WINAPI
* pCoGetTreatAsClass
)(REFCLSID clsidOld
, LPCLSID pClsidNew
);
78 static HRESULT (WINAPI
* pCoTreatAsClass
)(REFCLSID clsidOld
, REFCLSID pClsidNew
);
79 static HRESULT (WINAPI
* pCoGetContextToken
)(ULONG_PTR
*token
);
80 static HRESULT (WINAPI
* pCoGetApartmentType
)(APTTYPE
*type
, APTTYPEQUALIFIER
*qualifier
);
81 static LONG (WINAPI
* pRegDeleteKeyExA
)(HKEY
, LPCSTR
, REGSAM
, DWORD
);
82 static LONG (WINAPI
* pRegOverridePredefKey
)(HKEY key
, HKEY override
);
84 static BOOL (WINAPI
*pActivateActCtx
)(HANDLE
,ULONG_PTR
*);
85 static HANDLE (WINAPI
*pCreateActCtxW
)(PCACTCTXW
);
86 static BOOL (WINAPI
*pDeactivateActCtx
)(DWORD
,ULONG_PTR
);
87 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
, LPBOOL
);
88 static void (WINAPI
*pReleaseActCtx
)(HANDLE
);
90 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
91 #define ok_more_than_one_lock() ok(cLocks > 0, "Number of locks should be > 0, but actually is %d\n", cLocks)
92 #define ok_no_locks() ok(cLocks == 0, "Number of locks should be 0, but actually is %d\n", cLocks)
94 static const CLSID CLSID_non_existent
= { 0x12345678, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
95 static const CLSID CLSID_StdFont
= { 0x0be35203, 0x8f91, 0x11ce, { 0x9d, 0xe3, 0x00, 0xaa, 0x00, 0x4b, 0xb8, 0x51 } };
96 static const GUID IID_Testiface
= { 0x22222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
97 static const GUID IID_Testiface2
= { 0x32222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
98 static const GUID IID_Testiface3
= { 0x42222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
99 static const GUID IID_Testiface4
= { 0x52222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
100 static const GUID IID_Testiface5
= { 0x62222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
101 static const GUID IID_Testiface6
= { 0x72222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
102 static const GUID IID_TestPS
= { 0x66666666, 0x8888, 0x7777, { 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 } };
104 DEFINE_GUID(CLSID_InProcFreeMarshaler
, 0x0000033a,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
105 DEFINE_GUID(CLSID_testclsid
, 0xacd014c7,0x9535,0x4fac,0x8b,0x53,0xa4,0x8c,0xa7,0xf4,0xd7,0x26);
106 DEFINE_GUID(CLSID_GlobalOptions
, 0x0000034b,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
108 static const WCHAR stdfont
[] = {'S','t','d','F','o','n','t',0};
109 static const WCHAR wszNonExistent
[] = {'N','o','n','E','x','i','s','t','e','n','t',0};
110 static const WCHAR wszCLSID_StdFont
[] =
112 '{','0','b','e','3','5','2','0','3','-','8','f','9','1','-','1','1','c','e','-',
113 '9','d','e','3','-','0','0','a','a','0','0','4','b','b','8','5','1','}',0
115 static const WCHAR progidW
[] = {'P','r','o','g','I','d','.','P','r','o','g','I','d',0};
116 static const WCHAR cf_brokenW
[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-',
117 'c','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}','a',0};
119 DEFINE_GUID(IID_IWineTest
, 0x5201163f, 0x8164, 0x4fd0, 0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd);
120 DEFINE_GUID(CLSID_WineOOPTest
, 0x5201163f, 0x8164, 0x4fd0, 0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd);
124 static void LockModule(void)
126 InterlockedIncrement(&cLocks
);
129 static void UnlockModule(void)
131 InterlockedDecrement(&cLocks
);
134 static HRESULT WINAPI
Test_IClassFactory_QueryInterface(
135 LPCLASSFACTORY iface
,
139 if (ppvObj
== NULL
) return E_POINTER
;
141 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
142 IsEqualGUID(riid
, &IID_IClassFactory
))
145 IClassFactory_AddRef(iface
);
150 return E_NOINTERFACE
;
153 static ULONG WINAPI
Test_IClassFactory_AddRef(LPCLASSFACTORY iface
)
156 return 2; /* non-heap-based object */
159 static ULONG WINAPI
Test_IClassFactory_Release(LPCLASSFACTORY iface
)
162 return 1; /* non-heap-based object */
165 static IID create_instance_iid
;
166 static HRESULT WINAPI
Test_IClassFactory_CreateInstance(
167 LPCLASSFACTORY iface
,
173 create_instance_iid
= *riid
;
174 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
175 return E_NOINTERFACE
;
178 static HRESULT WINAPI
Test_IClassFactory_LockServer(
179 LPCLASSFACTORY iface
,
185 static const IClassFactoryVtbl TestClassFactory_Vtbl
=
187 Test_IClassFactory_QueryInterface
,
188 Test_IClassFactory_AddRef
,
189 Test_IClassFactory_Release
,
190 Test_IClassFactory_CreateInstance
,
191 Test_IClassFactory_LockServer
194 static IClassFactory Test_ClassFactory
= { &TestClassFactory_Vtbl
};
196 static WCHAR manifest_path
[MAX_PATH
];
198 static BOOL
create_manifest_file(const char *filename
, const char *manifest
)
203 WCHAR path
[MAX_PATH
];
205 MultiByteToWideChar( CP_ACP
, 0, filename
, -1, path
, MAX_PATH
);
206 GetFullPathNameW(path
, sizeof(manifest_path
)/sizeof(WCHAR
), manifest_path
, NULL
);
208 manifest_len
= strlen(manifest
);
209 file
= CreateFileW(path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
210 FILE_ATTRIBUTE_NORMAL
, NULL
);
211 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed: %u\n", GetLastError());
212 if(file
== INVALID_HANDLE_VALUE
)
214 WriteFile(file
, manifest
, manifest_len
, &size
, NULL
);
220 static HANDLE
activate_context(const char *manifest
, ULONG_PTR
*cookie
)
222 WCHAR path
[MAX_PATH
];
227 if (!pCreateActCtxW
) return NULL
;
229 create_manifest_file("file.manifest", manifest
);
231 MultiByteToWideChar( CP_ACP
, 0, "file.manifest", -1, path
, MAX_PATH
);
232 memset(&actctx
, 0, sizeof(ACTCTXW
));
233 actctx
.cbSize
= sizeof(ACTCTXW
);
234 actctx
.lpSource
= path
;
236 handle
= pCreateActCtxW(&actctx
);
237 ok(handle
!= INVALID_HANDLE_VALUE
|| broken(handle
== INVALID_HANDLE_VALUE
) /* some old XP/2k3 versions */,
238 "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
239 if (handle
== INVALID_HANDLE_VALUE
)
241 win_skip("activation context generation failed, some tests will be skipped\n");
245 ok(actctx
.cbSize
== sizeof(ACTCTXW
), "actctx.cbSize=%d\n", actctx
.cbSize
);
246 ok(actctx
.dwFlags
== 0, "actctx.dwFlags=%d\n", actctx
.dwFlags
);
247 ok(actctx
.lpSource
== path
, "actctx.lpSource=%p\n", actctx
.lpSource
);
248 ok(actctx
.wProcessorArchitecture
== 0, "actctx.wProcessorArchitecture=%d\n", actctx
.wProcessorArchitecture
);
249 ok(actctx
.wLangId
== 0, "actctx.wLangId=%d\n", actctx
.wLangId
);
250 ok(actctx
.lpAssemblyDirectory
== NULL
, "actctx.lpAssemblyDirectory=%p\n", actctx
.lpAssemblyDirectory
);
251 ok(actctx
.lpResourceName
== NULL
, "actctx.lpResourceName=%p\n", actctx
.lpResourceName
);
252 ok(actctx
.lpApplicationName
== NULL
, "actctx.lpApplicationName=%p\n", actctx
.lpApplicationName
);
253 ok(actctx
.hModule
== NULL
, "actctx.hModule=%p\n", actctx
.hModule
);
255 DeleteFileA("file.manifest");
259 ret
= pActivateActCtx(handle
, cookie
);
260 ok(ret
, "ActivateActCtx failed: %u\n", GetLastError());
266 static const char actctx_manifest
[] =
267 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
268 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\""
269 " publicKeyToken=\"6595b6414666f1df\" />"
270 "<file name=\"testlib.dll\">"
272 " clsid=\"{0000033a-0000-0000-c000-000000000046}\""
273 " progid=\"FTMarshal\""
276 " clsid=\"{5201163f-8164-4fd0-a1a2-5d5a3654d3bd}\""
277 " progid=\"WineOOPTest\""
279 " <comClass description=\"Test com class\""
280 " clsid=\"{12345678-1234-1234-1234-56789abcdef0}\""
281 " progid=\"ProgId.ProgId\""
282 " miscStatusIcon=\"recomposeonresize\""
284 " <comClass description=\"CustomFont Description\" clsid=\"{0be35203-8f91-11ce-9de3-00aa004bb851}\""
285 " progid=\"CustomFont\""
286 " miscStatusIcon=\"recomposeonresize\""
287 " miscStatusContent=\"insideout\""
289 " <comClass description=\"StdFont Description\" clsid=\"{0be35203-8f91-11ce-9de3-00aa004bb852}\""
290 " progid=\"StdFont\""
292 " <comClass clsid=\"{62222222-1234-1234-1234-56789abcdef0}\" >"
293 " <progid>ProgId.ProgId.1</progid>"
295 " <comInterfaceProxyStub "
297 " iid=\"{22222222-1234-1234-1234-56789abcdef0}\""
298 " proxyStubClsid32=\"{66666666-8888-7777-6666-555555555555}\""
301 " <comInterfaceExternalProxyStub "
302 " name=\"Iifaceps2\""
303 " iid=\"{32222222-1234-1234-1234-56789abcdef0}\""
305 " <comInterfaceExternalProxyStub "
306 " name=\"Iifaceps3\""
307 " iid=\"{42222222-1234-1234-1234-56789abcdef0}\""
308 " proxyStubClsid32=\"{66666666-8888-7777-6666-555555555555}\""
310 " <comInterfaceExternalProxyStub "
311 " name=\"Iifaceps4\""
312 " iid=\"{52222222-1234-1234-1234-56789abcdef0}\""
313 " proxyStubClsid32=\"{00000000-0000-0000-0000-000000000000}\""
316 " clsid=\"{72222222-1234-1234-1234-56789abcdef0}\""
319 " <progid>clrprogid.1</progid>"
323 DEFINE_GUID(CLSID_Testclass
, 0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0);
325 static void test_ProgIDFromCLSID(void)
327 ULONG_PTR cookie
= 0;
332 hr
= ProgIDFromCLSID(&CLSID_StdFont
, &progid
);
333 ok(hr
== S_OK
, "ProgIDFromCLSID failed with error 0x%08x\n", hr
);
336 ok(!lstrcmpiW(progid
, stdfont
), "Didn't get expected prog ID\n");
337 CoTaskMemFree(progid
);
340 progid
= (LPWSTR
)0xdeadbeef;
341 hr
= ProgIDFromCLSID(&CLSID_non_existent
, &progid
);
342 ok(hr
== REGDB_E_CLASSNOTREG
, "ProgIDFromCLSID returned %08x\n", hr
);
343 ok(progid
== NULL
, "ProgIDFromCLSID returns with progid %p\n", progid
);
345 hr
= ProgIDFromCLSID(&CLSID_StdFont
, NULL
);
346 ok(hr
== E_INVALIDARG
, "ProgIDFromCLSID should return E_INVALIDARG instead of 0x%08x\n", hr
);
348 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
350 static const WCHAR customfontW
[] = {'C','u','s','t','o','m','F','o','n','t',0};
352 hr
= ProgIDFromCLSID(&CLSID_non_existent
, &progid
);
353 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
354 ok(!lstrcmpiW(progid
, progidW
), "got %s\n", wine_dbgstr_w(progid
));
355 CoTaskMemFree(progid
);
357 /* try something registered and redirected */
359 hr
= ProgIDFromCLSID(&CLSID_StdFont
, &progid
);
360 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
361 ok(!lstrcmpiW(progid
, customfontW
), "got wrong progid %s\n", wine_dbgstr_w(progid
));
362 CoTaskMemFree(progid
);
364 /* classes without default progid, progid list is not used */
365 progid
= (void *)0xdeadbeef;
366 hr
= ProgIDFromCLSID(&IID_Testiface5
, &progid
);
367 ok(hr
== REGDB_E_CLASSNOTREG
&& progid
== NULL
, "got 0x%08x, progid %p\n", hr
, progid
);
369 progid
= (void *)0xdeadbeef;
370 hr
= ProgIDFromCLSID(&IID_Testiface6
, &progid
);
371 ok(hr
== REGDB_E_CLASSNOTREG
&& progid
== NULL
, "got 0x%08x, progid %p\n", hr
, progid
);
373 pDeactivateActCtx(0, cookie
);
374 pReleaseActCtx(handle
);
378 static void test_CLSIDFromProgID(void)
380 ULONG_PTR cookie
= 0;
383 HRESULT hr
= CLSIDFromProgID(stdfont
, &clsid
);
384 ok(hr
== S_OK
, "CLSIDFromProgID failed with error 0x%08x\n", hr
);
385 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
387 hr
= CLSIDFromString(stdfont
, &clsid
);
388 ok_ole_success(hr
, "CLSIDFromString");
389 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
391 /* test some failure cases */
393 hr
= CLSIDFromProgID(wszNonExistent
, NULL
);
394 ok(hr
== E_INVALIDARG
, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
396 hr
= CLSIDFromProgID(NULL
, &clsid
);
397 ok(hr
== E_INVALIDARG
, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
399 memset(&clsid
, 0xcc, sizeof(clsid
));
400 hr
= CLSIDFromProgID(wszNonExistent
, &clsid
);
401 ok(hr
== CO_E_CLASSSTRING
, "CLSIDFromProgID on nonexistent ProgID should have returned CO_E_CLASSSTRING instead of 0x%08x\n", hr
);
402 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "CLSIDFromProgID should have set clsid to all-zeros on failure\n");
404 /* fails without proper context */
405 memset(&clsid
, 0xcc, sizeof(clsid
));
406 hr
= CLSIDFromProgID(progidW
, &clsid
);
407 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
408 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "wrong clsid\n");
410 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
414 memset(&clsid
, 0xcc, sizeof(clsid
));
415 hr
= CLSIDFromProgID(wszNonExistent
, &clsid
);
416 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
417 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "should have zero CLSID on failure\n");
419 /* CLSIDFromString() doesn't check activation context */
420 hr
= CLSIDFromString(progidW
, &clsid
);
421 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
424 hr
= CLSIDFromProgID(progidW
, &clsid
);
425 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
426 /* it returns generated CLSID here */
427 ok(!IsEqualCLSID(&clsid
, &CLSID_non_existent
) && !IsEqualCLSID(&clsid
, &CLSID_NULL
),
428 "got wrong clsid %s\n", wine_dbgstr_guid(&clsid
));
430 /* duplicate progid present in context - returns generated guid here too */
432 hr
= CLSIDFromProgID(stdfont
, &clsid
);
433 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
434 clsid1
= CLSID_StdFont
;
435 /* that's where it differs from StdFont */
436 clsid1
.Data4
[7] = 0x52;
437 ok(!IsEqualCLSID(&clsid
, &CLSID_StdFont
) && !IsEqualCLSID(&clsid
, &CLSID_NULL
) && !IsEqualCLSID(&clsid
, &clsid1
),
438 "got %s\n", wine_dbgstr_guid(&clsid
));
440 pDeactivateActCtx(0, cookie
);
441 pReleaseActCtx(handle
);
445 static void test_CLSIDFromString(void)
448 WCHAR wszCLSID_Broken
[50];
451 HRESULT hr
= CLSIDFromString(wszCLSID_StdFont
, &clsid
);
452 ok_ole_success(hr
, "CLSIDFromString");
453 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
455 memset(&clsid
, 0xab, sizeof(clsid
));
456 hr
= CLSIDFromString(NULL
, &clsid
);
457 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
458 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "clsid wasn't equal to CLSID_NULL\n");
460 /* string is longer, but starts with a valid CLSID */
461 memset(&clsid
, 0, sizeof(clsid
));
462 hr
= CLSIDFromString(cf_brokenW
, &clsid
);
463 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
464 ok(IsEqualCLSID(&clsid
, &IID_IClassFactory
), "got %s\n", wine_dbgstr_guid(&clsid
));
466 lstrcpyW(wszCLSID_Broken
, wszCLSID_StdFont
);
467 for(i
= lstrlenW(wszCLSID_StdFont
); i
< 49; i
++)
468 wszCLSID_Broken
[i
] = 'A';
469 wszCLSID_Broken
[i
] = '\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 wszCLSID_Broken
[lstrlenW(wszCLSID_StdFont
)-1] = 'A';
477 memset(&clsid
, 0, sizeof(CLSID
));
478 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
479 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
480 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
482 wszCLSID_Broken
[lstrlenW(wszCLSID_StdFont
)] = '\0';
483 memset(&clsid
, 0, sizeof(CLSID
));
484 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
485 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
486 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
488 wszCLSID_Broken
[lstrlenW(wszCLSID_StdFont
)-1] = '\0';
489 memset(&clsid
, 0, sizeof(CLSID
));
490 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
491 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
492 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
494 memset(&clsid
, 0xcc, sizeof(CLSID
));
495 hr
= CLSIDFromString(wszCLSID_Broken
+1, &clsid
);
496 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
497 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "clsid wasn't equal to CLSID_NULL\n");
499 wszCLSID_Broken
[9] = '*';
500 memset(&clsid
, 0xcc, sizeof(CLSID
));
501 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
502 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
503 ok(clsid
.Data1
== CLSID_StdFont
.Data1
, "Got %08x\n", clsid
.Data1
);
504 ok(clsid
.Data2
== 0xcccc, "Got %04x\n", clsid
.Data2
);
506 wszCLSID_Broken
[3] = '*';
507 memset(&clsid
, 0xcc, sizeof(CLSID
));
508 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
509 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
510 ok(clsid
.Data1
== 0xb, "Got %08x\n", clsid
.Data1
);
511 ok(clsid
.Data2
== 0xcccc, "Got %04x\n", clsid
.Data2
);
513 wszCLSID_Broken
[3] = '\0';
514 memset(&clsid
, 0xcc, sizeof(CLSID
));
515 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
516 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
517 ok(clsid
.Data1
== 0xb, "Got %08x\n", clsid
.Data1
);
518 ok(clsid
.Data2
== 0xcccc, "Got %04x\n", clsid
.Data2
);
521 static void test_IIDFromString(void)
523 static const WCHAR cfW
[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-',
524 'c','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
525 static const WCHAR brokenW
[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-',
526 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
527 static const WCHAR broken2W
[] = {'{','0','0','0','0','0','0','0','1','=','0','0','0','0','-','0','0','0','0','-',
528 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
529 static const WCHAR broken3W
[] = {'b','r','o','k','e','n','0','0','1','=','0','0','0','0','-','0','0','0','0','-',
530 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
534 hr
= IIDFromString(wszCLSID_StdFont
, &iid
);
535 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
536 ok(IsEqualIID(&iid
, &CLSID_StdFont
), "got iid %s\n", wine_dbgstr_guid(&iid
));
538 memset(&iid
, 0xab, sizeof(iid
));
539 hr
= IIDFromString(NULL
, &iid
);
540 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
541 ok(IsEqualIID(&iid
, &CLSID_NULL
), "got iid %s\n", wine_dbgstr_guid(&iid
));
543 hr
= IIDFromString(cfW
, &iid
);
544 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
545 ok(IsEqualIID(&iid
, &IID_IClassFactory
), "got iid %s\n", wine_dbgstr_guid(&iid
));
547 /* string starts with a valid IID but is longer */
548 memset(&iid
, 0xab, sizeof(iid
));
549 hr
= IIDFromString(cf_brokenW
, &iid
);
550 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
551 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
553 /* invalid IID in a valid format */
554 memset(&iid
, 0xab, sizeof(iid
));
555 hr
= IIDFromString(brokenW
, &iid
);
556 ok(hr
== CO_E_IIDSTRING
, "got 0x%08x\n", hr
);
557 ok(iid
.Data1
== 0x00000001, "Got %08x\n", iid
.Data1
);
559 memset(&iid
, 0xab, sizeof(iid
));
560 hr
= IIDFromString(broken2W
, &iid
);
561 ok(hr
== CO_E_IIDSTRING
, "got 0x%08x\n", hr
);
562 ok(iid
.Data1
== 0x00000001, "Got %08x\n", iid
.Data1
);
564 /* format is broken, but string length is okay */
565 memset(&iid
, 0xab, sizeof(iid
));
566 hr
= IIDFromString(broken3W
, &iid
);
567 ok(hr
== CO_E_IIDSTRING
, "got 0x%08x\n", hr
);
568 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
571 memset(&iid
, 0xab, sizeof(iid
));
572 hr
= IIDFromString(wszNonExistent
, &iid
);
573 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
574 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
577 memset(&iid
, 0xab, sizeof(iid
));
578 hr
= IIDFromString(stdfont
, &iid
);
579 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
580 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
583 static void test_StringFromGUID2(void)
588 /* invalid pointer */
589 SetLastError(0xdeadbeef);
590 len
= StringFromGUID2(NULL
,str
,50);
591 ok(len
== 0, "len: %d (expected 0)\n", len
);
592 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %x\n", GetLastError());
594 /* Test corner cases for buffer size */
595 len
= StringFromGUID2(&CLSID_StdFont
,str
,50);
596 ok(len
== 39, "len: %d (expected 39)\n", len
);
597 ok(!lstrcmpiW(str
, wszCLSID_StdFont
),"string wasn't equal for CLSID_StdFont\n");
599 memset(str
,0,sizeof str
);
600 len
= StringFromGUID2(&CLSID_StdFont
,str
,39);
601 ok(len
== 39, "len: %d (expected 39)\n", len
);
602 ok(!lstrcmpiW(str
, wszCLSID_StdFont
),"string wasn't equal for CLSID_StdFont\n");
604 len
= StringFromGUID2(&CLSID_StdFont
,str
,38);
605 ok(len
== 0, "len: %d (expected 0)\n", len
);
607 len
= StringFromGUID2(&CLSID_StdFont
,str
,30);
608 ok(len
== 0, "len: %d (expected 0)\n", len
);
611 #define test_apt_type(t, q) _test_apt_type(t, q, __LINE__)
612 static void _test_apt_type(APTTYPE expected_type
, APTTYPEQUALIFIER expected_qualifier
, int line
)
614 APTTYPEQUALIFIER qualifier
= ~0u;
618 if (!pCoGetApartmentType
)
621 hr
= pCoGetApartmentType(&type
, &qualifier
);
622 ok_(__FILE__
, line
)(hr
== S_OK
|| hr
== CO_E_NOTINITIALIZED
, "Unexpected return code: 0x%08x\n", hr
);
623 ok_(__FILE__
, line
)(type
== expected_type
, "Wrong apartment type %d, expected %d\n", type
, expected_type
);
624 ok_(__FILE__
, line
)(qualifier
== expected_qualifier
, "Wrong apartment qualifier %d, expected %d\n", qualifier
,
628 static void test_CoCreateInstance(void)
632 REFCLSID rclsid
= &CLSID_InternetZoneManager
;
634 pUnk
= (IUnknown
*)0xdeadbeef;
635 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
636 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
637 ok(pUnk
== NULL
, "CoCreateInstance should have changed the passed in pointer to NULL, instead of %p\n", pUnk
);
641 /* test errors returned for non-registered clsids */
642 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
643 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered inproc server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
644 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_INPROC_HANDLER
, &IID_IUnknown
, (void **)&pUnk
);
645 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered inproc handler should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
646 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_LOCAL_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
647 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered local server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
648 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_REMOTE_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
649 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered remote server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
651 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
652 if(hr
== REGDB_E_CLASSNOTREG
)
654 skip("IE not installed so can't test CoCreateInstance\n");
659 ok_ole_success(hr
, "CoCreateInstance");
660 if(pUnk
) IUnknown_Release(pUnk
);
663 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
664 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
666 test_apt_type(APTTYPE_CURRENT
, APTTYPEQUALIFIER_NONE
);
669 static void test_CoGetClassObject(void)
675 REFCLSID rclsid
= &CLSID_InternetZoneManager
;
679 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
680 ok(hr
== CO_E_NOTINITIALIZED
, "CoGetClassObject should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
681 ok(pUnk
== NULL
, "CoGetClassObject should have changed the passed in pointer to NULL, instead of %p\n", pUnk
);
683 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, NULL
);
684 ok(hr
== E_INVALIDARG
||
685 broken(hr
== CO_E_NOTINITIALIZED
), /* win9x */
686 "CoGetClassObject should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
688 test_apt_type(APTTYPE_CURRENT
, APTTYPEQUALIFIER_NONE
);
690 if (!pRegOverridePredefKey
)
692 win_skip("RegOverridePredefKey not available\n");
696 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
698 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
701 IUnknown_Release(pUnk
);
703 res
= RegCreateKeyExA(HKEY_CURRENT_USER
, "Software\\Classes", 0, NULL
, 0,
704 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
);
705 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
707 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, hkey
);
708 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
710 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
711 ok(hr
== S_OK
, "CoGetClassObject should have returned S_OK instead of 0x%08x\n", hr
);
713 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, NULL
);
714 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
716 if (hr
== S_OK
) IUnknown_Release(pUnk
);
720 hr
= CoGetClassObject(&CLSID_InProcFreeMarshaler
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
721 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
722 IUnknown_Release(pUnk
);
724 /* context redefines FreeMarshaler CLSID */
725 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
727 hr
= CoGetClassObject(&CLSID_InProcFreeMarshaler
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
728 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
729 IUnknown_Release(pUnk
);
731 pDeactivateActCtx(0, cookie
);
732 pReleaseActCtx(handle
);
738 static void test_CoCreateInstanceEx(void)
740 MULTI_QI qi_res
= { &IID_IMoniker
};
746 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
747 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
748 ok_ole_success(hr
, "CoRegisterClassObject");
750 create_instance_iid
= IID_NULL
;
751 hr
= CoCreateInstanceEx(&CLSID_WineOOPTest
, NULL
, CLSCTX_INPROC_SERVER
, NULL
, 1, &qi_res
);
752 ok(hr
== E_NOINTERFACE
, "CoCreateInstanceEx failed: %08x\n", hr
);
753 ok(IsEqualGUID(&create_instance_iid
, qi_res
.pIID
), "Unexpected CreateInstance iid %s\n",
754 wine_dbgstr_guid(&create_instance_iid
));
756 hr
= CoRevokeClassObject(cookie
);
757 ok_ole_success(hr
, "CoRevokeClassObject");
762 static ATOM
register_dummy_class(void)
770 GetModuleHandleA(NULL
),
772 LoadCursorA(NULL
, (LPSTR
)IDC_ARROW
),
773 (HBRUSH
)(COLOR_BTNFACE
+1),
778 return RegisterClassA(&wc
);
781 static void test_ole_menu(void)
786 hwndFrame
= CreateWindowA((LPCSTR
)MAKEINTATOM(register_dummy_class()), "Test", 0, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, NULL
, NULL
, NULL
, NULL
);
787 hr
= OleSetMenuDescriptor(NULL
, hwndFrame
, NULL
, NULL
, NULL
);
788 todo_wine
ok_ole_success(hr
, "OleSetMenuDescriptor");
790 DestroyWindow(hwndFrame
);
794 static HRESULT WINAPI
MessageFilter_QueryInterface(IMessageFilter
*iface
, REFIID riid
, void ** ppvObj
)
796 if (ppvObj
== NULL
) return E_POINTER
;
798 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
799 IsEqualGUID(riid
, &IID_IClassFactory
))
802 IMessageFilter_AddRef(iface
);
806 return E_NOINTERFACE
;
809 static ULONG WINAPI
MessageFilter_AddRef(IMessageFilter
*iface
)
811 return 2; /* non-heap object */
814 static ULONG WINAPI
MessageFilter_Release(IMessageFilter
*iface
)
816 return 1; /* non-heap object */
819 static DWORD WINAPI
MessageFilter_HandleInComingCall(
820 IMessageFilter
*iface
,
822 HTASK threadIDCaller
,
824 LPINTERFACEINFO lpInterfaceInfo
)
826 trace("HandleInComingCall\n");
827 return SERVERCALL_ISHANDLED
;
830 static DWORD WINAPI
MessageFilter_RetryRejectedCall(
831 IMessageFilter
*iface
,
832 HTASK threadIDCallee
,
836 trace("RetryRejectedCall\n");
840 static DWORD WINAPI
MessageFilter_MessagePending(
841 IMessageFilter
*iface
,
842 HTASK threadIDCallee
,
846 trace("MessagePending\n");
847 todo_wine
ok(0, "unexpected call\n");
848 return PENDINGMSG_WAITNOPROCESS
;
851 static const IMessageFilterVtbl MessageFilter_Vtbl
=
853 MessageFilter_QueryInterface
,
854 MessageFilter_AddRef
,
855 MessageFilter_Release
,
856 MessageFilter_HandleInComingCall
,
857 MessageFilter_RetryRejectedCall
,
858 MessageFilter_MessagePending
861 static IMessageFilter MessageFilter
= { &MessageFilter_Vtbl
};
863 static void test_CoRegisterMessageFilter(void)
866 IMessageFilter
*prev_filter
;
868 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
869 ok(hr
== CO_E_NOT_SUPPORTED
,
870 "CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08x\n",
873 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
874 prev_filter
= (IMessageFilter
*)0xdeadbeef;
875 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
876 ok(hr
== CO_E_NOT_SUPPORTED
,
877 "CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08x\n",
879 ok(prev_filter
== (IMessageFilter
*)0xdeadbeef,
880 "prev_filter should have been set to %p\n", prev_filter
);
883 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
885 hr
= CoRegisterMessageFilter(NULL
, NULL
);
886 ok_ole_success(hr
, "CoRegisterMessageFilter");
888 prev_filter
= (IMessageFilter
*)0xdeadbeef;
889 hr
= CoRegisterMessageFilter(NULL
, &prev_filter
);
890 ok_ole_success(hr
, "CoRegisterMessageFilter");
891 ok(prev_filter
== NULL
, "prev_filter should have been set to NULL instead of %p\n", prev_filter
);
893 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
894 ok_ole_success(hr
, "CoRegisterMessageFilter");
895 ok(prev_filter
== NULL
, "prev_filter should have been set to NULL instead of %p\n", prev_filter
);
897 hr
= CoRegisterMessageFilter(NULL
, NULL
);
898 ok_ole_success(hr
, "CoRegisterMessageFilter");
903 static IUnknown Test_Unknown
;
905 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
907 return IUnknown_QueryInterface(&Test_Unknown
, riid
, ppv
);
910 static ULONG WINAPI
EnumOLEVERB_AddRef(IEnumOLEVERB
*iface
)
915 static ULONG WINAPI
EnumOLEVERB_Release(IEnumOLEVERB
*iface
)
920 static HRESULT WINAPI
EnumOLEVERB_Next(IEnumOLEVERB
*iface
, ULONG celt
, OLEVERB
*rgelt
, ULONG
*fetched
)
922 ok(0, "unexpected call\n");
926 static HRESULT WINAPI
EnumOLEVERB_Skip(IEnumOLEVERB
*iface
, ULONG celt
)
928 ok(0, "unexpected call\n");
932 static HRESULT WINAPI
EnumOLEVERB_Reset(IEnumOLEVERB
*iface
)
934 ok(0, "unexpected call\n");
938 static HRESULT WINAPI
EnumOLEVERB_Clone(IEnumOLEVERB
*iface
, IEnumOLEVERB
**ppenum
)
940 ok(0, "unexpected call\n");
944 static const IEnumOLEVERBVtbl EnumOLEVERBVtbl
= {
945 EnumOLEVERB_QueryInterface
,
954 static IEnumOLEVERB EnumOLEVERB
= { &EnumOLEVERBVtbl
};
956 static HRESULT WINAPI
Test_IUnknown_QueryInterface(
961 if (ppvObj
== NULL
) return E_POINTER
;
963 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IWineTest
)) {
965 }else if(IsEqualIID(riid
, &IID_IEnumOLEVERB
)) {
966 *ppvObj
= &EnumOLEVERB
;
969 return E_NOINTERFACE
;
972 IUnknown_AddRef((IUnknown
*)*ppvObj
);
976 static ULONG WINAPI
Test_IUnknown_AddRef(IUnknown
*iface
)
978 return 2; /* non-heap-based object */
981 static ULONG WINAPI
Test_IUnknown_Release(IUnknown
*iface
)
983 return 1; /* non-heap-based object */
986 static const IUnknownVtbl TestUnknown_Vtbl
=
988 Test_IUnknown_QueryInterface
,
989 Test_IUnknown_AddRef
,
990 Test_IUnknown_Release
,
993 static IUnknown Test_Unknown
= { &TestUnknown_Vtbl
};
995 static IPSFactoryBuffer
*ps_factory_buffer
;
997 static HRESULT WINAPI
PSFactoryBuffer_QueryInterface(
998 IPSFactoryBuffer
* This
,
999 /* [in] */ REFIID riid
,
1000 /* [iid_is][out] */ void **ppvObject
)
1002 if (IsEqualIID(riid
, &IID_IUnknown
) ||
1003 IsEqualIID(riid
, &IID_IPSFactoryBuffer
))
1006 IPSFactoryBuffer_AddRef(This
);
1009 return E_NOINTERFACE
;
1012 static ULONG WINAPI
PSFactoryBuffer_AddRef(
1013 IPSFactoryBuffer
* This
)
1018 static ULONG WINAPI
PSFactoryBuffer_Release(
1019 IPSFactoryBuffer
* This
)
1024 static HRESULT WINAPI
PSFactoryBuffer_CreateProxy(
1025 IPSFactoryBuffer
* This
,
1026 /* [in] */ IUnknown
*pUnkOuter
,
1027 /* [in] */ REFIID riid
,
1028 /* [out] */ IRpcProxyBuffer
**ppProxy
,
1029 /* [out] */ void **ppv
)
1034 static HRESULT WINAPI
PSFactoryBuffer_CreateStub(
1035 IPSFactoryBuffer
* This
,
1036 /* [in] */ REFIID riid
,
1037 /* [unique][in] */ IUnknown
*pUnkServer
,
1038 /* [out] */ IRpcStubBuffer
**ppStub
)
1040 CHECK_EXPECT(CreateStub
);
1042 ok(pUnkServer
== (IUnknown
*)&Test_Unknown
, "unexpected pUnkServer %p\n", pUnkServer
);
1043 if(!ps_factory_buffer
)
1046 return IPSFactoryBuffer_CreateStub(ps_factory_buffer
, &IID_IEnumOLEVERB
, pUnkServer
, ppStub
);
1049 static IPSFactoryBufferVtbl PSFactoryBufferVtbl
=
1051 PSFactoryBuffer_QueryInterface
,
1052 PSFactoryBuffer_AddRef
,
1053 PSFactoryBuffer_Release
,
1054 PSFactoryBuffer_CreateProxy
,
1055 PSFactoryBuffer_CreateStub
1058 static IPSFactoryBuffer PSFactoryBuffer
= { &PSFactoryBufferVtbl
};
1060 static const CLSID CLSID_WineTestPSFactoryBuffer
=
1065 {0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd}
1066 }; /* 52011640-8164-4fd0-a1a2-5d5a3654d3bd */
1068 static DWORD CALLBACK
register_ps_clsid_thread(void *context
)
1073 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1075 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1076 ok_ole_success(hr
, "CoGetPSClsid");
1077 ok(IsEqualGUID(&clsid
, &CLSID_WineTestPSFactoryBuffer
), "expected %s, got %s\n",
1078 wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer
), wine_dbgstr_guid(&clsid
));
1080 /* test registering a PSClsid in an apartment which is then destroyed */
1081 hr
= CoRegisterPSClsid(&IID_TestPS
, &clsid
);
1082 ok_ole_success(hr
, "CoRegisterPSClsid");
1089 static void test_CoRegisterPSClsid(void)
1092 DWORD dwRegistrationKey
;
1098 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
1099 ok(hr
== CO_E_NOTINITIALIZED
, "CoRegisterPSClsid should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
1101 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1103 hr
= CoRegisterClassObject(&CLSID_WineTestPSFactoryBuffer
, (IUnknown
*)&PSFactoryBuffer
,
1104 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &dwRegistrationKey
);
1105 ok_ole_success(hr
, "CoRegisterClassObject");
1107 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
1108 ok_ole_success(hr
, "CoRegisterPSClsid");
1110 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1111 ok_ole_success(hr
, "CoGetPSClsid");
1112 ok(IsEqualGUID(&clsid
, &CLSID_WineTestPSFactoryBuffer
), "expected %s, got %s\n",
1113 wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer
), wine_dbgstr_guid(&clsid
));
1115 thread
= CreateThread(NULL
, 0, register_ps_clsid_thread
, NULL
, 0, &tid
);
1116 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1117 ok(!WaitForSingleObject(thread
, 10000), "wait timed out\n");
1118 CloseHandle(thread
);
1120 hr
= CoGetPSClsid(&IID_TestPS
, &clsid
);
1121 ok_ole_success(hr
, "CoGetPSClsid");
1122 ok(IsEqualGUID(&clsid
, &CLSID_WineTestPSFactoryBuffer
), "expected %s, got %s\n",
1123 wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer
), wine_dbgstr_guid(&clsid
));
1125 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
1126 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1128 SET_EXPECT(CreateStub
);
1129 hr
= CoMarshalInterface(stream
, &IID_IWineTest
, &Test_Unknown
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1130 ok(hr
== E_NOTIMPL
, "CoMarshalInterface should have returned E_NOTIMPL instead of 0x%08x\n", hr
);
1131 CHECK_CALLED(CreateStub
);
1133 hr
= CoGetPSClsid(&IID_IEnumOLEVERB
, &clsid
);
1134 ok_ole_success(hr
, "CoGetPSClsid");
1136 hr
= CoGetClassObject(&clsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IPSFactoryBuffer
, (void **)&ps_factory_buffer
);
1137 ok_ole_success(hr
, "CoGetClassObject");
1139 hr
= CoRegisterPSClsid(&IID_IEnumOLEVERB
, &CLSID_WineTestPSFactoryBuffer
);
1140 ok_ole_success(hr
, "CoRegisterPSClsid");
1142 SET_EXPECT(CreateStub
);
1143 hr
= CoMarshalInterface(stream
, &IID_IEnumOLEVERB
, (IUnknown
*)&EnumOLEVERB
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1144 ok(hr
== S_OK
, "CoMarshalInterface should have returned S_OK instead of 0x%08x\n", hr
);
1145 CHECK_CALLED(CreateStub
);
1147 hr
= CoMarshalInterface(stream
, &IID_IEnumOLEVERB
, &Test_Unknown
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1148 ok(hr
== S_OK
, "CoMarshalInterface should have returned S_OK instead of 0x%08x\n", hr
);
1150 IStream_Release(stream
);
1151 IPSFactoryBuffer_Release(ps_factory_buffer
);
1152 ps_factory_buffer
= NULL
;
1154 hr
= CoRevokeClassObject(dwRegistrationKey
);
1155 ok_ole_success(hr
, "CoRevokeClassObject");
1159 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1161 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1162 ok(hr
== REGDB_E_IIDNOTREG
, "CoGetPSClsid should have returned REGDB_E_IIDNOTREG instead of 0x%08x\n", hr
);
1164 hr
= CoGetPSClsid(&IID_TestPS
, &clsid
);
1165 ok(hr
== REGDB_E_IIDNOTREG
, "CoGetPSClsid should have returned REGDB_E_IIDNOTREG instead of 0x%08x\n", hr
);
1169 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
1171 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
1172 ok_ole_success(hr
, "CoRegisterPSClsid");
1174 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1175 ok_ole_success(hr
, "CoGetPSClsid");
1176 ok(IsEqualGUID(&clsid
, &CLSID_WineTestPSFactoryBuffer
), "expected %s, got %s\n",
1177 wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer
), wine_dbgstr_guid(&clsid
));
1179 thread
= CreateThread(NULL
, 0, register_ps_clsid_thread
, NULL
, 0, &tid
);
1180 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1181 ok(!WaitForSingleObject(thread
, 10000), "wait timed out\n");
1182 CloseHandle(thread
);
1184 hr
= CoGetPSClsid(&IID_TestPS
, &clsid
);
1185 ok_ole_success(hr
, "CoGetPSClsid");
1186 ok(IsEqualGUID(&clsid
, &CLSID_WineTestPSFactoryBuffer
), "expected %s, got %s\n",
1187 wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer
), wine_dbgstr_guid(&clsid
));
1192 static void test_CoGetPSClsid(void)
1200 const BOOL is_win64
= (sizeof(void*) != sizeof(int));
1201 BOOL is_wow64
= FALSE
;
1203 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1204 ok(hr
== CO_E_NOTINITIALIZED
,
1205 "CoGetPSClsid should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n",
1208 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1210 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1211 ok_ole_success(hr
, "CoGetPSClsid");
1213 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1214 ok(hr
== REGDB_E_IIDNOTREG
,
1215 "CoGetPSClsid for random IID returned 0x%08x instead of REGDB_E_IIDNOTREG\n",
1218 hr
= CoGetPSClsid(&IID_IClassFactory
, NULL
);
1219 ok(hr
== E_INVALIDARG
,
1220 "CoGetPSClsid for null clsid returned 0x%08x instead of E_INVALIDARG\n",
1223 if (!pRegOverridePredefKey
)
1225 win_skip("RegOverridePredefKey not available\n");
1229 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1230 ok_ole_success(hr
, "CoGetPSClsid");
1232 res
= RegCreateKeyExA(HKEY_CURRENT_USER
, "Software\\Classes", 0, NULL
, 0,
1233 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
);
1234 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1236 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, hkey
);
1237 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
1239 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1240 ok_ole_success(hr
, "CoGetPSClsid");
1242 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, NULL
);
1243 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
1247 /* not registered CLSID */
1248 hr
= CoGetPSClsid(&IID_Testiface
, &clsid
);
1249 ok(hr
== REGDB_E_IIDNOTREG
, "got 0x%08x\n", hr
);
1251 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
1253 memset(&clsid
, 0, sizeof(clsid
));
1254 hr
= CoGetPSClsid(&IID_Testiface
, &clsid
);
1255 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1256 ok(IsEqualGUID(&clsid
, &IID_Testiface
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1258 memset(&clsid
, 0, sizeof(clsid
));
1259 hr
= CoGetPSClsid(&IID_Testiface2
, &clsid
);
1260 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1261 ok(IsEqualGUID(&clsid
, &IID_Testiface2
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1263 memset(&clsid
, 0, sizeof(clsid
));
1264 hr
= CoGetPSClsid(&IID_Testiface3
, &clsid
);
1265 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1266 ok(IsEqualGUID(&clsid
, &IID_TestPS
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1268 memset(&clsid
, 0xaa, sizeof(clsid
));
1269 hr
= CoGetPSClsid(&IID_Testiface4
, &clsid
);
1270 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1271 ok(IsEqualGUID(&clsid
, &GUID_NULL
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1273 /* register same interface and try to get CLSID back */
1274 hr
= CoRegisterPSClsid(&IID_Testiface
, &IID_Testiface4
);
1275 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1276 memset(&clsid
, 0, sizeof(clsid
));
1277 hr
= CoGetPSClsid(&IID_Testiface
, &clsid
);
1278 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1279 ok(IsEqualGUID(&clsid
, &IID_Testiface4
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1281 pDeactivateActCtx(0, cookie
);
1282 pReleaseActCtx(handle
);
1285 if (pRegDeleteKeyExA
&&
1287 (pIsWow64Process
&& pIsWow64Process(GetCurrentProcess(), &is_wow64
) && is_wow64
)))
1289 static GUID IID_DeadBeef
= {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
1290 static const char clsidDeadBeef
[] = "{deadbeef-dead-beef-dead-beefdeadbeef}";
1291 static const char clsidA
[] = "{66666666-8888-7777-6666-555555555555}";
1292 HKEY hkey_iface
, hkey_psclsid
;
1293 REGSAM opposite
= is_win64
? KEY_WOW64_32KEY
: KEY_WOW64_64KEY
;
1295 hr
= CoGetPSClsid(&IID_DeadBeef
, &clsid
);
1296 ok(hr
== REGDB_E_IIDNOTREG
, "got 0x%08x\n", hr
);
1298 res
= RegCreateKeyExA(HKEY_CLASSES_ROOT
, "Interface",
1299 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
, NULL
, &hkey_iface
, NULL
);
1300 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1301 res
= RegCreateKeyExA(hkey_iface
, clsidDeadBeef
,
1302 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
, NULL
, &hkey
, NULL
);
1303 if (res
== ERROR_ACCESS_DENIED
)
1305 win_skip("Failed to create a key, skipping some of CoGetPSClsid() tests\n");
1309 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1310 res
= RegCreateKeyExA(hkey
, "ProxyStubClsid32",
1311 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
, NULL
, &hkey_psclsid
, NULL
);
1312 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1313 res
= RegSetValueExA(hkey_psclsid
, NULL
, 0, REG_SZ
, (const BYTE
*)clsidA
, strlen(clsidA
)+1);
1314 ok(!res
, "RegSetValueEx returned %d\n", res
);
1315 RegCloseKey(hkey_psclsid
);
1317 hr
= CoGetPSClsid(&IID_DeadBeef
, &clsid
);
1318 ok_ole_success(hr
, "CoGetPSClsid");
1319 ok(IsEqualGUID(&clsid
, &IID_TestPS
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1321 res
= pRegDeleteKeyExA(hkey
, "ProxyStubClsid32", opposite
, 0);
1322 ok(!res
, "RegDeleteKeyEx returned %d\n", res
);
1324 res
= pRegDeleteKeyExA(hkey_iface
, clsidDeadBeef
, opposite
, 0);
1325 ok(!res
, "RegDeleteKeyEx returned %d\n", res
);
1328 RegCloseKey(hkey_iface
);
1334 /* basic test, mainly for invalid arguments. see marshal.c for more */
1335 static void test_CoUnmarshalInterface(void)
1341 hr
= CoUnmarshalInterface(NULL
, &IID_IUnknown
, (void **)&pProxy
);
1342 ok(hr
== E_INVALIDARG
, "CoUnmarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1344 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
1345 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1347 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, (void **)&pProxy
);
1349 ok(hr
== CO_E_NOTINITIALIZED
, "CoUnmarshalInterface should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
1351 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1353 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, (void **)&pProxy
);
1354 ok(hr
== STG_E_READFAULT
, "CoUnmarshalInterface should have returned STG_E_READFAULT instead of 0x%08x\n", hr
);
1358 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, NULL
);
1359 ok(hr
== E_INVALIDARG
, "CoUnmarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1361 IStream_Release(pStream
);
1364 static void test_CoGetInterfaceAndReleaseStream(void)
1369 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1371 hr
= CoGetInterfaceAndReleaseStream(NULL
, &IID_IUnknown
, (void**)&pUnk
);
1372 ok(hr
== E_INVALIDARG
, "hr %08x\n", hr
);
1377 /* basic test, mainly for invalid arguments. see marshal.c for more */
1378 static void test_CoMarshalInterface(void)
1382 static const LARGE_INTEGER llZero
;
1384 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1386 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
1387 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1389 hr
= CoMarshalInterface(pStream
, &IID_IUnknown
, NULL
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1390 ok(hr
== E_INVALIDARG
, "CoMarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1392 hr
= CoMarshalInterface(NULL
, &IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1393 ok(hr
== E_INVALIDARG
, "CoMarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1395 hr
= CoMarshalInterface(pStream
, &IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1396 ok_ole_success(hr
, "CoMarshalInterface");
1398 /* stream not rewound */
1399 hr
= CoReleaseMarshalData(pStream
);
1400 ok(hr
== STG_E_READFAULT
, "CoReleaseMarshalData should have returned STG_E_READFAULT instead of 0x%08x\n", hr
);
1402 hr
= IStream_Seek(pStream
, llZero
, STREAM_SEEK_SET
, NULL
);
1403 ok_ole_success(hr
, "IStream_Seek");
1405 hr
= CoReleaseMarshalData(pStream
);
1406 ok_ole_success(hr
, "CoReleaseMarshalData");
1408 IStream_Release(pStream
);
1413 static void test_CoMarshalInterThreadInterfaceInStream(void)
1417 IClassFactory
*pProxy
;
1419 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1423 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, NULL
);
1424 ok(hr
== E_INVALIDARG
, "CoMarshalInterThreadInterfaceInStream should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1426 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, NULL
, &pStream
);
1427 ok(hr
== E_INVALIDARG
, "CoMarshalInterThreadInterfaceInStream should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1431 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, &pStream
);
1432 ok_ole_success(hr
, "CoMarshalInterThreadInterfaceInStream");
1434 ok_more_than_one_lock();
1436 hr
= CoUnmarshalInterface(pStream
, &IID_IClassFactory
, (void **)&pProxy
);
1437 ok_ole_success(hr
, "CoUnmarshalInterface");
1439 IClassFactory_Release(pProxy
);
1440 IStream_Release(pStream
);
1447 static void test_CoRegisterClassObject(void)
1449 ULONG_PTR ctxcookie
;
1455 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1457 /* CLSCTX_INPROC_SERVER */
1458 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1459 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1460 ok_ole_success(hr
, "CoRegisterClassObject");
1461 hr
= CoRevokeClassObject(cookie
);
1462 ok_ole_success(hr
, "CoRevokeClassObject");
1464 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1465 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
1466 ok_ole_success(hr
, "CoRegisterClassObject");
1467 hr
= CoRevokeClassObject(cookie
);
1468 ok_ole_success(hr
, "CoRevokeClassObject");
1470 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1471 CLSCTX_INPROC_SERVER
, REGCLS_MULTI_SEPARATE
, &cookie
);
1472 ok_ole_success(hr
, "CoRegisterClassObject");
1473 hr
= CoRevokeClassObject(cookie
);
1474 ok_ole_success(hr
, "CoRevokeClassObject");
1476 /* CLSCTX_LOCAL_SERVER */
1477 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1478 CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1479 ok_ole_success(hr
, "CoRegisterClassObject");
1480 hr
= CoRevokeClassObject(cookie
);
1481 ok_ole_success(hr
, "CoRevokeClassObject");
1483 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1484 CLSCTX_LOCAL_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
1485 ok_ole_success(hr
, "CoRegisterClassObject");
1486 hr
= CoRevokeClassObject(cookie
);
1487 ok_ole_success(hr
, "CoRevokeClassObject");
1489 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1490 CLSCTX_LOCAL_SERVER
, REGCLS_MULTI_SEPARATE
, &cookie
);
1491 ok_ole_success(hr
, "CoRegisterClassObject");
1492 hr
= CoRevokeClassObject(cookie
);
1493 ok_ole_success(hr
, "CoRevokeClassObject");
1495 /* CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER */
1496 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1497 CLSCTX_INPROC_SERVER
|CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1498 ok_ole_success(hr
, "CoRegisterClassObject");
1499 hr
= CoRevokeClassObject(cookie
);
1500 ok_ole_success(hr
, "CoRevokeClassObject");
1502 /* test whether an object that doesn't support IClassFactory can be
1503 * registered for CLSCTX_LOCAL_SERVER */
1504 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, &Test_Unknown
,
1505 CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1506 ok_ole_success(hr
, "CoRegisterClassObject");
1507 hr
= CoRevokeClassObject(cookie
);
1508 ok_ole_success(hr
, "CoRevokeClassObject");
1510 /* test whether registered class becomes invalid when apartment is destroyed */
1511 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1512 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1513 ok_ole_success(hr
, "CoRegisterClassObject");
1516 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1518 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
,
1519 &IID_IClassFactory
, (void **)&pcf
);
1520 ok(hr
== REGDB_E_CLASSNOTREG
, "object registered in an apartment shouldn't accessible after it is destroyed\n");
1522 /* crashes with at least win9x DCOM! */
1524 CoRevokeClassObject(cookie
);
1526 /* test that object is accessible */
1527 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
, CLSCTX_INPROC_SERVER
,
1528 REGCLS_MULTIPLEUSE
, &cookie
);
1529 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1531 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&pcf
);
1532 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1533 IClassFactory_Release(pcf
);
1535 /* context now contains CLSID_WineOOPTest, test if registered one could still be used */
1536 if ((handle
= activate_context(actctx_manifest
, &ctxcookie
)))
1538 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&pcf
);
1540 ok(hr
== HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND
), "got 0x%08x\n", hr
);
1542 pDeactivateActCtx(0, ctxcookie
);
1543 pReleaseActCtx(handle
);
1546 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&pcf
);
1547 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1548 IClassFactory_Release(pcf
);
1550 hr
= CoRevokeClassObject(cookie
);
1551 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1556 static HRESULT
get_class_object(CLSCTX clsctx
)
1561 hr
= CoGetClassObject(&CLSID_WineOOPTest
, clsctx
, NULL
, &IID_IClassFactory
,
1565 IClassFactory_Release(pcf
);
1570 static DWORD CALLBACK
get_class_object_thread(LPVOID pv
)
1572 CLSCTX clsctx
= (CLSCTX
)(DWORD_PTR
)pv
;
1575 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1577 hr
= get_class_object(clsctx
);
1584 static DWORD CALLBACK
get_class_object_proxy_thread(LPVOID pv
)
1586 CLSCTX clsctx
= (CLSCTX
)(DWORD_PTR
)pv
;
1591 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1593 hr
= CoGetClassObject(&CLSID_WineOOPTest
, clsctx
, NULL
, &IID_IClassFactory
,
1598 hr
= IClassFactory_QueryInterface(pcf
, &IID_IMultiQI
, (void **)&pMQI
);
1600 IMultiQI_Release(pMQI
);
1601 IClassFactory_Release(pcf
);
1609 static DWORD CALLBACK
register_class_object_thread(LPVOID pv
)
1614 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1616 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1617 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1624 static DWORD CALLBACK
revoke_class_object_thread(LPVOID pv
)
1626 DWORD cookie
= (DWORD_PTR
)pv
;
1629 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1631 hr
= CoRevokeClassObject(cookie
);
1638 static void test_registered_object_thread_affinity(void)
1646 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1648 /* CLSCTX_INPROC_SERVER */
1650 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1651 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1652 ok_ole_success(hr
, "CoRegisterClassObject");
1654 thread
= CreateThread(NULL
, 0, get_class_object_thread
, (LPVOID
)CLSCTX_INPROC_SERVER
, 0, &tid
);
1655 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1656 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1657 GetExitCodeThread(thread
, &exitcode
);
1659 ok(hr
== REGDB_E_CLASSNOTREG
, "CoGetClassObject on inproc object "
1660 "registered in different thread should return REGDB_E_CLASSNOTREG "
1661 "instead of 0x%08x\n", hr
);
1663 hr
= get_class_object(CLSCTX_INPROC_SERVER
);
1664 ok(hr
== S_OK
, "CoGetClassObject on inproc object registered in same "
1665 "thread should return S_OK instead of 0x%08x\n", hr
);
1667 thread
= CreateThread(NULL
, 0, register_class_object_thread
, NULL
, 0, &tid
);
1668 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1669 ok ( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1670 GetExitCodeThread(thread
, &exitcode
);
1672 ok(hr
== S_OK
, "CoRegisterClassObject with same CLSID but in different thread should return S_OK instead of 0x%08x\n", hr
);
1674 hr
= CoRevokeClassObject(cookie
);
1675 ok_ole_success(hr
, "CoRevokeClassObject");
1677 /* CLSCTX_LOCAL_SERVER */
1679 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1680 CLSCTX_LOCAL_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
1681 ok_ole_success(hr
, "CoRegisterClassObject");
1683 thread
= CreateThread(NULL
, 0, get_class_object_proxy_thread
, (LPVOID
)CLSCTX_LOCAL_SERVER
, 0, &tid
);
1684 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1685 while (MsgWaitForMultipleObjects(1, &thread
, FALSE
, 10000, QS_ALLINPUT
) == WAIT_OBJECT_0
+ 1)
1688 while (PeekMessageA(&msg
, NULL
, 0, 0, PM_REMOVE
))
1690 TranslateMessage(&msg
);
1691 DispatchMessageA(&msg
);
1694 GetExitCodeThread(thread
, &exitcode
);
1696 ok(hr
== S_OK
, "CoGetClassObject on local server object "
1697 "registered in different thread should return S_OK "
1698 "instead of 0x%08x\n", hr
);
1700 hr
= get_class_object(CLSCTX_LOCAL_SERVER
);
1701 ok(hr
== S_OK
, "CoGetClassObject on local server object registered in same "
1702 "thread should return S_OK instead of 0x%08x\n", hr
);
1704 thread
= CreateThread(NULL
, 0, revoke_class_object_thread
, (LPVOID
)(DWORD_PTR
)cookie
, 0, &tid
);
1705 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1706 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1707 GetExitCodeThread(thread
, &exitcode
);
1709 ok(hr
== RPC_E_WRONG_THREAD
|| broken(hr
== S_OK
) /* win8 */, "CoRevokeClassObject called from different "
1710 "thread to where registered should return RPC_E_WRONG_THREAD instead of 0x%08x\n", hr
);
1712 thread
= CreateThread(NULL
, 0, register_class_object_thread
, NULL
, 0, &tid
);
1713 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1714 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1715 GetExitCodeThread(thread
, &exitcode
);
1717 ok(hr
== S_OK
, "CoRegisterClassObject with same CLSID but in different "
1718 "thread should return S_OK instead of 0x%08x\n", hr
);
1720 hr
= CoRevokeClassObject(cookie
);
1721 ok_ole_success(hr
, "CoRevokeClassObject");
1726 static DWORD CALLBACK
free_libraries_thread(LPVOID p
)
1728 CoFreeUnusedLibraries();
1732 static inline BOOL
is_module_loaded(const char *module
)
1734 return GetModuleHandleA(module
) != 0;
1737 static void test_CoFreeUnusedLibraries(void)
1744 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1746 ok(!is_module_loaded("urlmon.dll"), "urlmon.dll shouldn't be loaded\n");
1748 hr
= CoCreateInstance(&CLSID_FileProtocol
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IInternetProtocol
, (void **)&pUnk
);
1749 if (hr
== REGDB_E_CLASSNOTREG
)
1751 skip("IE not installed so can't run CoFreeUnusedLibraries test\n");
1755 ok_ole_success(hr
, "CoCreateInstance");
1757 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1760 broken(pUnk
== NULL
), /* win9x */
1761 "Expected a valid pointer\n");
1763 IUnknown_Release(pUnk
);
1765 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1767 thread
= CreateThread(NULL
, 0, free_libraries_thread
, NULL
, 0, &tid
);
1768 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1769 CloseHandle(thread
);
1771 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1773 CoFreeUnusedLibraries();
1775 ok(!is_module_loaded("urlmon.dll"), "urlmon.dll shouldn't be loaded\n");
1780 static void test_CoGetObjectContext(void)
1784 IComThreadingInfo
*pComThreadingInfo
, *threadinginfo2
;
1785 IContextCallback
*pContextCallback
;
1786 IObjContext
*pObjContext
;
1791 if (!pCoGetObjectContext
)
1793 win_skip("CoGetObjectContext not present\n");
1797 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1798 ok(hr
== CO_E_NOTINITIALIZED
, "CoGetObjectContext should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
1799 ok(pComThreadingInfo
== NULL
, "pComThreadingInfo should have been set to NULL\n");
1801 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1803 test_apt_type(APTTYPE_MAINSTA
, APTTYPEQUALIFIER_NONE
);
1805 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1806 ok_ole_success(hr
, "CoGetObjectContext");
1808 threadinginfo2
= NULL
;
1809 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&threadinginfo2
);
1810 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
1811 ok(pComThreadingInfo
== threadinginfo2
, "got different instance\n");
1812 IComThreadingInfo_Release(threadinginfo2
);
1814 hr
= IComThreadingInfo_GetCurrentLogicalThreadId(pComThreadingInfo
, NULL
);
1815 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
1817 id
= id2
= GUID_NULL
;
1818 hr
= IComThreadingInfo_GetCurrentLogicalThreadId(pComThreadingInfo
, &id
);
1819 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1821 hr
= CoGetCurrentLogicalThreadId(&id2
);
1822 ok(IsEqualGUID(&id
, &id2
), "got %s, expected %s\n", wine_dbgstr_guid(&id
), wine_dbgstr_guid(&id2
));
1824 hr
= IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo
, &apttype
);
1825 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentApartmentType");
1826 ok(apttype
== APTTYPE_MAINSTA
, "apartment type should be APTTYPE_MAINSTA instead of %d\n", apttype
);
1828 hr
= IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo
, &thdtype
);
1829 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentThreadType");
1830 ok(thdtype
== THDTYPE_PROCESSMESSAGES
, "thread type should be THDTYPE_PROCESSMESSAGES instead of %d\n", thdtype
);
1832 refs
= IComThreadingInfo_Release(pComThreadingInfo
);
1833 ok(refs
== 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs
);
1835 hr
= pCoGetObjectContext(&IID_IContextCallback
, (void **)&pContextCallback
);
1836 ok_ole_success(hr
, "CoGetObjectContext(ContextCallback)");
1838 refs
= IContextCallback_Release(pContextCallback
);
1839 ok(refs
== 0, "pContextCallback should have 0 refs instead of %d refs\n", refs
);
1843 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
1845 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1846 ok_ole_success(hr
, "CoGetObjectContext");
1848 hr
= IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo
, &apttype
);
1849 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentApartmentType");
1850 ok(apttype
== APTTYPE_MTA
, "apartment type should be APTTYPE_MTA instead of %d\n", apttype
);
1852 hr
= IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo
, &thdtype
);
1853 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentThreadType");
1854 ok(thdtype
== THDTYPE_BLOCKMESSAGES
, "thread type should be THDTYPE_BLOCKMESSAGES instead of %d\n", thdtype
);
1856 refs
= IComThreadingInfo_Release(pComThreadingInfo
);
1857 ok(refs
== 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs
);
1859 hr
= pCoGetObjectContext(&IID_IContextCallback
, (void **)&pContextCallback
);
1860 ok_ole_success(hr
, "CoGetObjectContext(ContextCallback)");
1862 refs
= IContextCallback_Release(pContextCallback
);
1863 ok(refs
== 0, "pContextCallback should have 0 refs instead of %d refs\n", refs
);
1865 hr
= pCoGetObjectContext(&IID_IObjContext
, (void **)&pObjContext
);
1866 ok_ole_success(hr
, "CoGetObjectContext");
1868 refs
= IObjContext_Release(pObjContext
);
1869 ok(refs
== 0, "pObjContext should have 0 refs instead of %d refs\n", refs
);
1875 IUnknown IUnknown_iface
;
1879 static inline Test_CallContext
*impl_from_IUnknown(IUnknown
*iface
)
1881 return CONTAINING_RECORD(iface
, Test_CallContext
, IUnknown_iface
);
1884 static HRESULT WINAPI
Test_CallContext_QueryInterface(
1889 if (ppvObj
== NULL
) return E_POINTER
;
1891 if (IsEqualGUID(riid
, &IID_IUnknown
))
1894 IUnknown_AddRef(iface
);
1899 return E_NOINTERFACE
;
1902 static ULONG WINAPI
Test_CallContext_AddRef(IUnknown
*iface
)
1904 Test_CallContext
*This
= impl_from_IUnknown(iface
);
1905 return InterlockedIncrement(&This
->refs
);
1908 static ULONG WINAPI
Test_CallContext_Release(IUnknown
*iface
)
1910 Test_CallContext
*This
= impl_from_IUnknown(iface
);
1911 ULONG refs
= InterlockedDecrement(&This
->refs
);
1913 HeapFree(GetProcessHeap(), 0, This
);
1917 static const IUnknownVtbl TestCallContext_Vtbl
=
1919 Test_CallContext_QueryInterface
,
1920 Test_CallContext_AddRef
,
1921 Test_CallContext_Release
1924 static void test_CoGetCallContext(void)
1929 Test_CallContext
*test_object
;
1931 if (!pCoSwitchCallContext
)
1933 skip("CoSwitchCallContext not present\n");
1939 test_object
= HeapAlloc(GetProcessHeap(), 0, sizeof(Test_CallContext
));
1940 test_object
->IUnknown_iface
.lpVtbl
= &TestCallContext_Vtbl
;
1941 test_object
->refs
= 1;
1943 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
1944 ok(hr
== RPC_E_CALL_COMPLETE
, "Expected RPC_E_CALL_COMPLETE, got 0x%08x\n", hr
);
1946 pUnk
= (IUnknown
*)0xdeadbeef;
1947 hr
= pCoSwitchCallContext(&test_object
->IUnknown_iface
, &pUnk
);
1948 ok_ole_success(hr
, "CoSwitchCallContext");
1949 ok(pUnk
== NULL
, "expected NULL, got %p\n", pUnk
);
1950 refs
= IUnknown_AddRef(&test_object
->IUnknown_iface
);
1951 ok(refs
== 2, "Expected refcount 2, got %d\n", refs
);
1952 IUnknown_Release(&test_object
->IUnknown_iface
);
1954 pUnk
= (IUnknown
*)0xdeadbeef;
1955 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
1956 ok_ole_success(hr
, "CoGetCallContext");
1957 ok(pUnk
== &test_object
->IUnknown_iface
, "expected %p, got %p\n",
1958 &test_object
->IUnknown_iface
, pUnk
);
1959 refs
= IUnknown_AddRef(&test_object
->IUnknown_iface
);
1960 ok(refs
== 3, "Expected refcount 3, got %d\n", refs
);
1961 IUnknown_Release(&test_object
->IUnknown_iface
);
1962 IUnknown_Release(pUnk
);
1964 pUnk
= (IUnknown
*)0xdeadbeef;
1965 hr
= pCoSwitchCallContext(NULL
, &pUnk
);
1966 ok_ole_success(hr
, "CoSwitchCallContext");
1967 ok(pUnk
== &test_object
->IUnknown_iface
, "expected %p, got %p\n",
1968 &test_object
->IUnknown_iface
, pUnk
);
1969 refs
= IUnknown_AddRef(&test_object
->IUnknown_iface
);
1970 ok(refs
== 2, "Expected refcount 2, got %d\n", refs
);
1971 IUnknown_Release(&test_object
->IUnknown_iface
);
1973 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
1974 ok(hr
== RPC_E_CALL_COMPLETE
, "Expected RPC_E_CALL_COMPLETE, got 0x%08x\n", hr
);
1976 IUnknown_Release(&test_object
->IUnknown_iface
);
1981 static void test_CoGetContextToken(void)
1985 ULONG_PTR token
, token2
;
1988 if (!pCoGetContextToken
)
1990 win_skip("CoGetContextToken not present\n");
1995 hr
= pCoGetContextToken(&token
);
1996 ok(hr
== CO_E_NOTINITIALIZED
, "Expected CO_E_NOTINITIALIZED, got 0x%08x\n", hr
);
1997 ok(token
== 0xdeadbeef, "Expected 0, got 0x%lx\n", token
);
1999 test_apt_type(APTTYPE_CURRENT
, APTTYPEQUALIFIER_NONE
);
2003 test_apt_type(APTTYPE_MAINSTA
, APTTYPEQUALIFIER_NONE
);
2005 hr
= pCoGetContextToken(NULL
);
2006 ok(hr
== E_POINTER
, "Expected E_POINTER, got 0x%08x\n", hr
);
2009 hr
= pCoGetContextToken(&token
);
2010 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2011 ok(token
, "Expected token != 0\n");
2014 hr
= pCoGetContextToken(&token2
);
2015 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2016 ok(token2
== token
, "got different token\n");
2018 refs
= IUnknown_AddRef((IUnknown
*)token
);
2019 ok(refs
== 1, "Expected 1, got %u\n", refs
);
2021 hr
= pCoGetObjectContext(&IID_IObjContext
, (void **)&ctx
);
2022 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2023 ok(ctx
== (IObjContext
*)token
, "Expected interface pointers to be the same\n");
2025 refs
= IObjContext_AddRef(ctx
);
2026 ok(refs
== 3, "Expected 3, got %u\n", refs
);
2028 refs
= IObjContext_Release(ctx
);
2029 ok(refs
== 2, "Expected 2, got %u\n", refs
);
2031 refs
= IUnknown_Release((IUnknown
*)token
);
2032 ok(refs
== 1, "Expected 1, got %u\n", refs
);
2034 /* CoGetContextToken does not add a reference */
2036 hr
= pCoGetContextToken(&token
);
2037 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2038 ok(token
, "Expected token != 0\n");
2039 ok(ctx
== (IObjContext
*)token
, "Expected interface pointers to be the same\n");
2041 refs
= IObjContext_AddRef(ctx
);
2042 ok(refs
== 2, "Expected 1, got %u\n", refs
);
2044 refs
= IObjContext_Release(ctx
);
2045 ok(refs
== 1, "Expected 0, got %u\n", refs
);
2047 refs
= IObjContext_Release(ctx
);
2048 ok(refs
== 0, "Expected 0, got %u\n", refs
);
2053 static void test_TreatAsClass(void)
2057 static GUID deadbeef
= {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
2058 static const char deadbeefA
[] = "{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}";
2059 IInternetProtocol
*pIP
= NULL
;
2060 HKEY clsidkey
, deadbeefkey
;
2063 if (!pCoGetTreatAsClass
)
2065 win_skip("CoGetTreatAsClass not present\n");
2069 hr
= pCoGetTreatAsClass(&deadbeef
,&out
);
2070 ok (hr
== S_FALSE
, "expected S_FALSE got %x\n",hr
);
2071 ok (IsEqualGUID(&out
,&deadbeef
), "expected to get same clsid back\n");
2073 hr
= pCoGetTreatAsClass(NULL
, &out
);
2074 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG got %08x\n", hr
);
2075 ok(IsEqualGUID(&out
, &deadbeef
), "expected no change to the clsid\n");
2077 hr
= pCoGetTreatAsClass(&deadbeef
, NULL
);
2078 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG got %08x\n", hr
);
2080 lr
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "CLSID", 0, KEY_READ
, &clsidkey
);
2081 ok(!lr
, "Couldn't open CLSID key, error %d\n", lr
);
2083 lr
= RegCreateKeyExA(clsidkey
, deadbeefA
, 0, NULL
, 0, KEY_WRITE
, NULL
, &deadbeefkey
, NULL
);
2085 win_skip("CoGetTreatAsClass() tests will be skipped (failed to create a test key, error %d)\n", lr
);
2086 RegCloseKey(clsidkey
);
2090 hr
= pCoTreatAsClass(&deadbeef
, &deadbeef
);
2091 ok(hr
== REGDB_E_WRITEREGDB
, "CoTreatAsClass gave wrong error: %08x\n", hr
);
2093 hr
= pCoTreatAsClass(&deadbeef
, &CLSID_FileProtocol
);
2094 if(hr
== REGDB_E_WRITEREGDB
){
2095 win_skip("Insufficient privileges to use CoTreatAsClass\n");
2098 ok(hr
== S_OK
, "CoTreatAsClass failed: %08x\n", hr
);
2100 hr
= pCoGetTreatAsClass(&deadbeef
, &out
);
2101 ok(hr
== S_OK
, "CoGetTreatAsClass failed: %08x\n",hr
);
2102 ok(IsEqualGUID(&out
, &CLSID_FileProtocol
), "expected to get substituted clsid\n");
2104 OleInitialize(NULL
);
2106 hr
= CoCreateInstance(&deadbeef
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IInternetProtocol
, (void **)&pIP
);
2107 if(hr
== REGDB_E_CLASSNOTREG
)
2109 win_skip("IE not installed so can't test CoCreateInstance\n");
2113 ok(hr
== S_OK
, "CoCreateInstance failed: %08x\n", hr
);
2115 IInternetProtocol_Release(pIP
);
2119 hr
= pCoTreatAsClass(&deadbeef
, &CLSID_NULL
);
2120 ok(hr
== S_OK
, "CoTreatAsClass failed: %08x\n", hr
);
2122 hr
= pCoGetTreatAsClass(&deadbeef
, &out
);
2123 ok(hr
== S_FALSE
, "expected S_FALSE got %08x\n", hr
);
2124 ok(IsEqualGUID(&out
, &deadbeef
), "expected to get same clsid back\n");
2126 /* bizarrely, native's CoTreatAsClass takes some time to take effect in CoCreateInstance */
2129 hr
= CoCreateInstance(&deadbeef
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IInternetProtocol
, (void **)&pIP
);
2130 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance gave wrong error: %08x\n", hr
);
2133 IInternetProtocol_Release(pIP
);
2137 RegCloseKey(deadbeefkey
);
2138 RegDeleteKeyA(clsidkey
, deadbeefA
);
2139 RegCloseKey(clsidkey
);
2142 static void test_CoInitializeEx(void)
2146 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2147 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2149 /* Calling OleInitialize for the first time should yield S_OK even with
2150 * apartment already initialized by previous CoInitialize(Ex) calls. */
2151 hr
= OleInitialize(NULL
);
2152 ok(hr
== S_OK
, "OleInitialize failed with error 0x%08x\n", hr
);
2154 /* Subsequent calls to OleInitialize should return S_FALSE */
2155 hr
= OleInitialize(NULL
);
2156 ok(hr
== S_FALSE
, "Expected S_FALSE, hr = 0x%08x\n", hr
);
2164 static void test_OleInitialize_InitCounting(void)
2168 REFCLSID rclsid
= &CLSID_InternetZoneManager
;
2170 /* 1. OleInitialize fails but OleUninitialize is still called: apartment stays initialized */
2171 hr
= pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
2172 ok(hr
== S_OK
, "CoInitializeEx(COINIT_MULTITHREADED) failed with error 0x%08x\n", hr
);
2174 hr
= OleInitialize(NULL
);
2175 ok(hr
== RPC_E_CHANGED_MODE
, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", RPC_E_CHANGED_MODE
, hr
);
2178 pUnk
= (IUnknown
*)0xdeadbeef;
2179 hr
= CoCreateInstance(rclsid
, NULL
, 0x17, &IID_IUnknown
, (void **)&pUnk
);
2180 ok(hr
== S_OK
, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", S_OK
, hr
);
2181 if (pUnk
) IUnknown_Release(pUnk
);
2185 /* 2. Extra multiple OleUninitialize: apartment stays initialized until CoUninitialize */
2186 hr
= CoInitialize(NULL
);
2187 ok(hr
== S_OK
, "CoInitialize() failed with error 0x%08x\n", hr
);
2189 hr
= OleInitialize(NULL
);
2190 ok(hr
== S_OK
, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", S_OK
, hr
);
2195 pUnk
= (IUnknown
*)0xdeadbeef;
2196 hr
= CoCreateInstance(rclsid
, NULL
, 0x17, &IID_IUnknown
, (void **)&pUnk
);
2197 ok(hr
== S_OK
, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", S_OK
, hr
);
2198 if (pUnk
) IUnknown_Release(pUnk
);
2202 pUnk
= (IUnknown
*)0xdeadbeef;
2203 hr
= CoCreateInstance(rclsid
, NULL
, 0x17, &IID_IUnknown
, (void **)&pUnk
);
2204 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", CO_E_NOTINITIALIZED
, hr
);
2205 if (pUnk
) IUnknown_Release(pUnk
);
2207 /* 3. CoUninitialize does not formally deinit Ole */
2208 hr
= CoInitialize(NULL
);
2209 ok(hr
== S_OK
, "CoInitialize() failed with error 0x%08x\n", hr
);
2211 hr
= OleInitialize(NULL
);
2212 ok(hr
== S_OK
, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", S_OK
, hr
);
2217 pUnk
= (IUnknown
*)0xdeadbeef;
2218 hr
= CoCreateInstance(rclsid
, NULL
, 0x17, &IID_IUnknown
, (void **)&pUnk
);
2219 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", CO_E_NOTINITIALIZED
, hr
);
2220 /* COM is not initialized anymore */
2221 if (pUnk
) IUnknown_Release(pUnk
);
2223 hr
= OleInitialize(NULL
);
2224 ok(hr
== S_FALSE
, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", S_FALSE
, hr
);
2225 /* ... but native OleInit returns S_FALSE as if Ole is considered initialized */
2231 static void test_OleRegGetMiscStatus(void)
2238 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_ICON
, NULL
);
2239 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2241 status
= 0xdeadbeef;
2242 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_ICON
, &status
);
2243 ok(hr
== REGDB_E_CLASSNOTREG
, "got 0x%08x\n", hr
);
2244 ok(status
== 0, "got 0x%08x\n", status
);
2247 hr
= OleRegGetMiscStatus(&CLSID_StdFont
, DVASPECT_ICON
, &status
);
2248 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2249 ok(status
== 0, "got 0x%08x\n", status
);
2251 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
2254 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_ICON
, &status
);
2255 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2256 ok(status
== OLEMISC_RECOMPOSEONRESIZE
, "got 0x%08x\n", status
);
2258 /* context data takes precedence over registration info */
2260 hr
= OleRegGetMiscStatus(&CLSID_StdFont
, DVASPECT_ICON
, &status
);
2261 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2262 ok(status
== OLEMISC_RECOMPOSEONRESIZE
, "got 0x%08x\n", status
);
2264 /* there's no such attribute in context */
2266 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_DOCPRINT
, &status
);
2267 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2268 ok(status
== 0, "got 0x%08x\n", status
);
2270 pDeactivateActCtx(0, cookie
);
2271 pReleaseActCtx(handle
);
2275 static void test_OleRegGetUserType(void)
2277 static const WCHAR stdfont_usertypeW
[] = {'S','t','a','n','d','a','r','d',' ','F','o','n','t',0};
2278 static const WCHAR stdfont2_usertypeW
[] = {'C','L','S','I','D','_','S','t','d','F','o','n','t',0};
2279 static const WCHAR clsidkeyW
[] = {'C','L','S','I','D',0};
2280 static const WCHAR defvalueW
[] = {'D','e','f','a','u','l','t',' ','N','a','m','e',0};
2281 static const WCHAR auxvalue0W
[] = {'A','u','x',' ','N','a','m','e',' ','0',0};
2282 static const WCHAR auxvalue2W
[] = {'A','u','x',' ','N','a','m','e',' ','2',0};
2283 static const WCHAR auxvalue3W
[] = {'A','u','x',' ','N','a','m','e',' ','3',0};
2284 static const WCHAR auxvalue4W
[] = {'A','u','x',' ','N','a','m','e',' ','4',0};
2286 static const char auxvalues
[][16] = {
2294 HKEY clsidhkey
, hkey
, auxhkey
, classkey
;
2295 DWORD form
, ret
, disposition
;
2303 for (form
= 0; form
<= USERCLASSTYPE_APPNAME
+1; form
++) {
2304 hr
= OleRegGetUserType(&CLSID_Testclass
, form
, NULL
);
2305 ok(hr
== E_INVALIDARG
, "form %u: got 0x%08x\n", form
, hr
);
2307 str
= (void*)0xdeadbeef;
2308 hr
= OleRegGetUserType(&CLSID_Testclass
, form
, &str
);
2309 ok(hr
== REGDB_E_CLASSNOTREG
, "form %u: got 0x%08x\n", form
, hr
);
2310 ok(str
== NULL
, "form %u: got %p\n", form
, str
);
2312 /* same string returned for StdFont for all form types */
2314 hr
= OleRegGetUserType(&CLSID_StdFont
, form
, &str
);
2315 ok(hr
== S_OK
, "form %u: got 0x%08x\n", form
, hr
);
2316 ok(!lstrcmpW(str
, stdfont_usertypeW
) || !lstrcmpW(str
, stdfont2_usertypeW
) /* winxp */,
2317 "form %u, got %s\n", form
, wine_dbgstr_w(str
));
2321 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
2323 for (form
= 0; form
<= USERCLASSTYPE_APPNAME
+1; form
++) {
2324 str
= (void*)0xdeadbeef;
2325 hr
= OleRegGetUserType(&CLSID_Testclass
, form
, &str
);
2326 ok(hr
== REGDB_E_CLASSNOTREG
, "form %u: got 0x%08x\n", form
, hr
);
2327 ok(str
== NULL
, "form %u: got %s\n", form
, wine_dbgstr_w(str
));
2329 /* same string returned for StdFont for all form types */
2331 hr
= OleRegGetUserType(&CLSID_StdFont
, form
, &str
);
2332 ok(hr
== S_OK
, "form %u: got 0x%08x\n", form
, hr
);
2333 ok(!lstrcmpW(str
, stdfont_usertypeW
) || !lstrcmpW(str
, stdfont2_usertypeW
) /* winxp */,
2334 "form %u, got %s\n", form
, wine_dbgstr_w(str
));
2338 pDeactivateActCtx(0, cookie
);
2339 pReleaseActCtx(handle
);
2342 /* test using registered CLSID */
2343 StringFromGUID2(&CLSID_non_existent
, clsidW
, sizeof(clsidW
)/sizeof(clsidW
[0]));
2345 ret
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, clsidkeyW
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &clsidhkey
, &disposition
);
2348 ret
= RegCreateKeyExW(clsidhkey
, clsidW
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &classkey
, NULL
);
2350 RegCloseKey(clsidhkey
);
2353 if (ret
== ERROR_ACCESS_DENIED
)
2355 win_skip("Failed to create test key, skipping some of OleRegGetUserType() tests.\n");
2359 ok(!ret
, "failed to create a key, error %d\n", ret
);
2361 ret
= RegSetValueExW(classkey
, NULL
, 0, REG_SZ
, (const BYTE
*)defvalueW
, sizeof(defvalueW
));
2362 ok(!ret
, "got error %d\n", ret
);
2364 ret
= RegCreateKeyExA(classkey
, "AuxUserType", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &auxhkey
, NULL
);
2365 ok(!ret
, "got error %d\n", ret
);
2367 /* populate AuxUserType */
2368 for (i
= 0; i
<= 4; i
++) {
2371 sprintf(name
, "AuxUserType\\%d", i
);
2372 ret
= RegCreateKeyExA(classkey
, name
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
);
2373 ok(!ret
, "got error %d\n", ret
);
2375 ret
= RegSetValueExA(hkey
, NULL
, 0, REG_SZ
, (const BYTE
*)auxvalues
[i
], strlen(auxvalues
[i
]));
2376 ok(!ret
, "got error %d\n", ret
);
2381 hr
= OleRegGetUserType(&CLSID_non_existent
, 0, &str
);
2382 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2383 ok(!lstrcmpW(str
, auxvalue0W
), "got %s\n", wine_dbgstr_w(str
));
2387 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_FULL
, &str
);
2388 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2389 ok(!lstrcmpW(str
, defvalueW
), "got %s\n", wine_dbgstr_w(str
));
2393 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_SHORT
, &str
);
2394 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2395 ok(!lstrcmpW(str
, auxvalue2W
), "got %s\n", wine_dbgstr_w(str
));
2399 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_APPNAME
, &str
);
2400 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2401 ok(!lstrcmpW(str
, auxvalue3W
), "got %s\n", wine_dbgstr_w(str
));
2405 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_APPNAME
+1, &str
);
2406 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2407 ok(!lstrcmpW(str
, auxvalue4W
), "got %s\n", wine_dbgstr_w(str
));
2411 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_APPNAME
+2, &str
);
2412 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2413 ok(!lstrcmpW(str
, defvalueW
), "got %s\n", wine_dbgstr_w(str
));
2416 /* registry cleanup */
2417 for (i
= 0; i
<= 4; i
++)
2420 sprintf(name
, "%d", i
);
2421 RegDeleteKeyA(auxhkey
, name
);
2423 RegCloseKey(auxhkey
);
2424 RegDeleteKeyA(classkey
, "AuxUserType");
2425 RegCloseKey(classkey
);
2426 RegDeleteKeyW(clsidhkey
, clsidW
);
2427 RegCloseKey(clsidhkey
);
2428 if (disposition
== REG_CREATED_NEW_KEY
)
2429 RegDeleteKeyA(HKEY_CLASSES_ROOT
, "CLSID");
2432 static void test_CoCreateGuid(void)
2436 hr
= CoCreateGuid(NULL
);
2437 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2440 static void CALLBACK
apc_test_proc(ULONG_PTR param
)
2445 static DWORD CALLBACK
release_semaphore_thread( LPVOID arg
)
2447 HANDLE handle
= arg
;
2448 if (WaitForSingleObject(handle
, 200) == WAIT_TIMEOUT
)
2449 ReleaseSemaphore(handle
, 1, NULL
);
2453 static DWORD CALLBACK
send_message_thread(LPVOID arg
)
2457 SendMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2461 static DWORD CALLBACK
send_and_post_user_message_thread(void *arg
)
2465 SendMessageA(hwnd
, WM_USER
, 0, 0);
2466 PostMessageA(hwnd
, WM_USER
, 0, 0);
2470 static DWORD CALLBACK
post_message_thread(LPVOID arg
)
2474 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2478 static const char cls_name
[] = "cowait_test_class";
2480 static UINT cowait_msgs
[100], cowait_msgs_first
, cowait_msgs_last
;
2482 static void cowait_msgs_reset(void)
2484 cowait_msgs_first
= cowait_msgs_last
= 0;
2487 #define cowait_msgs_expect_empty() _cowait_msgs_expect_empty(__LINE__)
2488 static void _cowait_msgs_expect_empty(unsigned line
)
2490 while(cowait_msgs_first
< cowait_msgs_last
) {
2491 ok_(__FILE__
,line
)(0, "unexpected message %u\n", cowait_msgs
[cowait_msgs_first
]);
2492 cowait_msgs_first
++;
2494 cowait_msgs_reset();
2497 #define cowait_msgs_expect_notified(a) _cowait_msgs_expect_notified(__LINE__,a)
2498 static void _cowait_msgs_expect_notified(unsigned line
, UINT expected_msg
)
2500 if(cowait_msgs_first
== cowait_msgs_last
) {
2501 ok_(__FILE__
,line
)(0, "expected message %u, received none\n", expected_msg
);
2503 ok_(__FILE__
,line
)(cowait_msgs
[cowait_msgs_first
] == expected_msg
,
2504 "expected message %u, received %u \n",
2505 expected_msg
, cowait_msgs
[cowait_msgs_first
]);
2506 cowait_msgs_first
++;
2510 #define cowait_msgs_expect_queued(a,b) _cowait_msgs_expect_queued(__LINE__,a,b)
2511 static void _cowait_msgs_expect_queued(unsigned line
, HWND hwnd
, UINT expected_msg
)
2516 success
= PeekMessageA(&msg
, hwnd
, expected_msg
, expected_msg
, PM_REMOVE
);
2517 ok_(__FILE__
,line
)(success
, "PeekMessageA failed: %u\n", GetLastError());
2519 ok_(__FILE__
,line
)(msg
.message
== expected_msg
, "unexpected message %u, expected %u\n",
2520 msg
.message
, expected_msg
);
2523 static void flush_messages(void)
2526 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
));
2529 static LRESULT CALLBACK
cowait_window_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2531 if(cowait_msgs_last
< sizeof(cowait_msgs
)/sizeof(*cowait_msgs
))
2532 cowait_msgs
[cowait_msgs_last
++] = msg
;
2533 if(msg
== WM_DDE_FIRST
)
2535 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
2538 static DWORD CALLBACK
cowait_unmarshal_thread(void *arg
)
2540 IStream
*stream
= arg
;
2541 IEnumOLEVERB
*enum_verb
;
2549 hr
= IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
2550 ok(hr
== S_OK
, "Seek failed: %08x\n", hr
);
2552 hr
= CoUnmarshalInterface(stream
, &IID_IUnknown
, (void**)&unk
);
2553 ok(hr
== S_OK
, "CoUnmarshalInterface failed: %08x\n", hr
);
2555 hr
= IUnknown_QueryInterface(unk
, &IID_IEnumOLEVERB
, (void**)&enum_verb
);
2556 ok(hr
== S_OK
, "QueryInterface failed: %08x\n", hr
);
2558 IEnumOLEVERB_Release(enum_verb
);
2559 IUnknown_Release(unk
);
2565 static DWORD CALLBACK
test_CoWaitForMultipleHandles_thread(LPVOID arg
)
2567 HANDLE
*handles
= arg
, event
, thread
;
2577 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2578 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2580 hWnd
= CreateWindowExA(0, cls_name
, "Test (thread)", WS_TILEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
2581 ok(hWnd
!= 0, "CreateWindowExA failed %u\n", GetLastError());
2584 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2585 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2586 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2587 ok(index
==0 || index
==0xdeadbeef/* Win 8 */, "expected index 0, got %u\n", index
);
2588 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2589 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2592 PostMessageA(hWnd
, WM_USER
, 0, 0);
2593 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2594 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2595 ok(index
==0 || index
==0xdeadbeef/* Win 8 */, "expected index 0, got %u\n", index
);
2596 success
= PeekMessageA(&msg
, hWnd
, WM_USER
, WM_USER
, PM_REMOVE
);
2597 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2599 /* Even if CoWaitForMultipleHandles does not pump a message it peeks
2602 PostMessageA(NULL
, uMSG
, 0, 0);
2604 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 2, handles
, &index
);
2605 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2606 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2608 /* Make sure message was peeked at */
2609 ret
= MsgWaitForMultipleObjectsEx(0, NULL
, 2, QS_ALLPOSTMESSAGE
, MWMO_ALERTABLE
);
2610 ok(ret
== WAIT_TIMEOUT
, "MsgWaitForMultipleObjects returned %x\n", ret
);
2612 /* But not pumped */
2613 success
= PeekMessageA(&msg
, NULL
, uMSG
, uMSG
, PM_REMOVE
);
2614 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2616 DestroyWindow(hWnd
);
2619 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2620 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2622 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
2623 ok(hr
== S_OK
, "CreateStreamOnHGlobal failed: %08x\n", hr
);
2625 hr
= CoMarshalInterface(stream
, &IID_IUnknown
, &Test_Unknown
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
2626 ok(hr
== S_OK
, "CoMarshalInterface should have returned S_OK instead of 0x%08x\n", hr
);
2628 event
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
2630 PostQuitMessage(66);
2631 PostThreadMessageW(GetCurrentThreadId(), WM_QUIT
, 0, 0);
2633 hr
= CoRegisterMessageFilter(&MessageFilter
, NULL
);
2634 ok(hr
== S_OK
, "CoRegisterMessageFilter failed: %08x\n", hr
);
2636 thread
= CreateThread(NULL
, 0, cowait_unmarshal_thread
, stream
, 0, &tid
);
2637 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2638 hr
= CoWaitForMultipleHandles(0, 50, 1, &event
, &index
);
2639 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2640 index
= WaitForSingleObject(thread
, 200);
2641 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2642 CloseHandle(thread
);
2644 hr
= CoRegisterMessageFilter(NULL
, NULL
);
2645 ok(hr
== S_OK
, "CoRegisterMessageFilter failed: %08x\n", hr
);
2647 IStream_Release(stream
);
2654 static void test_CoWaitForMultipleHandles(void)
2656 HANDLE handles
[2], thread
;
2664 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2665 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2667 memset(&wc
, 0, sizeof(wc
));
2668 wc
.cbSize
= sizeof(wc
);
2669 wc
.style
= CS_VREDRAW
| CS_HREDRAW
;
2670 wc
.hInstance
= GetModuleHandleA(0);
2671 wc
.hCursor
= LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
);
2672 wc
.hbrBackground
= NULL
;
2673 wc
.lpszClassName
= cls_name
;
2674 wc
.lpfnWndProc
= cowait_window_proc
;
2675 success
= RegisterClassExA(&wc
) != 0;
2676 ok(success
, "RegisterClassExA failed %u\n", GetLastError());
2678 hWnd
= CreateWindowExA(0, cls_name
, "Test", WS_TILEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
2679 ok(hWnd
!= 0, "CreateWindowExA failed %u\n", GetLastError());
2680 handles
[0] = CreateSemaphoreA(NULL
, 1, 1, NULL
);
2681 ok(handles
[0] != 0, "CreateSemaphoreA failed %u\n", GetLastError());
2682 handles
[1] = CreateSemaphoreA(NULL
, 1, 1, NULL
);
2683 ok(handles
[1] != 0, "CreateSemaphoreA failed %u\n", GetLastError());
2685 /* test without flags */
2687 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2688 hr
= CoWaitForMultipleHandles(0, 50, 0, handles
, NULL
);
2689 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
2690 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2691 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2694 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2695 hr
= CoWaitForMultipleHandles(0, 50, 0, NULL
, &index
);
2696 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
2697 ok(index
== 0, "expected index 0, got %u\n", index
);
2698 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2699 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2702 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2703 hr
= CoWaitForMultipleHandles(0, 50, 0, handles
, &index
);
2704 ok(hr
== RPC_E_NO_SYNC
, "expected RPC_E_NO_SYNC, got 0x%08x\n", hr
);
2705 ok(index
== 0, "expected index 0, got %u\n", index
);
2706 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2707 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2710 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2711 hr
= CoWaitForMultipleHandles(0, 50, 1, handles
, &index
);
2712 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2713 ok(index
== 0, "expected index 0, got %u\n", index
);
2714 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2715 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2718 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2719 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2720 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2721 ok(index
== 1, "expected index 1, got %u\n", index
);
2722 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2723 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2726 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2727 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2728 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2729 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2730 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2731 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2733 /* test PostMessageA/SendMessageA from a different thread */
2736 thread
= CreateThread(NULL
, 0, post_message_thread
, hWnd
, 0, &tid
);
2737 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2738 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2739 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2740 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2741 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2742 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2743 index
= WaitForSingleObject(thread
, 200);
2744 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2745 CloseHandle(thread
);
2748 thread
= CreateThread(NULL
, 0, send_message_thread
, hWnd
, 0, &tid
);
2749 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2750 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2751 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2752 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2753 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2754 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2755 index
= WaitForSingleObject(thread
, 200);
2756 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2757 CloseHandle(thread
);
2759 ReleaseSemaphore(handles
[0], 1, NULL
);
2760 ReleaseSemaphore(handles
[1], 1, NULL
);
2762 /* test with COWAIT_WAITALL */
2765 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2766 hr
= CoWaitForMultipleHandles(COWAIT_WAITALL
, 50, 2, handles
, &index
);
2767 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2768 ok(index
== 0, "expected index 0, got %u\n", index
);
2769 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2770 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2773 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2774 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2775 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2776 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2777 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2778 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2780 ReleaseSemaphore(handles
[0], 1, NULL
);
2781 ReleaseSemaphore(handles
[1], 1, NULL
);
2783 /* test with COWAIT_ALERTABLE */
2786 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2787 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 1, handles
, &index
);
2788 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2789 ok(index
== 0, "expected index 0, got %u\n", index
);
2790 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2791 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2794 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2795 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 2, handles
, &index
);
2796 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2797 ok(index
== 1, "expected index 1, got %u\n", index
);
2798 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2799 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2802 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2803 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 2, handles
, &index
);
2804 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2805 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2806 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2807 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2810 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2811 success
= QueueUserAPC(apc_test_proc
, GetCurrentThread(), 0);
2812 ok(success
, "QueueUserAPC failed %u\n", GetLastError());
2813 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 2, handles
, &index
);
2814 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2815 ok(index
== WAIT_IO_COMPLETION
, "expected index WAIT_IO_COMPLETION, got %u\n", index
);
2816 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2817 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2819 /* test with COWAIT_INPUTAVAILABLE (semaphores are still locked) */
2822 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2823 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_NOREMOVE
);
2824 ok(success
, "PeekMessageA returned FALSE\n");
2825 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2826 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2827 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2828 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2829 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2832 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2833 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_NOREMOVE
);
2834 ok(success
, "PeekMessageA returned FALSE\n");
2835 thread
= CreateThread(NULL
, 0, release_semaphore_thread
, handles
[1], 0, &tid
);
2836 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2837 hr
= CoWaitForMultipleHandles(COWAIT_INPUTAVAILABLE
, 50, 2, handles
, &index
);
2838 ok(hr
== RPC_S_CALLPENDING
|| broken(hr
== E_INVALIDARG
) || broken(hr
== S_OK
) /* Win 8 */,
2839 "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2840 if (hr
!= S_OK
) ReleaseSemaphore(handles
[1], 1, NULL
);
2841 ok(index
== 0 || broken(index
== 1) /* 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
|| broken(success
&& hr
== E_INVALIDARG
),
2844 "CoWaitForMultipleHandles didn't pump any messages\n");
2845 index
= WaitForSingleObject(thread
, 200);
2846 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2847 CloseHandle(thread
);
2849 cowait_msgs_reset();
2850 PostMessageA(hWnd
, 0, 0, 0);
2851 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2852 PostMessageA(hWnd
, WM_USER
+1, 0, 0);
2853 PostMessageA(hWnd
, WM_DDE_FIRST
+1, 0, 0);
2854 thread
= CreateThread(NULL
, 0, send_and_post_user_message_thread
, hWnd
, 0, &tid
);
2855 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2857 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2858 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2860 cowait_msgs_expect_notified(WM_DDE_FIRST
);
2861 cowait_msgs_expect_notified(WM_DDE_FIRST
+1);
2862 cowait_msgs_expect_notified(WM_USER
);
2863 cowait_msgs_expect_empty();
2864 cowait_msgs_expect_queued(hWnd
, WM_USER
);
2865 cowait_msgs_expect_queued(hWnd
, WM_USER
+1);
2868 index
= WaitForSingleObject(thread
, 200);
2869 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2870 CloseHandle(thread
);
2872 /* test behaviour of WM_QUIT (semaphores are still locked) */
2874 PostMessageA(hWnd
, WM_QUIT
, 40, 0);
2875 memset(&msg
, 0, sizeof(msg
));
2876 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2877 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2878 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2879 ok(msg
.wParam
== 40, "expected msg.wParam = 40, got %lu\n", msg
.wParam
);
2880 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2881 ok(!success
, "PeekMessageA succeeded\n");
2883 cowait_msgs_reset();
2884 PostMessageA(hWnd
, WM_QUIT
, 40, 0);
2885 PostMessageA(hWnd
, 0, 0, 0);
2886 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2887 PostMessageA(hWnd
, WM_USER
+1, 0, 0);
2888 PostMessageA(hWnd
, WM_DDE_FIRST
+1, 0, 0);
2889 thread
= CreateThread(NULL
, 0, send_and_post_user_message_thread
, hWnd
, 0, &tid
);
2890 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2892 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2893 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2895 cowait_msgs_expect_notified(WM_DDE_FIRST
);
2896 cowait_msgs_expect_notified(WM_DDE_FIRST
+1);
2897 cowait_msgs_expect_notified(WM_USER
);
2898 cowait_msgs_expect_empty();
2899 cowait_msgs_expect_queued(hWnd
, WM_USER
);
2902 index
= WaitForSingleObject(thread
, 200);
2903 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2904 CloseHandle(thread
);
2907 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2908 PostMessageA(hWnd
, WM_QUIT
, 41, 0);
2909 thread
= CreateThread(NULL
, 0, post_message_thread
, hWnd
, 0, &tid
);
2910 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2911 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2912 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2913 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2914 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2916 ok(success
|| broken(!success
) /* Win 2000/XP/8 */, "PeekMessageA failed, error %u\n", GetLastError());
2917 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2918 ok(!success
, "PeekMessageA succeeded\n");
2919 memset(&msg
, 0, sizeof(msg
));
2920 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2922 ok(!success
|| broken(success
) /* Win 2000/XP/8 */, "PeekMessageA succeeded\n");
2925 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2926 ok(msg
.wParam
== 41, "expected msg.wParam = 41, got %lu\n", msg
.wParam
);
2928 index
= WaitForSingleObject(thread
, 200);
2929 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2930 CloseHandle(thread
);
2933 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2934 PostMessageA(hWnd
, WM_QUIT
, 42, 0);
2935 thread
= CreateThread(NULL
, 0, send_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
, "CoWaitForMultipleHandles didn't pump all WM_DDE_FIRST messages\n");
2942 memset(&msg
, 0, sizeof(msg
));
2943 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2944 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2945 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2946 ok(msg
.wParam
== 42, "expected msg.wParam = 42, got %lu\n", msg
.wParam
);
2947 index
= WaitForSingleObject(thread
, 200);
2948 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2949 CloseHandle(thread
);
2951 PostQuitMessage(43);
2952 memset(&msg
, 0, sizeof(msg
));
2953 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2954 ok(success
|| broken(!success
) /* Win 8 */, "PeekMessageA failed, error %u\n", GetLastError());
2956 win_skip("PostQuitMessage didn't queue a WM_QUIT message, skipping tests\n");
2959 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2960 ok(msg
.wParam
== 43, "expected msg.wParam = 43, got %lu\n", msg
.wParam
);
2961 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2962 ok(!success
, "PeekMessageA succeeded\n");
2965 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2966 PostQuitMessage(44);
2967 thread
= CreateThread(NULL
, 0, post_message_thread
, hWnd
, 0, &tid
);
2968 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2969 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2970 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2971 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2972 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2973 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2974 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2975 ok(!success
, "PeekMessageA succeeded\n");
2976 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2977 ok(!success
, "CoWaitForMultipleHandles didn't remove WM_QUIT messages\n");
2978 index
= WaitForSingleObject(thread
, 200);
2979 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2980 CloseHandle(thread
);
2983 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2984 PostQuitMessage(45);
2985 thread
= CreateThread(NULL
, 0, send_message_thread
, hWnd
, 0, &tid
);
2986 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2987 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2988 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2989 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2990 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2991 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2992 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2993 ok(!success
, "PeekMessageA succeeded\n");
2994 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2995 ok(!success
, "CoWaitForMultipleHandles didn't remove WM_QUIT messages\n");
2996 index
= WaitForSingleObject(thread
, 200);
2997 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2998 CloseHandle(thread
);
3001 /* test message pumping when CoWaitForMultipleHandles is called from non main apartment thread */
3002 thread
= CreateThread(NULL
, 0, test_CoWaitForMultipleHandles_thread
, handles
, 0, &tid
);
3003 index
= WaitForSingleObject(thread
, 500);
3004 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
3005 CloseHandle(thread
);
3009 /* If COM was not initialized, messages are neither pumped nor peeked at */
3010 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
3011 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
3012 ok(hr
== RPC_S_CALLPENDING
, "got %#x\n", hr
);
3013 success
= MsgWaitForMultipleObjectsEx(0, NULL
, 2, QS_ALLPOSTMESSAGE
, MWMO_ALERTABLE
);
3014 ok(success
== 0, "MsgWaitForMultipleObjects returned %x\n", success
);
3015 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
3016 ok(success
, "PeekMessage failed: %u\n", GetLastError());
3018 /* same in an MTA */
3019 CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
3021 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
3022 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
3023 ok(hr
== RPC_S_CALLPENDING
, "got %#x\n", hr
);
3024 success
= MsgWaitForMultipleObjectsEx(0, NULL
, 2, QS_ALLPOSTMESSAGE
, MWMO_ALERTABLE
);
3025 ok(success
== 0, "MsgWaitForMultipleObjects returned %x\n", success
);
3026 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
3027 ok(success
, "PeekMessage failed: %u\n", GetLastError());
3031 CloseHandle(handles
[0]);
3032 CloseHandle(handles
[1]);
3033 DestroyWindow(hWnd
);
3035 success
= UnregisterClassA(cls_name
, GetModuleHandleA(0));
3036 ok(success
, "UnregisterClass failed %u\n", GetLastError());
3039 static void test_CoGetMalloc(void)
3044 if (0) /* crashes on native */
3045 hr
= CoGetMalloc(0, NULL
);
3047 imalloc
= (void*)0xdeadbeef;
3048 hr
= CoGetMalloc(0, &imalloc
);
3049 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3050 ok(imalloc
== NULL
, "got %p\n", imalloc
);
3052 imalloc
= (void*)0xdeadbeef;
3053 hr
= CoGetMalloc(MEMCTX_SHARED
, &imalloc
);
3054 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3055 ok(imalloc
== NULL
, "got %p\n", imalloc
);
3057 imalloc
= (void*)0xdeadbeef;
3058 hr
= CoGetMalloc(MEMCTX_MACSYSTEM
, &imalloc
);
3059 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3060 ok(imalloc
== NULL
, "got %p\n", imalloc
);
3062 imalloc
= (void*)0xdeadbeef;
3063 hr
= CoGetMalloc(MEMCTX_UNKNOWN
, &imalloc
);
3064 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3065 ok(imalloc
== NULL
, "got %p\n", imalloc
);
3067 imalloc
= (void*)0xdeadbeef;
3068 hr
= CoGetMalloc(MEMCTX_SAME
, &imalloc
);
3069 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3070 ok(imalloc
== NULL
, "got %p\n", imalloc
);
3073 hr
= CoGetMalloc(MEMCTX_TASK
, &imalloc
);
3074 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3075 ok(imalloc
!= NULL
, "got %p\n", imalloc
);
3076 IMalloc_Release(imalloc
);
3079 static void test_CoGetApartmentType(void)
3081 APTTYPEQUALIFIER qualifier
;
3085 if (!pCoGetApartmentType
)
3087 win_skip("CoGetApartmentType not present\n");
3091 hr
= pCoGetApartmentType(NULL
, NULL
);
3092 ok(hr
== E_INVALIDARG
, "CoGetApartmentType succeeded, error: 0x%08x\n", hr
);
3095 hr
= pCoGetApartmentType(&type
, NULL
);
3096 ok(hr
== E_INVALIDARG
, "CoGetApartmentType succeeded, error: 0x%08x\n", hr
);
3097 ok(type
== 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", type
);
3099 qualifier
= 0xdeadbeef;
3100 hr
= pCoGetApartmentType(NULL
, &qualifier
);
3101 ok(hr
== E_INVALIDARG
, "CoGetApartmentType succeeded, error: 0x%08x\n", hr
);
3102 ok(qualifier
== 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", qualifier
);
3105 qualifier
= 0xdeadbeef;
3106 hr
= pCoGetApartmentType(&type
, &qualifier
);
3107 ok(hr
== CO_E_NOTINITIALIZED
, "CoGetApartmentType succeeded, error: 0x%08x\n", hr
);
3108 ok(type
== APTTYPE_CURRENT
, "Expected APTTYPE_CURRENT, got %u\n", type
);
3109 ok(qualifier
== APTTYPEQUALIFIER_NONE
, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier
);
3112 qualifier
= 0xdeadbeef;
3113 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
3114 ok(hr
== S_OK
, "CoInitializeEx failed, error: 0x%08x\n", hr
);
3115 hr
= pCoGetApartmentType(&type
, &qualifier
);
3116 ok(hr
== S_OK
, "CoGetApartmentType failed, error: 0x%08x\n", hr
);
3117 ok(type
== APTTYPE_MAINSTA
, "Expected APTTYPE_MAINSTA, got %u\n", type
);
3118 ok(qualifier
== APTTYPEQUALIFIER_NONE
, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier
);
3122 qualifier
= 0xdeadbeef;
3123 hr
= pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
3124 ok(hr
== S_OK
, "CoInitializeEx failed, error: 0x%08x\n", hr
);
3125 hr
= pCoGetApartmentType(&type
, &qualifier
);
3126 ok(hr
== S_OK
, "CoGetApartmentType failed, error: 0x%08x\n", hr
);
3127 ok(type
== APTTYPE_MTA
, "Expected APTTYPE_MTA, got %u\n", type
);
3128 ok(qualifier
== APTTYPEQUALIFIER_NONE
, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier
);
3132 static HRESULT WINAPI
testspy_QI(IMallocSpy
*iface
, REFIID riid
, void **obj
)
3134 if (IsEqualIID(riid
, &IID_IMallocSpy
) || IsEqualIID(riid
, &IID_IUnknown
))
3137 IMallocSpy_AddRef(iface
);
3141 return E_NOINTERFACE
;
3144 static ULONG WINAPI
testspy_AddRef(IMallocSpy
*iface
)
3149 static ULONG WINAPI
testspy_Release(IMallocSpy
*iface
)
3154 static SIZE_T WINAPI
testspy_PreAlloc(IMallocSpy
*iface
, SIZE_T cb
)
3156 ok(0, "unexpected call\n");
3160 static void* WINAPI
testspy_PostAlloc(IMallocSpy
*iface
, void *ptr
)
3162 ok(0, "unexpected call\n");
3166 static void* WINAPI
testspy_PreFree(IMallocSpy
*iface
, void *ptr
, BOOL spyed
)
3168 ok(0, "unexpected call\n");
3172 static void WINAPI
testspy_PostFree(IMallocSpy
*iface
, BOOL spyed
)
3174 ok(0, "unexpected call\n");
3177 static SIZE_T WINAPI
testspy_PreRealloc(IMallocSpy
*iface
, void *ptr
, SIZE_T cb
, void **newptr
, BOOL spyed
)
3179 ok(0, "unexpected call\n");
3183 static void* WINAPI
testspy_PostRealloc(IMallocSpy
*iface
, void *ptr
, BOOL spyed
)
3185 ok(0, "unexpected call\n");
3189 static void* WINAPI
testspy_PreGetSize(IMallocSpy
*iface
, void *ptr
, BOOL spyed
)
3191 ok(0, "unexpected call\n");
3195 static SIZE_T WINAPI
testspy_PostGetSize(IMallocSpy
*iface
, SIZE_T actual
, BOOL spyed
)
3197 ok(0, "unexpected call\n");
3201 static void* WINAPI
testspy_PreDidAlloc(IMallocSpy
*iface
, void *ptr
, BOOL spyed
)
3203 ok(0, "unexpected call\n");
3207 static int WINAPI
testspy_PostDidAlloc(IMallocSpy
*iface
, void *ptr
, BOOL spyed
, int actual
)
3209 ok(0, "unexpected call\n");
3213 static void WINAPI
testspy_PreHeapMinimize(IMallocSpy
*iface
)
3215 ok(0, "unexpected call\n");
3218 static void WINAPI
testspy_PostHeapMinimize(IMallocSpy
*iface
)
3220 ok(0, "unexpected call\n");
3223 static const IMallocSpyVtbl testspyvtbl
=
3233 testspy_PostRealloc
,
3235 testspy_PostGetSize
,
3236 testspy_PreDidAlloc
,
3237 testspy_PostDidAlloc
,
3238 testspy_PreHeapMinimize
,
3239 testspy_PostHeapMinimize
3242 static IMallocSpy testspy
= { &testspyvtbl
};
3244 static void test_IMallocSpy(void)
3249 hr
= CoRegisterMallocSpy(NULL
);
3250 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3252 hr
= CoRevokeMallocSpy();
3253 ok(hr
== CO_E_OBJNOTREG
, "got 0x%08x\n", hr
);
3255 hr
= CoRegisterMallocSpy(&testspy
);
3256 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3258 hr
= CoRegisterMallocSpy(NULL
);
3259 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3261 hr
= CoRegisterMallocSpy(&testspy
);
3262 ok(hr
== CO_E_OBJISREG
, "got 0x%08x\n", hr
);
3265 hr
= CoGetMalloc(MEMCTX_TASK
, &imalloc
);
3266 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3267 ok(imalloc
!= NULL
, "got %p\n", imalloc
);
3269 IMalloc_Free(imalloc
, NULL
);
3271 IMalloc_Release(imalloc
);
3273 hr
= CoRevokeMallocSpy();
3274 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3276 hr
= CoRevokeMallocSpy();
3277 ok(hr
== CO_E_OBJNOTREG
, "got 0x%08x\n", hr
);
3280 static void test_CoGetCurrentLogicalThreadId(void)
3285 hr
= CoGetCurrentLogicalThreadId(NULL
);
3286 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3289 hr
= CoGetCurrentLogicalThreadId(&id
);
3290 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3291 ok(!IsEqualGUID(&id
, &GUID_NULL
), "got null id\n");
3294 static HRESULT WINAPI
testinitialize_QI(IInitializeSpy
*iface
, REFIID riid
, void **obj
)
3296 if (IsEqualIID(riid
, &IID_IInitializeSpy
) || IsEqualIID(riid
, &IID_IUnknown
))
3299 IInitializeSpy_AddRef(iface
);
3304 return E_NOINTERFACE
;
3307 static ULONG WINAPI
testinitialize_AddRef(IInitializeSpy
*iface
)
3312 static ULONG WINAPI
testinitialize_Release(IInitializeSpy
*iface
)
3317 static HRESULT WINAPI
testinitialize_PreInitialize(IInitializeSpy
*iface
, DWORD coinit
, DWORD aptrefs
)
3319 ok(0, "unexpected call\n");
3323 static HRESULT WINAPI
testinitialize_PostInitialize(IInitializeSpy
*iface
, HRESULT hr
, DWORD coinit
, DWORD aptrefs
)
3325 ok(0, "unexpected call\n");
3329 static HRESULT WINAPI
testinitialize_PreUninitialize(IInitializeSpy
*iface
, DWORD aptrefs
)
3331 ok(0, "unexpected call\n");
3335 static HRESULT WINAPI
testinitialize_PostUninitialize(IInitializeSpy
*iface
, DWORD aptrefs
)
3337 ok(0, "unexpected call\n");
3341 static const IInitializeSpyVtbl testinitializevtbl
=
3344 testinitialize_AddRef
,
3345 testinitialize_Release
,
3346 testinitialize_PreInitialize
,
3347 testinitialize_PostInitialize
,
3348 testinitialize_PreUninitialize
,
3349 testinitialize_PostUninitialize
3352 static IInitializeSpy testinitialize
= { &testinitializevtbl
};
3354 static void test_IInitializeSpy(void)
3356 ULARGE_INTEGER cookie
, cookie1
, cookie2
;
3359 hr
= CoRegisterInitializeSpy(NULL
, NULL
);
3360 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3362 cookie
.QuadPart
= 1;
3363 hr
= CoRegisterInitializeSpy(NULL
, &cookie
);
3364 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3365 ok(cookie
.QuadPart
== 1, "got wrong cookie\n");
3367 hr
= CoRegisterInitializeSpy(&testinitialize
, NULL
);
3368 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3370 cookie
.HighPart
= 0;
3372 hr
= CoRegisterInitializeSpy(&testinitialize
, &cookie
);
3373 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3375 ok(cookie
.HighPart
== GetCurrentThreadId(), "got high part 0x%08x, expected 0x%08x\n", cookie
.HighPart
,
3376 GetCurrentThreadId());
3377 ok(cookie
.LowPart
== 0, "got wrong low part 0x%x\n", cookie
.LowPart
);
3379 /* register same instance one more time */
3380 cookie1
.HighPart
= 0;
3381 cookie1
.LowPart
= 0;
3382 hr
= CoRegisterInitializeSpy(&testinitialize
, &cookie1
);
3384 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3385 ok(cookie1
.HighPart
== GetCurrentThreadId(), "got high part 0x%08x, expected 0x%08x\n", cookie1
.HighPart
,
3386 GetCurrentThreadId());
3387 ok(cookie1
.LowPart
== 1, "got wrong low part 0x%x\n", cookie1
.LowPart
);
3389 cookie2
.HighPart
= 0;
3390 cookie2
.LowPart
= 0;
3391 hr
= CoRegisterInitializeSpy(&testinitialize
, &cookie2
);
3393 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3394 ok(cookie2
.HighPart
== GetCurrentThreadId(), "got high part 0x%08x, expected 0x%08x\n", cookie2
.HighPart
,
3395 GetCurrentThreadId());
3396 ok(cookie2
.LowPart
== 2, "got wrong low part 0x%x\n", cookie2
.LowPart
);
3398 hr
= CoRevokeInitializeSpy(cookie1
);
3400 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3402 hr
= CoRevokeInitializeSpy(cookie1
);
3403 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3405 cookie1
.HighPart
= 0;
3406 cookie1
.LowPart
= 0;
3407 hr
= CoRegisterInitializeSpy(&testinitialize
, &cookie1
);
3409 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3410 ok(cookie1
.HighPart
== GetCurrentThreadId(), "got high part 0x%08x, expected 0x%08x\n", cookie1
.HighPart
,
3411 GetCurrentThreadId());
3412 ok(cookie1
.LowPart
== 1, "got wrong low part 0x%x\n", cookie1
.LowPart
);
3414 hr
= CoRevokeInitializeSpy(cookie
);
3415 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3417 hr
= CoRevokeInitializeSpy(cookie1
);
3419 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3421 hr
= CoRevokeInitializeSpy(cookie2
);
3423 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3426 static HRESULT g_persistfile_qi_ret
;
3427 static HRESULT g_persistfile_load_ret
;
3428 static HRESULT WINAPI
testinstance_QI(IPersistFile
*iface
, REFIID riid
, void **obj
)
3430 if (IsEqualIID(riid
, &IID_IUnknown
)) {
3432 IUnknown_AddRef(iface
);
3436 if (IsEqualIID(riid
, &IID_IPersistFile
)) {
3437 if (SUCCEEDED(g_persistfile_qi_ret
)) {
3439 IUnknown_AddRef(iface
);
3443 return g_persistfile_qi_ret
;
3446 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid
));
3448 return E_NOINTERFACE
;
3451 static ULONG WINAPI
testinstance_AddRef(IPersistFile
*iface
)
3456 static ULONG WINAPI
testinstance_Release(IPersistFile
*iface
)
3461 static HRESULT WINAPI
testinstance_GetClassID(IPersistFile
*iface
, CLSID
*clsid
)
3463 ok(0, "unexpected call\n");
3467 static HRESULT WINAPI
testinstance_IsDirty(IPersistFile
*iface
)
3469 ok(0, "unexpected call\n");
3473 static HRESULT WINAPI
testinstance_Load(IPersistFile
*iface
, LPCOLESTR filename
, DWORD mode
)
3475 return g_persistfile_load_ret
;
3478 static HRESULT WINAPI
testinstance_Save(IPersistFile
*iface
, LPCOLESTR filename
, BOOL remember
)
3483 static HRESULT WINAPI
testinstance_SaveCompleted(IPersistFile
*iface
, LPCOLESTR filename
)
3485 ok(0, "unexpected call\n");
3489 static HRESULT WINAPI
testinstance_GetCurFile(IPersistFile
*iface
, LPOLESTR
*filename
)
3491 ok(0, "unexpected call\n");
3495 static const IPersistFileVtbl testpersistfilevtbl
= {
3497 testinstance_AddRef
,
3498 testinstance_Release
,
3499 testinstance_GetClassID
,
3500 testinstance_IsDirty
,
3503 testinstance_SaveCompleted
,
3504 testinstance_GetCurFile
3507 static IPersistFile testpersistfile
= { &testpersistfilevtbl
};
3509 static HRESULT WINAPI
getinstance_cf_QI(IClassFactory
*iface
, REFIID riid
, void **obj
)
3511 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IClassFactory
)) {
3513 IClassFactory_AddRef(iface
);
3518 return E_NOINTERFACE
;
3521 static ULONG WINAPI
getinstance_cf_AddRef(IClassFactory
*iface
)
3526 static ULONG WINAPI
getinstance_cf_Release(IClassFactory
*iface
)
3531 static HRESULT WINAPI
getinstance_cf_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
,
3532 REFIID riid
, void **obj
)
3534 if (IsEqualIID(riid
, &IID_IUnknown
)) {
3535 *obj
= &testpersistfile
;
3539 ok(0, "unexpected call, riid %s\n", wine_dbgstr_guid(riid
));
3544 static HRESULT WINAPI
getinstance_cf_LockServer(IClassFactory
*iface
, BOOL lock
)
3546 ok(0, "unexpected call\n");
3550 static const IClassFactoryVtbl getinstance_cf_vtbl
= {
3552 getinstance_cf_AddRef
,
3553 getinstance_cf_Release
,
3554 getinstance_cf_CreateInstance
,
3555 getinstance_cf_LockServer
3558 static IClassFactory getinstance_cf
= { &getinstance_cf_vtbl
};
3560 static void test_CoGetInstanceFromFile(void)
3562 static const WCHAR filenameW
[] = {'d','u','m','m','y','p','a','t','h',0};
3563 CLSID
*clsid
= (CLSID
*)&CLSID_testclsid
;
3568 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
3569 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3571 /* CLSID is not specified, file does not exist */
3572 mqi
[0].pIID
= &IID_IUnknown
;
3574 mqi
[0].hr
= E_NOTIMPL
;
3575 hr
= CoGetInstanceFromFile(NULL
, NULL
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3577 ok(hr
== MK_E_CANTOPENFILE
, "got 0x%08x\n", hr
);
3578 ok(mqi
[0].pItf
== NULL
, "got %p\n", mqi
[0].pItf
);
3579 ok(mqi
[0].hr
== E_NOINTERFACE
, "got 0x%08x\n", mqi
[0].hr
);
3581 /* class is not available */
3582 mqi
[0].pIID
= &IID_IUnknown
;
3584 mqi
[0].hr
= E_NOTIMPL
;
3585 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3586 ok(hr
== REGDB_E_CLASSNOTREG
, "got 0x%08x\n", hr
);
3587 ok(mqi
[0].pItf
== NULL
, "got %p\n", mqi
[0].pItf
);
3588 ok(mqi
[0].hr
== REGDB_E_CLASSNOTREG
, "got 0x%08x\n", mqi
[0].hr
);
3590 hr
= CoRegisterClassObject(clsid
, (IUnknown
*)&getinstance_cf
, CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
,
3592 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3594 mqi
[0].pIID
= &IID_IUnknown
;
3595 mqi
[0].pItf
= (void*)0xdeadbeef;
3597 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3599 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3600 ok(mqi
[0].pItf
== (void*)0xdeadbeef, "got %p\n", mqi
[0].pItf
);
3602 ok(mqi
[0].hr
== S_OK
, "got 0x%08x\n", mqi
[0].hr
);
3604 mqi
[0].pIID
= &IID_IUnknown
;
3605 mqi
[0].pItf
= (void*)0xdeadbeef;
3606 mqi
[0].hr
= E_NOTIMPL
;
3607 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3609 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3610 ok(mqi
[0].pItf
== (void*)0xdeadbeef, "got %p\n", mqi
[0].pItf
);
3611 ok(mqi
[0].hr
== E_NOTIMPL
, "got 0x%08x\n", mqi
[0].hr
);
3613 mqi
[0].pIID
= &IID_IUnknown
;
3615 mqi
[0].hr
= E_NOTIMPL
;
3616 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3617 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3618 ok(mqi
[0].pItf
!= NULL
, "got %p\n", mqi
[0].pItf
);
3619 ok(mqi
[0].hr
== S_OK
, "got 0x%08x\n", mqi
[0].hr
);
3621 mqi
[0].pIID
= &IID_IUnknown
;
3624 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3625 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3626 ok(mqi
[0].pItf
!= NULL
, "got %p\n", mqi
[0].pItf
);
3627 ok(mqi
[0].hr
== S_OK
, "got 0x%08x\n", mqi
[0].hr
);
3629 mqi
[0].pIID
= &IID_IUnknown
;
3632 g_persistfile_qi_ret
= S_FALSE
;
3633 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 1, mqi
);
3634 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3635 ok(mqi
[0].pItf
!= NULL
, "got %p\n", mqi
[0].pItf
);
3636 ok(mqi
[0].hr
== S_OK
, "got 0x%08x\n", mqi
[0].hr
);
3637 g_persistfile_qi_ret
= S_OK
;
3639 mqi
[0].pIID
= &IID_IUnknown
;
3642 mqi
[1].pIID
= &IID_IUnknown
;
3645 g_persistfile_qi_ret
= 0x8000efef;
3646 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 2, mqi
);
3647 ok(hr
== 0x8000efef, "got 0x%08x\n", hr
);
3648 ok(mqi
[0].pItf
== NULL
, "got %p\n", mqi
[0].pItf
);
3649 ok(mqi
[0].hr
== 0x8000efef, "got 0x%08x\n", mqi
[0].hr
);
3650 ok(mqi
[1].pItf
== NULL
, "got %p\n", mqi
[1].pItf
);
3651 ok(mqi
[1].hr
== 0x8000efef, "got 0x%08x\n", mqi
[1].hr
);
3652 g_persistfile_qi_ret
= S_OK
;
3654 mqi
[0].pIID
= &IID_IUnknown
;
3657 mqi
[1].pIID
= &IID_IUnknown
;
3660 g_persistfile_load_ret
= 0x8000fefe;
3661 hr
= CoGetInstanceFromFile(NULL
, clsid
, NULL
, CLSCTX_INPROC_SERVER
, STGM_READ
, (OLECHAR
*)filenameW
, 2, mqi
);
3662 ok(hr
== 0x8000fefe, "got 0x%08x\n", hr
);
3663 ok(mqi
[0].pItf
== NULL
, "got %p\n", mqi
[0].pItf
);
3664 ok(mqi
[0].hr
== 0x8000fefe, "got 0x%08x\n", mqi
[0].hr
);
3665 ok(mqi
[1].pItf
== NULL
, "got %p\n", mqi
[1].pItf
);
3666 ok(mqi
[1].hr
== 0x8000fefe, "got 0x%08x\n", mqi
[1].hr
);
3667 g_persistfile_load_ret
= S_OK
;
3669 hr
= CoRevokeClassObject(cookie
);
3670 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3675 static void test_GlobalOptions(void)
3677 IGlobalOptions
*global_options
;
3682 hres
= CoCreateInstance(&CLSID_GlobalOptions
, NULL
, CLSCTX_INPROC_SERVER
,
3683 &IID_IGlobalOptions
, (void**)&global_options
);
3684 ok(hres
== S_OK
|| broken(hres
== E_NOINTERFACE
), "CoCreateInstance(CLSID_GlobalOptions) failed: %08x\n", hres
);
3687 win_skip("CLSID_GlobalOptions not available\n");
3692 IGlobalOptions_Release(global_options
);
3694 hres
= CoCreateInstance(&CLSID_GlobalOptions
, (IUnknown
*)0xdeadbeef, CLSCTX_INPROC_SERVER
,
3695 &IID_IGlobalOptions
, (void**)&global_options
);
3696 ok(hres
== E_INVALIDARG
, "CoCreateInstance(CLSID_GlobalOptions) failed: %08x\n", hres
);
3701 static void init_funcs(void)
3703 HMODULE hOle32
= GetModuleHandleA("ole32");
3704 HMODULE hAdvapi32
= GetModuleHandleA("advapi32");
3705 HMODULE hkernel32
= GetModuleHandleA("kernel32");
3707 pCoGetObjectContext
= (void*)GetProcAddress(hOle32
, "CoGetObjectContext");
3708 pCoSwitchCallContext
= (void*)GetProcAddress(hOle32
, "CoSwitchCallContext");
3709 pCoGetTreatAsClass
= (void*)GetProcAddress(hOle32
,"CoGetTreatAsClass");
3710 pCoTreatAsClass
= (void*)GetProcAddress(hOle32
,"CoTreatAsClass");
3711 pCoGetContextToken
= (void*)GetProcAddress(hOle32
, "CoGetContextToken");
3712 pCoGetApartmentType
= (void*)GetProcAddress(hOle32
, "CoGetApartmentType");
3713 pRegDeleteKeyExA
= (void*)GetProcAddress(hAdvapi32
, "RegDeleteKeyExA");
3714 pRegOverridePredefKey
= (void*)GetProcAddress(hAdvapi32
, "RegOverridePredefKey");
3715 pCoInitializeEx
= (void*)GetProcAddress(hOle32
, "CoInitializeEx");
3717 pActivateActCtx
= (void*)GetProcAddress(hkernel32
, "ActivateActCtx");
3718 pCreateActCtxW
= (void*)GetProcAddress(hkernel32
, "CreateActCtxW");
3719 pDeactivateActCtx
= (void*)GetProcAddress(hkernel32
, "DeactivateActCtx");
3720 pIsWow64Process
= (void*)GetProcAddress(hkernel32
, "IsWow64Process");
3721 pReleaseActCtx
= (void*)GetProcAddress(hkernel32
, "ReleaseActCtx");
3724 static DWORD CALLBACK
implicit_mta_proc(void *param
)
3726 IComThreadingInfo
*threading_info
;
3733 test_apt_type(APTTYPE_MTA
, APTTYPEQUALIFIER_IMPLICIT_MTA
);
3735 hr
= CoCreateInstance(&CLSID_InternetZoneManager
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&unk
);
3736 ok_ole_success(hr
, "CoCreateInstance");
3737 IUnknown_Release(unk
);
3739 hr
= CoGetClassObject(&CLSID_InternetZoneManager
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&unk
);
3740 ok_ole_success(hr
, "CoGetClassObject");
3741 IUnknown_Release(unk
);
3743 hr
= CoGetObjectContext(&IID_IComThreadingInfo
, (void **)&threading_info
);
3744 ok_ole_success(hr
, "CoGetObjectContext");
3745 IComThreadingInfo_Release(threading_info
);
3747 hr
= CoGetContextToken(&token
);
3748 ok_ole_success(hr
, "CoGetContextToken");
3750 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
3751 ok_ole_success(hr
, "CoRegisterPSClsid");
3753 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
3754 ok_ole_success(hr
, "CoGetPSClsid");
3756 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
3757 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
3758 ok_ole_success(hr
, "CoRegisterClassObject");
3760 hr
= CoRevokeClassObject(cookie
);
3761 ok_ole_success(hr
, "CoRevokeClassObject");
3763 hr
= CoRegisterMessageFilter(NULL
, NULL
);
3764 ok(hr
== CO_E_NOT_SUPPORTED
, "got %#x\n", hr
);
3766 hr
= CoLockObjectExternal((IUnknown
*)&Test_Unknown
, TRUE
, TRUE
);
3767 ok_ole_success(hr
, "CoLockObjectExternal");
3769 hr
= CoDisconnectObject((IUnknown
*)&Test_Unknown
, 0);
3770 ok_ole_success(hr
, "CoDisconnectObject");
3775 /* Some COM functions (perhaps even all of them?) can make use of an "implicit"
3776 * multi-threaded apartment created by another thread in the same process. */
3777 static void test_implicit_mta(void)
3781 CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
3783 thread
= CreateThread(NULL
, 0, implicit_mta_proc
, NULL
, 0, NULL
);
3784 ok(!WaitForSingleObject(thread
, 1000), "wait failed\n");
3793 if (!pCoInitializeEx
)
3795 trace("You need DCOM95 installed to run this test\n");
3799 if (!pCreateActCtxW
)
3800 win_skip("Activation contexts are not supported, some tests will be skipped.\n");
3802 test_ProgIDFromCLSID();
3803 test_CLSIDFromProgID();
3804 test_CLSIDFromString();
3805 test_IIDFromString();
3806 test_StringFromGUID2();
3807 test_CoCreateInstance();
3809 test_CoGetClassObject();
3810 test_CoCreateInstanceEx();
3811 test_CoRegisterMessageFilter();
3812 test_CoRegisterPSClsid();
3813 test_CoGetPSClsid();
3814 test_CoUnmarshalInterface();
3815 test_CoGetInterfaceAndReleaseStream();
3816 test_CoMarshalInterface();
3817 test_CoMarshalInterThreadInterfaceInStream();
3818 test_CoRegisterClassObject();
3819 test_registered_object_thread_affinity();
3820 test_CoFreeUnusedLibraries();
3821 test_CoGetObjectContext();
3822 test_CoGetCallContext();
3823 test_CoGetContextToken();
3824 test_TreatAsClass();
3825 test_CoInitializeEx();
3826 test_OleInitialize_InitCounting();
3827 test_OleRegGetMiscStatus();
3828 test_CoCreateGuid();
3829 test_CoWaitForMultipleHandles();
3831 test_OleRegGetUserType();
3832 test_CoGetApartmentType();
3834 test_CoGetCurrentLogicalThreadId();
3835 test_IInitializeSpy();
3836 test_CoGetInstanceFromFile();
3837 test_GlobalOptions();
3838 test_implicit_mta();