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
33 #include "urlmon.h" /* for CLSID_FileProtocol */
38 #include "wine/test.h"
40 #define DEFINE_EXPECT(func) \
41 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
43 #define SET_EXPECT(func) \
44 expect_ ## func = TRUE
46 #define CHECK_EXPECT2(func) \
48 ok(expect_ ##func, "unexpected call " #func "\n"); \
49 called_ ## func = TRUE; \
52 #define CHECK_EXPECT(func) \
54 CHECK_EXPECT2(func); \
55 expect_ ## func = FALSE; \
58 #define CHECK_CALLED(func) \
60 ok(called_ ## func, "expected " #func "\n"); \
61 expect_ ## func = called_ ## func = FALSE; \
64 DEFINE_EXPECT(CreateStub
);
66 /* functions that are not present on all versions of Windows */
67 static HRESULT (WINAPI
* pCoInitializeEx
)(LPVOID lpReserved
, DWORD dwCoInit
);
68 static HRESULT (WINAPI
* pCoGetObjectContext
)(REFIID riid
, LPVOID
*ppv
);
69 static HRESULT (WINAPI
* pCoSwitchCallContext
)(IUnknown
*pObject
, IUnknown
**ppOldObject
);
70 static HRESULT (WINAPI
* pCoGetTreatAsClass
)(REFCLSID clsidOld
, LPCLSID pClsidNew
);
71 static HRESULT (WINAPI
* pCoTreatAsClass
)(REFCLSID clsidOld
, REFCLSID pClsidNew
);
72 static HRESULT (WINAPI
* pCoGetContextToken
)(ULONG_PTR
*token
);
73 static HRESULT (WINAPI
* pCoGetApartmentType
)(APTTYPE
*type
, APTTYPEQUALIFIER
*qualifier
);
74 static LONG (WINAPI
* pRegDeleteKeyExA
)(HKEY
, LPCSTR
, REGSAM
, DWORD
);
75 static LONG (WINAPI
* pRegOverridePredefKey
)(HKEY key
, HKEY override
);
77 static BOOL (WINAPI
*pActivateActCtx
)(HANDLE
,ULONG_PTR
*);
78 static HANDLE (WINAPI
*pCreateActCtxW
)(PCACTCTXW
);
79 static BOOL (WINAPI
*pDeactivateActCtx
)(DWORD
,ULONG_PTR
);
80 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
, LPBOOL
);
81 static void (WINAPI
*pReleaseActCtx
)(HANDLE
);
83 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
84 #define ok_more_than_one_lock() ok(cLocks > 0, "Number of locks should be > 0, but actually is %d\n", cLocks)
85 #define ok_no_locks() ok(cLocks == 0, "Number of locks should be 0, but actually is %d\n", cLocks)
87 static const CLSID CLSID_non_existent
= { 0x12345678, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
88 static const CLSID CLSID_StdFont
= { 0x0be35203, 0x8f91, 0x11ce, { 0x9d, 0xe3, 0x00, 0xaa, 0x00, 0x4b, 0xb8, 0x51 } };
89 static const GUID IID_Testiface
= { 0x22222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
90 static const GUID IID_Testiface2
= { 0x32222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
91 static const GUID IID_Testiface3
= { 0x42222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
92 static const GUID IID_Testiface4
= { 0x52222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
93 static const GUID IID_Testiface5
= { 0x62222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
94 static const GUID IID_Testiface6
= { 0x72222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };
95 static const GUID IID_TestPS
= { 0x66666666, 0x8888, 0x7777, { 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 } };
97 DEFINE_GUID(CLSID_InProcFreeMarshaler
, 0x0000033a,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
99 static const WCHAR stdfont
[] = {'S','t','d','F','o','n','t',0};
100 static const WCHAR wszNonExistent
[] = {'N','o','n','E','x','i','s','t','e','n','t',0};
101 static const WCHAR wszCLSID_StdFont
[] =
103 '{','0','b','e','3','5','2','0','3','-','8','f','9','1','-','1','1','c','e','-',
104 '9','d','e','3','-','0','0','a','a','0','0','4','b','b','8','5','1','}',0
106 static const WCHAR progidW
[] = {'P','r','o','g','I','d','.','P','r','o','g','I','d',0};
107 static const WCHAR cf_brokenW
[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-',
108 'c','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}','a',0};
110 DEFINE_GUID(IID_IWineTest
, 0x5201163f, 0x8164, 0x4fd0, 0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd);
111 DEFINE_GUID(CLSID_WineOOPTest
, 0x5201163f, 0x8164, 0x4fd0, 0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd);
115 static void LockModule(void)
117 InterlockedIncrement(&cLocks
);
120 static void UnlockModule(void)
122 InterlockedDecrement(&cLocks
);
125 static HRESULT WINAPI
Test_IClassFactory_QueryInterface(
126 LPCLASSFACTORY iface
,
130 if (ppvObj
== NULL
) return E_POINTER
;
132 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
133 IsEqualGUID(riid
, &IID_IClassFactory
))
136 IClassFactory_AddRef(iface
);
141 return E_NOINTERFACE
;
144 static ULONG WINAPI
Test_IClassFactory_AddRef(LPCLASSFACTORY iface
)
147 return 2; /* non-heap-based object */
150 static ULONG WINAPI
Test_IClassFactory_Release(LPCLASSFACTORY iface
)
153 return 1; /* non-heap-based object */
156 static IID create_instance_iid
;
157 static HRESULT WINAPI
Test_IClassFactory_CreateInstance(
158 LPCLASSFACTORY iface
,
164 create_instance_iid
= *riid
;
165 if (pUnkOuter
) return CLASS_E_NOAGGREGATION
;
166 return E_NOINTERFACE
;
169 static HRESULT WINAPI
Test_IClassFactory_LockServer(
170 LPCLASSFACTORY iface
,
176 static const IClassFactoryVtbl TestClassFactory_Vtbl
=
178 Test_IClassFactory_QueryInterface
,
179 Test_IClassFactory_AddRef
,
180 Test_IClassFactory_Release
,
181 Test_IClassFactory_CreateInstance
,
182 Test_IClassFactory_LockServer
185 static IClassFactory Test_ClassFactory
= { &TestClassFactory_Vtbl
};
187 static WCHAR manifest_path
[MAX_PATH
];
189 static BOOL
create_manifest_file(const char *filename
, const char *manifest
)
194 WCHAR path
[MAX_PATH
];
196 MultiByteToWideChar( CP_ACP
, 0, filename
, -1, path
, MAX_PATH
);
197 GetFullPathNameW(path
, sizeof(manifest_path
)/sizeof(WCHAR
), manifest_path
, NULL
);
199 manifest_len
= strlen(manifest
);
200 file
= CreateFileW(path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
201 FILE_ATTRIBUTE_NORMAL
, NULL
);
202 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed: %u\n", GetLastError());
203 if(file
== INVALID_HANDLE_VALUE
)
205 WriteFile(file
, manifest
, manifest_len
, &size
, NULL
);
211 static HANDLE
activate_context(const char *manifest
, ULONG_PTR
*cookie
)
213 WCHAR path
[MAX_PATH
];
218 if (!pCreateActCtxW
) return NULL
;
220 create_manifest_file("file.manifest", manifest
);
222 MultiByteToWideChar( CP_ACP
, 0, "file.manifest", -1, path
, MAX_PATH
);
223 memset(&actctx
, 0, sizeof(ACTCTXW
));
224 actctx
.cbSize
= sizeof(ACTCTXW
);
225 actctx
.lpSource
= path
;
227 handle
= pCreateActCtxW(&actctx
);
228 ok(handle
!= INVALID_HANDLE_VALUE
|| broken(handle
== INVALID_HANDLE_VALUE
) /* some old XP/2k3 versions */,
229 "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError());
230 if (handle
== INVALID_HANDLE_VALUE
)
232 win_skip("activation context generation failed, some tests will be skipped\n");
236 ok(actctx
.cbSize
== sizeof(ACTCTXW
), "actctx.cbSize=%d\n", actctx
.cbSize
);
237 ok(actctx
.dwFlags
== 0, "actctx.dwFlags=%d\n", actctx
.dwFlags
);
238 ok(actctx
.lpSource
== path
, "actctx.lpSource=%p\n", actctx
.lpSource
);
239 ok(actctx
.wProcessorArchitecture
== 0, "actctx.wProcessorArchitecture=%d\n", actctx
.wProcessorArchitecture
);
240 ok(actctx
.wLangId
== 0, "actctx.wLangId=%d\n", actctx
.wLangId
);
241 ok(actctx
.lpAssemblyDirectory
== NULL
, "actctx.lpAssemblyDirectory=%p\n", actctx
.lpAssemblyDirectory
);
242 ok(actctx
.lpResourceName
== NULL
, "actctx.lpResourceName=%p\n", actctx
.lpResourceName
);
243 ok(actctx
.lpApplicationName
== NULL
, "actctx.lpApplicationName=%p\n", actctx
.lpApplicationName
);
244 ok(actctx
.hModule
== NULL
, "actctx.hModule=%p\n", actctx
.hModule
);
246 DeleteFileA("file.manifest");
250 ret
= pActivateActCtx(handle
, cookie
);
251 ok(ret
, "ActivateActCtx failed: %u\n", GetLastError());
257 static const char actctx_manifest
[] =
258 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
259 "<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\""
260 " publicKeyToken=\"6595b6414666f1df\" />"
261 "<file name=\"testlib.dll\">"
263 " clsid=\"{0000033a-0000-0000-c000-000000000046}\""
264 " progid=\"FTMarshal\""
267 " clsid=\"{5201163f-8164-4fd0-a1a2-5d5a3654d3bd}\""
268 " progid=\"WineOOPTest\""
270 " <comClass description=\"Test com class\""
271 " clsid=\"{12345678-1234-1234-1234-56789abcdef0}\""
272 " progid=\"ProgId.ProgId\""
273 " miscStatusIcon=\"recomposeonresize\""
275 " <comClass description=\"CustomFont Description\" clsid=\"{0be35203-8f91-11ce-9de3-00aa004bb851}\""
276 " progid=\"CustomFont\""
277 " miscStatusIcon=\"recomposeonresize\""
278 " miscStatusContent=\"insideout\""
280 " <comClass description=\"StdFont Description\" clsid=\"{0be35203-8f91-11ce-9de3-00aa004bb852}\""
281 " progid=\"StdFont\""
283 " <comClass clsid=\"{62222222-1234-1234-1234-56789abcdef0}\" >"
284 " <progid>ProgId.ProgId.1</progid>"
286 " <comInterfaceProxyStub "
288 " iid=\"{22222222-1234-1234-1234-56789abcdef0}\""
289 " proxyStubClsid32=\"{66666666-8888-7777-6666-555555555555}\""
292 " <comInterfaceExternalProxyStub "
293 " name=\"Iifaceps2\""
294 " iid=\"{32222222-1234-1234-1234-56789abcdef0}\""
296 " <comInterfaceExternalProxyStub "
297 " name=\"Iifaceps3\""
298 " iid=\"{42222222-1234-1234-1234-56789abcdef0}\""
299 " proxyStubClsid32=\"{66666666-8888-7777-6666-555555555555}\""
301 " <comInterfaceExternalProxyStub "
302 " name=\"Iifaceps4\""
303 " iid=\"{52222222-1234-1234-1234-56789abcdef0}\""
304 " proxyStubClsid32=\"{00000000-0000-0000-0000-000000000000}\""
307 " clsid=\"{72222222-1234-1234-1234-56789abcdef0}\""
310 " <progid>clrprogid.1</progid>"
314 DEFINE_GUID(CLSID_Testclass
, 0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0);
316 static void test_ProgIDFromCLSID(void)
318 ULONG_PTR cookie
= 0;
323 hr
= ProgIDFromCLSID(&CLSID_StdFont
, &progid
);
324 ok(hr
== S_OK
, "ProgIDFromCLSID failed with error 0x%08x\n", hr
);
327 ok(!lstrcmpiW(progid
, stdfont
), "Didn't get expected prog ID\n");
328 CoTaskMemFree(progid
);
331 progid
= (LPWSTR
)0xdeadbeef;
332 hr
= ProgIDFromCLSID(&CLSID_non_existent
, &progid
);
333 ok(hr
== REGDB_E_CLASSNOTREG
, "ProgIDFromCLSID returned %08x\n", hr
);
334 ok(progid
== NULL
, "ProgIDFromCLSID returns with progid %p\n", progid
);
336 hr
= ProgIDFromCLSID(&CLSID_StdFont
, NULL
);
337 ok(hr
== E_INVALIDARG
, "ProgIDFromCLSID should return E_INVALIDARG instead of 0x%08x\n", hr
);
339 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
341 static const WCHAR customfontW
[] = {'C','u','s','t','o','m','F','o','n','t',0};
343 hr
= ProgIDFromCLSID(&CLSID_non_existent
, &progid
);
344 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
345 ok(!lstrcmpiW(progid
, progidW
), "got %s\n", wine_dbgstr_w(progid
));
346 CoTaskMemFree(progid
);
348 /* try something registered and redirected */
350 hr
= ProgIDFromCLSID(&CLSID_StdFont
, &progid
);
351 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
352 ok(!lstrcmpiW(progid
, customfontW
), "got wrong progid %s\n", wine_dbgstr_w(progid
));
353 CoTaskMemFree(progid
);
355 /* classes without default progid, progid list is not used */
356 hr
= ProgIDFromCLSID(&IID_Testiface5
, &progid
);
357 ok(hr
== REGDB_E_CLASSNOTREG
, "got 0x%08x\n", hr
);
359 hr
= ProgIDFromCLSID(&IID_Testiface6
, &progid
);
360 ok(hr
== REGDB_E_CLASSNOTREG
, "got 0x%08x\n", hr
);
362 pDeactivateActCtx(0, cookie
);
363 pReleaseActCtx(handle
);
367 static void test_CLSIDFromProgID(void)
369 ULONG_PTR cookie
= 0;
372 HRESULT hr
= CLSIDFromProgID(stdfont
, &clsid
);
373 ok(hr
== S_OK
, "CLSIDFromProgID failed with error 0x%08x\n", hr
);
374 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
376 hr
= CLSIDFromString(stdfont
, &clsid
);
377 ok_ole_success(hr
, "CLSIDFromString");
378 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
380 /* test some failure cases */
382 hr
= CLSIDFromProgID(wszNonExistent
, NULL
);
383 ok(hr
== E_INVALIDARG
, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
385 hr
= CLSIDFromProgID(NULL
, &clsid
);
386 ok(hr
== E_INVALIDARG
, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
388 memset(&clsid
, 0xcc, sizeof(clsid
));
389 hr
= CLSIDFromProgID(wszNonExistent
, &clsid
);
390 ok(hr
== CO_E_CLASSSTRING
, "CLSIDFromProgID on nonexistent ProgID should have returned CO_E_CLASSSTRING instead of 0x%08x\n", hr
);
391 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "CLSIDFromProgID should have set clsid to all-zeros on failure\n");
393 /* fails without proper context */
394 memset(&clsid
, 0xcc, sizeof(clsid
));
395 hr
= CLSIDFromProgID(progidW
, &clsid
);
396 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
397 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "wrong clsid\n");
399 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
403 memset(&clsid
, 0xcc, sizeof(clsid
));
404 hr
= CLSIDFromProgID(wszNonExistent
, &clsid
);
405 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
406 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "should have zero CLSID on failure\n");
408 /* CLSIDFromString() doesn't check activation context */
409 hr
= CLSIDFromString(progidW
, &clsid
);
410 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
413 hr
= CLSIDFromProgID(progidW
, &clsid
);
414 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
415 /* it returns generated CLSID here */
416 ok(!IsEqualCLSID(&clsid
, &CLSID_non_existent
) && !IsEqualCLSID(&clsid
, &CLSID_NULL
),
417 "got wrong clsid %s\n", wine_dbgstr_guid(&clsid
));
419 /* duplicate progid present in context - returns generated guid here too */
421 hr
= CLSIDFromProgID(stdfont
, &clsid
);
422 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
423 clsid1
= CLSID_StdFont
;
424 /* that's where it differs from StdFont */
425 clsid1
.Data4
[7] = 0x52;
426 ok(!IsEqualCLSID(&clsid
, &CLSID_StdFont
) && !IsEqualCLSID(&clsid
, &CLSID_NULL
) && !IsEqualCLSID(&clsid
, &clsid1
),
427 "got %s\n", wine_dbgstr_guid(&clsid
));
429 pDeactivateActCtx(0, cookie
);
430 pReleaseActCtx(handle
);
434 static void test_CLSIDFromString(void)
437 WCHAR wszCLSID_Broken
[50];
440 HRESULT hr
= CLSIDFromString(wszCLSID_StdFont
, &clsid
);
441 ok_ole_success(hr
, "CLSIDFromString");
442 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
444 memset(&clsid
, 0xab, sizeof(clsid
));
445 hr
= CLSIDFromString(NULL
, &clsid
);
446 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
447 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "clsid wasn't equal to CLSID_NULL\n");
449 /* string is longer, but starts with a valid CLSID */
450 memset(&clsid
, 0, sizeof(clsid
));
451 hr
= CLSIDFromString(cf_brokenW
, &clsid
);
452 ok(hr
== CO_E_CLASSSTRING
, "got 0x%08x\n", hr
);
453 ok(IsEqualCLSID(&clsid
, &IID_IClassFactory
), "got %s\n", wine_dbgstr_guid(&clsid
));
455 lstrcpyW(wszCLSID_Broken
, wszCLSID_StdFont
);
456 for(i
= lstrlenW(wszCLSID_StdFont
); i
< 49; i
++)
457 wszCLSID_Broken
[i
] = 'A';
458 wszCLSID_Broken
[i
] = '\0';
460 memset(&clsid
, 0, sizeof(CLSID
));
461 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
462 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
463 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
465 wszCLSID_Broken
[lstrlenW(wszCLSID_StdFont
)-1] = 'A';
466 memset(&clsid
, 0, sizeof(CLSID
));
467 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
468 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
469 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
471 wszCLSID_Broken
[lstrlenW(wszCLSID_StdFont
)] = '\0';
472 memset(&clsid
, 0, sizeof(CLSID
));
473 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
474 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
475 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
477 wszCLSID_Broken
[lstrlenW(wszCLSID_StdFont
)-1] = '\0';
478 memset(&clsid
, 0, sizeof(CLSID
));
479 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
480 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
481 ok(IsEqualCLSID(&clsid
, &CLSID_StdFont
), "clsid wasn't equal to CLSID_StdFont\n");
483 memset(&clsid
, 0xcc, sizeof(CLSID
));
484 hr
= CLSIDFromString(wszCLSID_Broken
+1, &clsid
);
485 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
486 ok(IsEqualCLSID(&clsid
, &CLSID_NULL
), "clsid wasn't equal to CLSID_NULL\n");
488 wszCLSID_Broken
[9] = '*';
489 memset(&clsid
, 0xcc, sizeof(CLSID
));
490 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
491 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
492 ok(clsid
.Data1
== CLSID_StdFont
.Data1
, "Got %08x\n", clsid
.Data1
);
493 ok(clsid
.Data2
== 0xcccc, "Got %04x\n", clsid
.Data2
);
495 wszCLSID_Broken
[3] = '*';
496 memset(&clsid
, 0xcc, sizeof(CLSID
));
497 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
498 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
499 ok(clsid
.Data1
== 0xb, "Got %08x\n", clsid
.Data1
);
500 ok(clsid
.Data2
== 0xcccc, "Got %04x\n", clsid
.Data2
);
502 wszCLSID_Broken
[3] = '\0';
503 memset(&clsid
, 0xcc, sizeof(CLSID
));
504 hr
= CLSIDFromString(wszCLSID_Broken
, &clsid
);
505 ok(hr
== CO_E_CLASSSTRING
, "Got %08x\n", hr
);
506 ok(clsid
.Data1
== 0xb, "Got %08x\n", clsid
.Data1
);
507 ok(clsid
.Data2
== 0xcccc, "Got %04x\n", clsid
.Data2
);
510 static void test_IIDFromString(void)
512 static const WCHAR cfW
[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-',
513 'c','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
514 static const WCHAR brokenW
[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-',
515 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
516 static const WCHAR broken2W
[] = {'{','0','0','0','0','0','0','0','1','=','0','0','0','0','-','0','0','0','0','-',
517 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
518 static const WCHAR broken3W
[] = {'b','r','o','k','e','n','0','0','1','=','0','0','0','0','-','0','0','0','0','-',
519 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0};
523 hr
= IIDFromString(wszCLSID_StdFont
, &iid
);
524 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
525 ok(IsEqualIID(&iid
, &CLSID_StdFont
), "got iid %s\n", wine_dbgstr_guid(&iid
));
527 memset(&iid
, 0xab, sizeof(iid
));
528 hr
= IIDFromString(NULL
, &iid
);
529 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
530 ok(IsEqualIID(&iid
, &CLSID_NULL
), "got iid %s\n", wine_dbgstr_guid(&iid
));
532 hr
= IIDFromString(cfW
, &iid
);
533 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
534 ok(IsEqualIID(&iid
, &IID_IClassFactory
), "got iid %s\n", wine_dbgstr_guid(&iid
));
536 /* string starts with a valid IID but is longer */
537 memset(&iid
, 0xab, sizeof(iid
));
538 hr
= IIDFromString(cf_brokenW
, &iid
);
539 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
540 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
542 /* invalid IID in a valid format */
543 memset(&iid
, 0xab, sizeof(iid
));
544 hr
= IIDFromString(brokenW
, &iid
);
545 ok(hr
== CO_E_IIDSTRING
, "got 0x%08x\n", hr
);
546 ok(iid
.Data1
== 0x00000001, "Got %08x\n", iid
.Data1
);
548 memset(&iid
, 0xab, sizeof(iid
));
549 hr
= IIDFromString(broken2W
, &iid
);
550 ok(hr
== CO_E_IIDSTRING
, "got 0x%08x\n", hr
);
551 ok(iid
.Data1
== 0x00000001, "Got %08x\n", iid
.Data1
);
553 /* format is broken, but string length is okay */
554 memset(&iid
, 0xab, sizeof(iid
));
555 hr
= IIDFromString(broken3W
, &iid
);
556 ok(hr
== CO_E_IIDSTRING
, "got 0x%08x\n", hr
);
557 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
560 memset(&iid
, 0xab, sizeof(iid
));
561 hr
= IIDFromString(wszNonExistent
, &iid
);
562 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
563 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
566 memset(&iid
, 0xab, sizeof(iid
));
567 hr
= IIDFromString(stdfont
, &iid
);
568 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
569 ok(iid
.Data1
== 0xabababab, "Got %08x\n", iid
.Data1
);
572 static void test_StringFromGUID2(void)
577 /* invalid pointer */
578 SetLastError(0xdeadbeef);
579 len
= StringFromGUID2(NULL
,str
,50);
580 ok(len
== 0, "len: %d (expected 0)\n", len
);
581 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %x\n", GetLastError());
583 /* Test corner cases for buffer size */
584 len
= StringFromGUID2(&CLSID_StdFont
,str
,50);
585 ok(len
== 39, "len: %d (expected 39)\n", len
);
586 ok(!lstrcmpiW(str
, wszCLSID_StdFont
),"string wasn't equal for CLSID_StdFont\n");
588 memset(str
,0,sizeof str
);
589 len
= StringFromGUID2(&CLSID_StdFont
,str
,39);
590 ok(len
== 39, "len: %d (expected 39)\n", len
);
591 ok(!lstrcmpiW(str
, wszCLSID_StdFont
),"string wasn't equal for CLSID_StdFont\n");
593 len
= StringFromGUID2(&CLSID_StdFont
,str
,38);
594 ok(len
== 0, "len: %d (expected 0)\n", len
);
596 len
= StringFromGUID2(&CLSID_StdFont
,str
,30);
597 ok(len
== 0, "len: %d (expected 0)\n", len
);
605 static DWORD CALLBACK
ole_initialize_thread(LPVOID pv
)
608 struct info
*info
= pv
;
610 hr
= pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
612 SetEvent(info
->wait
);
613 WaitForSingleObject(info
->stop
, 10000);
619 static void test_CoCreateInstance(void)
626 REFCLSID rclsid
= &CLSID_InternetZoneManager
;
628 pUnk
= (IUnknown
*)0xdeadbeef;
629 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
630 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
631 ok(pUnk
== NULL
, "CoCreateInstance should have changed the passed in pointer to NULL, instead of %p\n", pUnk
);
635 /* test errors returned for non-registered clsids */
636 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
637 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered inproc server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
638 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_INPROC_HANDLER
, &IID_IUnknown
, (void **)&pUnk
);
639 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered inproc handler should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
640 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_LOCAL_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
641 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered local server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
642 hr
= CoCreateInstance(&CLSID_non_existent
, NULL
, CLSCTX_REMOTE_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
643 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance for non-registered remote server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr
);
645 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
646 if(hr
== REGDB_E_CLASSNOTREG
)
648 skip("IE not installed so can't test CoCreateInstance\n");
653 ok_ole_success(hr
, "CoCreateInstance");
654 if(pUnk
) IUnknown_Release(pUnk
);
657 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
658 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
660 /* show that COM doesn't have to be initialized for multi-threaded apartments if another
661 thread has already done so */
663 info
.wait
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
664 ok(info
.wait
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
666 info
.stop
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
667 ok(info
.stop
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
669 thread
= CreateThread(NULL
, 0, ole_initialize_thread
, &info
, 0, &tid
);
670 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
672 ok( !WaitForSingleObject(info
.wait
, 10000 ), "wait timed out\n" );
674 pUnk
= (IUnknown
*)0xdeadbeef;
675 hr
= CoCreateInstance(rclsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&pUnk
);
676 ok(hr
== S_OK
, "CoCreateInstance should have returned S_OK instead of 0x%08x\n", hr
);
677 if (pUnk
) IUnknown_Release(pUnk
);
680 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
682 GetExitCodeThread(thread
, &exitcode
);
684 ok(hr
== S_OK
, "thread should have returned S_OK instead of 0x%08x\n", hr
);
687 CloseHandle(info
.wait
);
688 CloseHandle(info
.stop
);
691 static void test_CoGetClassObject(void)
694 HANDLE thread
, handle
;
699 REFCLSID rclsid
= &CLSID_InternetZoneManager
;
703 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
704 ok(hr
== CO_E_NOTINITIALIZED
, "CoGetClassObject should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
705 ok(pUnk
== NULL
, "CoGetClassObject should have changed the passed in pointer to NULL, instead of %p\n", pUnk
);
707 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, NULL
);
708 ok(hr
== E_INVALIDARG
||
709 broken(hr
== CO_E_NOTINITIALIZED
), /* win9x */
710 "CoGetClassObject should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
712 /* show that COM doesn't have to be initialized for multi-threaded apartments if another
713 thread has already done so */
715 info
.wait
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
716 ok(info
.wait
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
718 info
.stop
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
719 ok(info
.stop
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
721 thread
= CreateThread(NULL
, 0, ole_initialize_thread
, &info
, 0, &tid
);
722 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
724 ok( !WaitForSingleObject(info
.wait
, 10000), "wait timed out\n" );
726 pUnk
= (IUnknown
*)0xdeadbeef;
727 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
728 if(hr
== REGDB_E_CLASSNOTREG
)
729 skip("IE not installed so can't test CoGetClassObject\n");
732 ok(hr
== S_OK
, "CoGetClassObject should have returned S_OK instead of 0x%08x\n", hr
);
733 if (pUnk
) IUnknown_Release(pUnk
);
737 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
739 GetExitCodeThread(thread
, &exitcode
);
741 ok(hr
== S_OK
, "thread should have returned S_OK instead of 0x%08x\n", hr
);
744 CloseHandle(info
.wait
);
745 CloseHandle(info
.stop
);
747 if (!pRegOverridePredefKey
)
749 win_skip("RegOverridePredefKey not available\n");
753 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
755 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
758 IUnknown_Release(pUnk
);
760 res
= RegCreateKeyExA(HKEY_CURRENT_USER
, "Software\\Classes", 0, NULL
, 0,
761 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
);
762 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
764 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, hkey
);
765 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
767 hr
= CoGetClassObject(rclsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
768 ok(hr
== S_OK
, "CoGetClassObject should have returned S_OK instead of 0x%08x\n", hr
);
770 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, NULL
);
771 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
773 if (hr
== S_OK
) IUnknown_Release(pUnk
);
777 hr
= CoGetClassObject(&CLSID_InProcFreeMarshaler
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
778 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
779 IUnknown_Release(pUnk
);
781 /* context redefines FreeMarshaler CLSID */
782 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
784 hr
= CoGetClassObject(&CLSID_InProcFreeMarshaler
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void **)&pUnk
);
785 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
786 IUnknown_Release(pUnk
);
788 pDeactivateActCtx(0, cookie
);
789 pReleaseActCtx(handle
);
795 static void test_CoCreateInstanceEx(void)
797 MULTI_QI qi_res
= { &IID_IMoniker
};
803 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
804 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
805 ok_ole_success(hr
, "CoRegisterClassObject");
807 create_instance_iid
= IID_NULL
;
808 hr
= CoCreateInstanceEx(&CLSID_WineOOPTest
, NULL
, CLSCTX_INPROC_SERVER
, NULL
, 1, &qi_res
);
809 ok(hr
== E_NOINTERFACE
, "CoCreateInstanceEx failed: %08x\n", hr
);
810 ok(IsEqualGUID(&create_instance_iid
, qi_res
.pIID
), "Unexpected CreateInstance iid %s\n",
811 wine_dbgstr_guid(&create_instance_iid
));
813 hr
= CoRevokeClassObject(cookie
);
814 ok_ole_success(hr
, "CoRevokeClassObject");
819 static ATOM
register_dummy_class(void)
827 GetModuleHandleA(NULL
),
829 LoadCursorA(NULL
, (LPSTR
)IDC_ARROW
),
830 (HBRUSH
)(COLOR_BTNFACE
+1),
835 return RegisterClassA(&wc
);
838 static void test_ole_menu(void)
843 hwndFrame
= CreateWindowA((LPCSTR
)MAKEINTATOM(register_dummy_class()), "Test", 0, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, NULL
, NULL
, NULL
, NULL
);
844 hr
= OleSetMenuDescriptor(NULL
, hwndFrame
, NULL
, NULL
, NULL
);
845 todo_wine
ok_ole_success(hr
, "OleSetMenuDescriptor");
847 DestroyWindow(hwndFrame
);
851 static HRESULT WINAPI
MessageFilter_QueryInterface(IMessageFilter
*iface
, REFIID riid
, void ** ppvObj
)
853 if (ppvObj
== NULL
) return E_POINTER
;
855 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
856 IsEqualGUID(riid
, &IID_IClassFactory
))
859 IMessageFilter_AddRef(iface
);
863 return E_NOINTERFACE
;
866 static ULONG WINAPI
MessageFilter_AddRef(IMessageFilter
*iface
)
868 return 2; /* non-heap object */
871 static ULONG WINAPI
MessageFilter_Release(IMessageFilter
*iface
)
873 return 1; /* non-heap object */
876 static DWORD WINAPI
MessageFilter_HandleInComingCall(
877 IMessageFilter
*iface
,
879 HTASK threadIDCaller
,
881 LPINTERFACEINFO lpInterfaceInfo
)
883 trace("HandleInComingCall\n");
884 return SERVERCALL_ISHANDLED
;
887 static DWORD WINAPI
MessageFilter_RetryRejectedCall(
888 IMessageFilter
*iface
,
889 HTASK threadIDCallee
,
893 trace("RetryRejectedCall\n");
897 static DWORD WINAPI
MessageFilter_MessagePending(
898 IMessageFilter
*iface
,
899 HTASK threadIDCallee
,
903 trace("MessagePending\n");
904 return PENDINGMSG_WAITNOPROCESS
;
907 static const IMessageFilterVtbl MessageFilter_Vtbl
=
909 MessageFilter_QueryInterface
,
910 MessageFilter_AddRef
,
911 MessageFilter_Release
,
912 MessageFilter_HandleInComingCall
,
913 MessageFilter_RetryRejectedCall
,
914 MessageFilter_MessagePending
917 static IMessageFilter MessageFilter
= { &MessageFilter_Vtbl
};
919 static void test_CoRegisterMessageFilter(void)
922 IMessageFilter
*prev_filter
;
924 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
925 ok(hr
== CO_E_NOT_SUPPORTED
,
926 "CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08x\n",
929 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
930 prev_filter
= (IMessageFilter
*)0xdeadbeef;
931 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
932 ok(hr
== CO_E_NOT_SUPPORTED
,
933 "CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08x\n",
935 ok(prev_filter
== (IMessageFilter
*)0xdeadbeef,
936 "prev_filter should have been set to %p\n", prev_filter
);
939 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
941 hr
= CoRegisterMessageFilter(NULL
, NULL
);
942 ok_ole_success(hr
, "CoRegisterMessageFilter");
944 prev_filter
= (IMessageFilter
*)0xdeadbeef;
945 hr
= CoRegisterMessageFilter(NULL
, &prev_filter
);
946 ok_ole_success(hr
, "CoRegisterMessageFilter");
947 ok(prev_filter
== NULL
, "prev_filter should have been set to NULL instead of %p\n", prev_filter
);
949 hr
= CoRegisterMessageFilter(&MessageFilter
, &prev_filter
);
950 ok_ole_success(hr
, "CoRegisterMessageFilter");
951 ok(prev_filter
== NULL
, "prev_filter should have been set to NULL instead of %p\n", prev_filter
);
953 hr
= CoRegisterMessageFilter(NULL
, NULL
);
954 ok_ole_success(hr
, "CoRegisterMessageFilter");
959 static IUnknown Test_Unknown
;
961 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
963 return IUnknown_QueryInterface(&Test_Unknown
, riid
, ppv
);
966 static ULONG WINAPI
EnumOLEVERB_AddRef(IEnumOLEVERB
*iface
)
971 static ULONG WINAPI
EnumOLEVERB_Release(IEnumOLEVERB
*iface
)
976 static HRESULT WINAPI
EnumOLEVERB_Next(IEnumOLEVERB
*iface
, ULONG celt
, OLEVERB
*rgelt
, ULONG
*fetched
)
978 ok(0, "unexpected call\n");
982 static HRESULT WINAPI
EnumOLEVERB_Skip(IEnumOLEVERB
*iface
, ULONG celt
)
984 ok(0, "unexpected call\n");
988 static HRESULT WINAPI
EnumOLEVERB_Reset(IEnumOLEVERB
*iface
)
990 ok(0, "unexpected call\n");
994 static HRESULT WINAPI
EnumOLEVERB_Clone(IEnumOLEVERB
*iface
, IEnumOLEVERB
**ppenum
)
996 ok(0, "unexpected call\n");
1000 static const IEnumOLEVERBVtbl EnumOLEVERBVtbl
= {
1001 EnumOLEVERB_QueryInterface
,
1003 EnumOLEVERB_Release
,
1010 static IEnumOLEVERB EnumOLEVERB
= { &EnumOLEVERBVtbl
};
1012 static HRESULT WINAPI
Test_IUnknown_QueryInterface(
1017 if (ppvObj
== NULL
) return E_POINTER
;
1019 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IWineTest
)) {
1021 }else if(IsEqualIID(riid
, &IID_IEnumOLEVERB
)) {
1022 *ppvObj
= &EnumOLEVERB
;
1025 return E_NOINTERFACE
;
1028 IUnknown_AddRef((IUnknown
*)*ppvObj
);
1032 static ULONG WINAPI
Test_IUnknown_AddRef(IUnknown
*iface
)
1034 return 2; /* non-heap-based object */
1037 static ULONG WINAPI
Test_IUnknown_Release(IUnknown
*iface
)
1039 return 1; /* non-heap-based object */
1042 static const IUnknownVtbl TestUnknown_Vtbl
=
1044 Test_IUnknown_QueryInterface
,
1045 Test_IUnknown_AddRef
,
1046 Test_IUnknown_Release
,
1049 static IUnknown Test_Unknown
= { &TestUnknown_Vtbl
};
1051 static IPSFactoryBuffer
*ps_factory_buffer
;
1053 static HRESULT WINAPI
PSFactoryBuffer_QueryInterface(
1054 IPSFactoryBuffer
* This
,
1055 /* [in] */ REFIID riid
,
1056 /* [iid_is][out] */ void **ppvObject
)
1058 if (IsEqualIID(riid
, &IID_IUnknown
) ||
1059 IsEqualIID(riid
, &IID_IPSFactoryBuffer
))
1062 IPSFactoryBuffer_AddRef(This
);
1065 return E_NOINTERFACE
;
1068 static ULONG WINAPI
PSFactoryBuffer_AddRef(
1069 IPSFactoryBuffer
* This
)
1074 static ULONG WINAPI
PSFactoryBuffer_Release(
1075 IPSFactoryBuffer
* This
)
1080 static HRESULT WINAPI
PSFactoryBuffer_CreateProxy(
1081 IPSFactoryBuffer
* This
,
1082 /* [in] */ IUnknown
*pUnkOuter
,
1083 /* [in] */ REFIID riid
,
1084 /* [out] */ IRpcProxyBuffer
**ppProxy
,
1085 /* [out] */ void **ppv
)
1090 static HRESULT WINAPI
PSFactoryBuffer_CreateStub(
1091 IPSFactoryBuffer
* This
,
1092 /* [in] */ REFIID riid
,
1093 /* [unique][in] */ IUnknown
*pUnkServer
,
1094 /* [out] */ IRpcStubBuffer
**ppStub
)
1096 CHECK_EXPECT(CreateStub
);
1098 ok(pUnkServer
== (IUnknown
*)&Test_Unknown
, "unexpected pUnkServer %p\n", pUnkServer
);
1099 if(!ps_factory_buffer
)
1102 return IPSFactoryBuffer_CreateStub(ps_factory_buffer
, &IID_IEnumOLEVERB
, pUnkServer
, ppStub
);
1105 static IPSFactoryBufferVtbl PSFactoryBufferVtbl
=
1107 PSFactoryBuffer_QueryInterface
,
1108 PSFactoryBuffer_AddRef
,
1109 PSFactoryBuffer_Release
,
1110 PSFactoryBuffer_CreateProxy
,
1111 PSFactoryBuffer_CreateStub
1114 static IPSFactoryBuffer PSFactoryBuffer
= { &PSFactoryBufferVtbl
};
1116 static const CLSID CLSID_WineTestPSFactoryBuffer
=
1121 {0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd}
1122 }; /* 52011640-8164-4fd0-a1a2-5d5a3654d3bd */
1124 static void test_CoRegisterPSClsid(void)
1127 DWORD dwRegistrationKey
;
1131 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
1132 ok(hr
== CO_E_NOTINITIALIZED
, "CoRegisterPSClsid should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
1134 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1136 hr
= CoRegisterClassObject(&CLSID_WineTestPSFactoryBuffer
, (IUnknown
*)&PSFactoryBuffer
,
1137 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &dwRegistrationKey
);
1138 ok_ole_success(hr
, "CoRegisterClassObject");
1140 hr
= CoRegisterPSClsid(&IID_IWineTest
, &CLSID_WineTestPSFactoryBuffer
);
1141 ok_ole_success(hr
, "CoRegisterPSClsid");
1143 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
1144 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1146 SET_EXPECT(CreateStub
);
1147 hr
= CoMarshalInterface(stream
, &IID_IWineTest
, &Test_Unknown
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1148 ok(hr
== E_NOTIMPL
, "CoMarshalInterface should have returned E_NOTIMPL instead of 0x%08x\n", hr
);
1149 CHECK_CALLED(CreateStub
);
1151 hr
= CoGetPSClsid(&IID_IEnumOLEVERB
, &clsid
);
1152 ok_ole_success(hr
, "CoGetPSClsid");
1154 hr
= CoGetClassObject(&clsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IPSFactoryBuffer
, (void **)&ps_factory_buffer
);
1155 ok_ole_success(hr
, "CoGetClassObject");
1157 hr
= CoRegisterPSClsid(&IID_IEnumOLEVERB
, &CLSID_WineTestPSFactoryBuffer
);
1158 ok_ole_success(hr
, "CoRegisterPSClsid");
1160 SET_EXPECT(CreateStub
);
1161 hr
= CoMarshalInterface(stream
, &IID_IEnumOLEVERB
, (IUnknown
*)&EnumOLEVERB
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1162 ok(hr
== S_OK
, "CoMarshalInterface should have returned E_NOTIMPL instead of 0x%08x\n", hr
);
1163 CHECK_CALLED(CreateStub
);
1165 hr
= CoMarshalInterface(stream
, &IID_IEnumOLEVERB
, &Test_Unknown
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1166 ok(hr
== S_OK
, "CoMarshalInterface should have returned E_NOTIMPL instead of 0x%08x\n", hr
);
1168 IStream_Release(stream
);
1169 IPSFactoryBuffer_Release(ps_factory_buffer
);
1170 ps_factory_buffer
= NULL
;
1172 hr
= CoRevokeClassObject(dwRegistrationKey
);
1173 ok_ole_success(hr
, "CoRevokeClassObject");
1177 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1179 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1180 ok(hr
== REGDB_E_IIDNOTREG
, "CoGetPSClsid should have returned REGDB_E_IIDNOTREG instead of 0x%08x\n", hr
);
1185 static void test_CoGetPSClsid(void)
1193 const BOOL is_win64
= (sizeof(void*) != sizeof(int));
1194 BOOL is_wow64
= FALSE
;
1196 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1197 ok(hr
== CO_E_NOTINITIALIZED
,
1198 "CoGetPSClsid should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n",
1201 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1203 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1204 ok_ole_success(hr
, "CoGetPSClsid");
1206 hr
= CoGetPSClsid(&IID_IWineTest
, &clsid
);
1207 ok(hr
== REGDB_E_IIDNOTREG
,
1208 "CoGetPSClsid for random IID returned 0x%08x instead of REGDB_E_IIDNOTREG\n",
1211 hr
= CoGetPSClsid(&IID_IClassFactory
, NULL
);
1212 ok(hr
== E_INVALIDARG
,
1213 "CoGetPSClsid for null clsid returned 0x%08x instead of E_INVALIDARG\n",
1216 if (!pRegOverridePredefKey
)
1218 win_skip("RegOverridePredefKey not available\n");
1222 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1223 ok_ole_success(hr
, "CoGetPSClsid");
1225 res
= RegCreateKeyExA(HKEY_CURRENT_USER
, "Software\\Classes", 0, NULL
, 0,
1226 KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
);
1227 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1229 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, hkey
);
1230 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
1232 hr
= CoGetPSClsid(&IID_IClassFactory
, &clsid
);
1233 ok_ole_success(hr
, "CoGetPSClsid");
1235 res
= pRegOverridePredefKey(HKEY_CLASSES_ROOT
, NULL
);
1236 ok(!res
, "RegOverridePredefKey returned %d\n", res
);
1240 /* not registered CLSID */
1241 hr
= CoGetPSClsid(&IID_Testiface
, &clsid
);
1242 ok(hr
== REGDB_E_IIDNOTREG
, "got 0x%08x\n", hr
);
1244 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
1246 memset(&clsid
, 0, sizeof(clsid
));
1247 hr
= CoGetPSClsid(&IID_Testiface
, &clsid
);
1248 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1249 ok(IsEqualGUID(&clsid
, &IID_Testiface
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1251 memset(&clsid
, 0, sizeof(clsid
));
1252 hr
= CoGetPSClsid(&IID_Testiface2
, &clsid
);
1253 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1254 ok(IsEqualGUID(&clsid
, &IID_Testiface2
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1256 memset(&clsid
, 0, sizeof(clsid
));
1257 hr
= CoGetPSClsid(&IID_Testiface3
, &clsid
);
1258 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1259 ok(IsEqualGUID(&clsid
, &IID_TestPS
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1261 memset(&clsid
, 0xaa, sizeof(clsid
));
1262 hr
= CoGetPSClsid(&IID_Testiface4
, &clsid
);
1263 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1264 ok(IsEqualGUID(&clsid
, &GUID_NULL
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1266 /* register same interface and try to get CLSID back */
1267 hr
= CoRegisterPSClsid(&IID_Testiface
, &IID_Testiface4
);
1268 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1269 memset(&clsid
, 0, sizeof(clsid
));
1270 hr
= CoGetPSClsid(&IID_Testiface
, &clsid
);
1271 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1272 ok(IsEqualGUID(&clsid
, &IID_Testiface4
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1274 pDeactivateActCtx(0, cookie
);
1275 pReleaseActCtx(handle
);
1278 if (pRegDeleteKeyExA
&&
1280 (pIsWow64Process
&& pIsWow64Process(GetCurrentProcess(), &is_wow64
) && is_wow64
)))
1282 static GUID IID_DeadBeef
= {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
1283 static const char clsidDeadBeef
[] = "{deadbeef-dead-beef-dead-beefdeadbeef}";
1284 static const char clsidA
[] = "{66666666-8888-7777-6666-555555555555}";
1285 HKEY hkey_iface
, hkey_psclsid
;
1286 REGSAM opposite
= is_win64
? KEY_WOW64_32KEY
: KEY_WOW64_64KEY
;
1288 hr
= CoGetPSClsid(&IID_DeadBeef
, &clsid
);
1289 ok(hr
== REGDB_E_IIDNOTREG
, "got 0x%08x\n", hr
);
1291 res
= RegCreateKeyExA(HKEY_CLASSES_ROOT
, "Interface",
1292 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
, NULL
, &hkey_iface
, NULL
);
1293 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1294 res
= RegCreateKeyExA(hkey_iface
, clsidDeadBeef
,
1295 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
, NULL
, &hkey
, NULL
);
1296 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1297 res
= RegCreateKeyExA(hkey
, "ProxyStubClsid32",
1298 0, NULL
, 0, KEY_ALL_ACCESS
| opposite
, NULL
, &hkey_psclsid
, NULL
);
1299 ok(!res
, "RegCreateKeyEx returned %d\n", res
);
1300 res
= RegSetValueExA(hkey_psclsid
, NULL
, 0, REG_SZ
, (const BYTE
*)clsidA
, strlen(clsidA
)+1);
1301 ok(!res
, "RegSetValueEx returned %d\n", res
);
1302 RegCloseKey(hkey_psclsid
);
1304 hr
= CoGetPSClsid(&IID_DeadBeef
, &clsid
);
1305 ok_ole_success(hr
, "CoGetPSClsid");
1306 ok(IsEqualGUID(&clsid
, &IID_TestPS
), "got clsid %s\n", wine_dbgstr_guid(&clsid
));
1308 res
= pRegDeleteKeyExA(hkey
, "ProxyStubClsid32", opposite
, 0);
1309 ok(!res
, "RegDeleteKeyEx returned %d\n", res
);
1311 res
= pRegDeleteKeyExA(hkey_iface
, clsidDeadBeef
, opposite
, 0);
1312 ok(!res
, "RegDeleteKeyEx returned %d\n", res
);
1313 RegCloseKey(hkey_iface
);
1319 /* basic test, mainly for invalid arguments. see marshal.c for more */
1320 static void test_CoUnmarshalInterface(void)
1326 hr
= CoUnmarshalInterface(NULL
, &IID_IUnknown
, (void **)&pProxy
);
1327 ok(hr
== E_INVALIDARG
, "CoUnmarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1329 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
1330 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1332 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, (void **)&pProxy
);
1334 ok(hr
== CO_E_NOTINITIALIZED
, "CoUnmarshalInterface should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
1336 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1338 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, (void **)&pProxy
);
1339 ok(hr
== STG_E_READFAULT
, "CoUnmarshalInterface should have returned STG_E_READFAULT instead of 0x%08x\n", hr
);
1343 hr
= CoUnmarshalInterface(pStream
, &IID_IUnknown
, NULL
);
1344 ok(hr
== E_INVALIDARG
, "CoUnmarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1346 IStream_Release(pStream
);
1349 static void test_CoGetInterfaceAndReleaseStream(void)
1354 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1356 hr
= CoGetInterfaceAndReleaseStream(NULL
, &IID_IUnknown
, (void**)&pUnk
);
1357 ok(hr
== E_INVALIDARG
, "hr %08x\n", hr
);
1362 /* basic test, mainly for invalid arguments. see marshal.c for more */
1363 static void test_CoMarshalInterface(void)
1367 static const LARGE_INTEGER llZero
;
1369 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1371 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &pStream
);
1372 ok_ole_success(hr
, "CreateStreamOnHGlobal");
1374 hr
= CoMarshalInterface(pStream
, &IID_IUnknown
, NULL
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1375 ok(hr
== E_INVALIDARG
, "CoMarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1377 hr
= CoMarshalInterface(NULL
, &IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1378 ok(hr
== E_INVALIDARG
, "CoMarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1380 hr
= CoMarshalInterface(pStream
, &IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
1381 ok_ole_success(hr
, "CoMarshalInterface");
1383 /* stream not rewound */
1384 hr
= CoReleaseMarshalData(pStream
);
1385 ok(hr
== STG_E_READFAULT
, "CoReleaseMarshalData should have returned STG_E_READFAULT instead of 0x%08x\n", hr
);
1387 hr
= IStream_Seek(pStream
, llZero
, STREAM_SEEK_SET
, NULL
);
1388 ok_ole_success(hr
, "IStream_Seek");
1390 hr
= CoReleaseMarshalData(pStream
);
1391 ok_ole_success(hr
, "CoReleaseMarshalData");
1393 IStream_Release(pStream
);
1398 static void test_CoMarshalInterThreadInterfaceInStream(void)
1402 IClassFactory
*pProxy
;
1404 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1408 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, NULL
);
1409 ok(hr
== E_INVALIDARG
, "CoMarshalInterThreadInterfaceInStream should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1411 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, NULL
, &pStream
);
1412 ok(hr
== E_INVALIDARG
, "CoMarshalInterThreadInterfaceInStream should have returned E_INVALIDARG instead of 0x%08x\n", hr
);
1416 hr
= CoMarshalInterThreadInterfaceInStream(&IID_IUnknown
, (IUnknown
*)&Test_ClassFactory
, &pStream
);
1417 ok_ole_success(hr
, "CoMarshalInterThreadInterfaceInStream");
1419 ok_more_than_one_lock();
1421 hr
= CoUnmarshalInterface(pStream
, &IID_IClassFactory
, (void **)&pProxy
);
1422 ok_ole_success(hr
, "CoUnmarshalInterface");
1424 IClassFactory_Release(pProxy
);
1425 IStream_Release(pStream
);
1432 static void test_CoRegisterClassObject(void)
1434 ULONG_PTR ctxcookie
;
1440 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1442 /* CLSCTX_INPROC_SERVER */
1443 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1444 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1445 ok_ole_success(hr
, "CoRegisterClassObject");
1446 hr
= CoRevokeClassObject(cookie
);
1447 ok_ole_success(hr
, "CoRevokeClassObject");
1449 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1450 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
1451 ok_ole_success(hr
, "CoRegisterClassObject");
1452 hr
= CoRevokeClassObject(cookie
);
1453 ok_ole_success(hr
, "CoRevokeClassObject");
1455 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1456 CLSCTX_INPROC_SERVER
, REGCLS_MULTI_SEPARATE
, &cookie
);
1457 ok_ole_success(hr
, "CoRegisterClassObject");
1458 hr
= CoRevokeClassObject(cookie
);
1459 ok_ole_success(hr
, "CoRevokeClassObject");
1461 /* CLSCTX_LOCAL_SERVER */
1462 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1463 CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1464 ok_ole_success(hr
, "CoRegisterClassObject");
1465 hr
= CoRevokeClassObject(cookie
);
1466 ok_ole_success(hr
, "CoRevokeClassObject");
1468 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1469 CLSCTX_LOCAL_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
1470 ok_ole_success(hr
, "CoRegisterClassObject");
1471 hr
= CoRevokeClassObject(cookie
);
1472 ok_ole_success(hr
, "CoRevokeClassObject");
1474 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1475 CLSCTX_LOCAL_SERVER
, REGCLS_MULTI_SEPARATE
, &cookie
);
1476 ok_ole_success(hr
, "CoRegisterClassObject");
1477 hr
= CoRevokeClassObject(cookie
);
1478 ok_ole_success(hr
, "CoRevokeClassObject");
1480 /* CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER */
1481 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1482 CLSCTX_INPROC_SERVER
|CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1483 ok_ole_success(hr
, "CoRegisterClassObject");
1484 hr
= CoRevokeClassObject(cookie
);
1485 ok_ole_success(hr
, "CoRevokeClassObject");
1487 /* test whether an object that doesn't support IClassFactory can be
1488 * registered for CLSCTX_LOCAL_SERVER */
1489 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, &Test_Unknown
,
1490 CLSCTX_LOCAL_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1491 ok_ole_success(hr
, "CoRegisterClassObject");
1492 hr
= CoRevokeClassObject(cookie
);
1493 ok_ole_success(hr
, "CoRevokeClassObject");
1495 /* test whether registered class becomes invalid when apartment is destroyed */
1496 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1497 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1498 ok_ole_success(hr
, "CoRegisterClassObject");
1501 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1503 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
,
1504 &IID_IClassFactory
, (void **)&pcf
);
1505 ok(hr
== REGDB_E_CLASSNOTREG
, "object registered in an apartment shouldn't accessible after it is destroyed\n");
1507 /* crashes with at least win9x DCOM! */
1509 CoRevokeClassObject(cookie
);
1511 /* test that object is accessible */
1512 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
, CLSCTX_INPROC_SERVER
,
1513 REGCLS_MULTIPLEUSE
, &cookie
);
1514 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1516 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&pcf
);
1517 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1518 IClassFactory_Release(pcf
);
1520 /* context now contains CLSID_WineOOPTest, test if registered one could still be used */
1521 if ((handle
= activate_context(actctx_manifest
, &ctxcookie
)))
1523 hr
= CoGetClassObject(&CLSID_WineOOPTest
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&pcf
);
1525 ok(hr
== HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND
), "got 0x%08x\n", hr
);
1527 pDeactivateActCtx(0, ctxcookie
);
1528 pReleaseActCtx(handle
);
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 hr
= CoRevokeClassObject(cookie
);
1536 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1541 static HRESULT
get_class_object(CLSCTX clsctx
)
1546 hr
= CoGetClassObject(&CLSID_WineOOPTest
, clsctx
, NULL
, &IID_IClassFactory
,
1550 IClassFactory_Release(pcf
);
1555 static DWORD CALLBACK
get_class_object_thread(LPVOID pv
)
1557 CLSCTX clsctx
= (CLSCTX
)(DWORD_PTR
)pv
;
1560 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1562 hr
= get_class_object(clsctx
);
1569 static DWORD CALLBACK
get_class_object_proxy_thread(LPVOID pv
)
1571 CLSCTX clsctx
= (CLSCTX
)(DWORD_PTR
)pv
;
1576 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1578 hr
= CoGetClassObject(&CLSID_WineOOPTest
, clsctx
, NULL
, &IID_IClassFactory
,
1583 hr
= IClassFactory_QueryInterface(pcf
, &IID_IMultiQI
, (void **)&pMQI
);
1585 IMultiQI_Release(pMQI
);
1586 IClassFactory_Release(pcf
);
1594 static DWORD CALLBACK
register_class_object_thread(LPVOID pv
)
1599 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1601 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1602 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1609 static DWORD CALLBACK
revoke_class_object_thread(LPVOID pv
)
1611 DWORD cookie
= (DWORD_PTR
)pv
;
1614 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1616 hr
= CoRevokeClassObject(cookie
);
1623 static void test_registered_object_thread_affinity(void)
1631 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1633 /* CLSCTX_INPROC_SERVER */
1635 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1636 CLSCTX_INPROC_SERVER
, REGCLS_SINGLEUSE
, &cookie
);
1637 ok_ole_success(hr
, "CoRegisterClassObject");
1639 thread
= CreateThread(NULL
, 0, get_class_object_thread
, (LPVOID
)CLSCTX_INPROC_SERVER
, 0, &tid
);
1640 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1641 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1642 GetExitCodeThread(thread
, &exitcode
);
1644 ok(hr
== REGDB_E_CLASSNOTREG
, "CoGetClassObject on inproc object "
1645 "registered in different thread should return REGDB_E_CLASSNOTREG "
1646 "instead of 0x%08x\n", hr
);
1648 hr
= get_class_object(CLSCTX_INPROC_SERVER
);
1649 ok(hr
== S_OK
, "CoGetClassObject on inproc object registered in same "
1650 "thread should return S_OK instead of 0x%08x\n", hr
);
1652 thread
= CreateThread(NULL
, 0, register_class_object_thread
, NULL
, 0, &tid
);
1653 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1654 ok ( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1655 GetExitCodeThread(thread
, &exitcode
);
1657 ok(hr
== S_OK
, "CoRegisterClassObject with same CLSID but in different thread should return S_OK instead of 0x%08x\n", hr
);
1659 hr
= CoRevokeClassObject(cookie
);
1660 ok_ole_success(hr
, "CoRevokeClassObject");
1662 /* CLSCTX_LOCAL_SERVER */
1664 hr
= CoRegisterClassObject(&CLSID_WineOOPTest
, (IUnknown
*)&Test_ClassFactory
,
1665 CLSCTX_LOCAL_SERVER
, REGCLS_MULTIPLEUSE
, &cookie
);
1666 ok_ole_success(hr
, "CoRegisterClassObject");
1668 thread
= CreateThread(NULL
, 0, get_class_object_proxy_thread
, (LPVOID
)CLSCTX_LOCAL_SERVER
, 0, &tid
);
1669 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1670 while (MsgWaitForMultipleObjects(1, &thread
, FALSE
, 10000, QS_ALLINPUT
) == WAIT_OBJECT_0
+ 1)
1673 while (PeekMessageA(&msg
, NULL
, 0, 0, PM_REMOVE
))
1675 TranslateMessage(&msg
);
1676 DispatchMessageA(&msg
);
1679 GetExitCodeThread(thread
, &exitcode
);
1681 ok(hr
== S_OK
, "CoGetClassObject on local server object "
1682 "registered in different thread should return S_OK "
1683 "instead of 0x%08x\n", hr
);
1685 hr
= get_class_object(CLSCTX_LOCAL_SERVER
);
1686 ok(hr
== S_OK
, "CoGetClassObject on local server object registered in same "
1687 "thread should return S_OK instead of 0x%08x\n", hr
);
1689 thread
= CreateThread(NULL
, 0, revoke_class_object_thread
, (LPVOID
)(DWORD_PTR
)cookie
, 0, &tid
);
1690 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1691 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1692 GetExitCodeThread(thread
, &exitcode
);
1694 ok(hr
== RPC_E_WRONG_THREAD
|| broken(hr
== S_OK
) /* win8 */, "CoRevokeClassObject called from different "
1695 "thread to where registered should return RPC_E_WRONG_THREAD instead of 0x%08x\n", hr
);
1697 thread
= CreateThread(NULL
, 0, register_class_object_thread
, NULL
, 0, &tid
);
1698 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1699 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1700 GetExitCodeThread(thread
, &exitcode
);
1702 ok(hr
== S_OK
, "CoRegisterClassObject with same CLSID but in different "
1703 "thread should return S_OK instead of 0x%08x\n", hr
);
1705 hr
= CoRevokeClassObject(cookie
);
1706 ok_ole_success(hr
, "CoRevokeClassObject");
1711 static DWORD CALLBACK
free_libraries_thread(LPVOID p
)
1713 CoFreeUnusedLibraries();
1717 static inline BOOL
is_module_loaded(const char *module
)
1719 return GetModuleHandleA(module
) != 0;
1722 static void test_CoFreeUnusedLibraries(void)
1729 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1731 ok(!is_module_loaded("urlmon.dll"), "urlmon.dll shouldn't be loaded\n");
1733 hr
= CoCreateInstance(&CLSID_FileProtocol
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IInternetProtocol
, (void **)&pUnk
);
1734 if (hr
== REGDB_E_CLASSNOTREG
)
1736 skip("IE not installed so can't run CoFreeUnusedLibraries test\n");
1740 ok_ole_success(hr
, "CoCreateInstance");
1742 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1745 broken(pUnk
== NULL
), /* win9x */
1746 "Expected a valid pointer\n");
1748 IUnknown_Release(pUnk
);
1750 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1752 thread
= CreateThread(NULL
, 0, free_libraries_thread
, NULL
, 0, &tid
);
1753 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1754 CloseHandle(thread
);
1756 ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
1758 CoFreeUnusedLibraries();
1760 ok(!is_module_loaded("urlmon.dll"), "urlmon.dll shouldn't be loaded\n");
1765 static void test_CoGetObjectContext(void)
1769 IComThreadingInfo
*pComThreadingInfo
;
1770 IContextCallback
*pContextCallback
;
1771 IObjContext
*pObjContext
;
1776 DWORD tid
, exitcode
;
1778 if (!pCoGetObjectContext
)
1780 skip("CoGetObjectContext not present\n");
1784 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1785 ok(hr
== CO_E_NOTINITIALIZED
, "CoGetObjectContext should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr
);
1786 ok(pComThreadingInfo
== NULL
, "pComThreadingInfo should have been set to NULL\n");
1788 /* show that COM doesn't have to be initialized for multi-threaded apartments if another
1789 thread has already done so */
1791 info
.wait
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
1792 ok(info
.wait
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
1794 info
.stop
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
1795 ok(info
.stop
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
1797 thread
= CreateThread(NULL
, 0, ole_initialize_thread
, &info
, 0, &tid
);
1798 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
1800 ok( !WaitForSingleObject(info
.wait
, 10000), "wait timed out\n" );
1802 pComThreadingInfo
= NULL
;
1803 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1804 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
1805 IComThreadingInfo_Release(pComThreadingInfo
);
1807 SetEvent(info
.stop
);
1808 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
1810 GetExitCodeThread(thread
, &exitcode
);
1812 ok(hr
== S_OK
, "thread should have returned S_OK instead of 0x%08x\n", hr
);
1814 CloseHandle(thread
);
1815 CloseHandle(info
.wait
);
1816 CloseHandle(info
.stop
);
1818 pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1820 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1821 ok_ole_success(hr
, "CoGetObjectContext");
1823 hr
= IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo
, &apttype
);
1824 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentApartmentType");
1825 ok(apttype
== APTTYPE_MAINSTA
, "apartment type should be APTTYPE_MAINSTA instead of %d\n", apttype
);
1827 hr
= IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo
, &thdtype
);
1828 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentThreadType");
1829 ok(thdtype
== THDTYPE_PROCESSMESSAGES
, "thread type should be THDTYPE_PROCESSMESSAGES instead of %d\n", thdtype
);
1831 refs
= IComThreadingInfo_Release(pComThreadingInfo
);
1832 ok(refs
== 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs
);
1834 hr
= pCoGetObjectContext(&IID_IContextCallback
, (void **)&pContextCallback
);
1835 ok_ole_success(hr
, "CoGetObjectContext(ContextCallback)");
1839 refs
= IContextCallback_Release(pContextCallback
);
1840 ok(refs
== 0, "pContextCallback should have 0 refs instead of %d refs\n", refs
);
1845 pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
1847 hr
= pCoGetObjectContext(&IID_IComThreadingInfo
, (void **)&pComThreadingInfo
);
1848 ok_ole_success(hr
, "CoGetObjectContext");
1850 hr
= IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo
, &apttype
);
1851 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentApartmentType");
1852 ok(apttype
== APTTYPE_MTA
, "apartment type should be APTTYPE_MTA instead of %d\n", apttype
);
1854 hr
= IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo
, &thdtype
);
1855 ok_ole_success(hr
, "IComThreadingInfo_GetCurrentThreadType");
1856 ok(thdtype
== THDTYPE_BLOCKMESSAGES
, "thread type should be THDTYPE_BLOCKMESSAGES instead of %d\n", thdtype
);
1858 refs
= IComThreadingInfo_Release(pComThreadingInfo
);
1859 ok(refs
== 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs
);
1861 hr
= pCoGetObjectContext(&IID_IContextCallback
, (void **)&pContextCallback
);
1862 ok_ole_success(hr
, "CoGetObjectContext(ContextCallback)");
1866 refs
= IContextCallback_Release(pContextCallback
);
1867 ok(refs
== 0, "pContextCallback should have 0 refs instead of %d refs\n", refs
);
1870 hr
= pCoGetObjectContext(&IID_IObjContext
, (void **)&pObjContext
);
1871 ok_ole_success(hr
, "CoGetObjectContext");
1873 refs
= IObjContext_Release(pObjContext
);
1874 ok(refs
== 0, "pObjContext should have 0 refs instead of %d refs\n", refs
);
1880 IUnknown IUnknown_iface
;
1884 static inline Test_CallContext
*impl_from_IUnknown(IUnknown
*iface
)
1886 return CONTAINING_RECORD(iface
, Test_CallContext
, IUnknown_iface
);
1889 static HRESULT WINAPI
Test_CallContext_QueryInterface(
1894 if (ppvObj
== NULL
) return E_POINTER
;
1896 if (IsEqualGUID(riid
, &IID_IUnknown
))
1899 IUnknown_AddRef(iface
);
1904 return E_NOINTERFACE
;
1907 static ULONG WINAPI
Test_CallContext_AddRef(IUnknown
*iface
)
1909 Test_CallContext
*This
= impl_from_IUnknown(iface
);
1910 return InterlockedIncrement(&This
->refs
);
1913 static ULONG WINAPI
Test_CallContext_Release(IUnknown
*iface
)
1915 Test_CallContext
*This
= impl_from_IUnknown(iface
);
1916 ULONG refs
= InterlockedDecrement(&This
->refs
);
1918 HeapFree(GetProcessHeap(), 0, This
);
1922 static const IUnknownVtbl TestCallContext_Vtbl
=
1924 Test_CallContext_QueryInterface
,
1925 Test_CallContext_AddRef
,
1926 Test_CallContext_Release
1929 static void test_CoGetCallContext(void)
1934 Test_CallContext
*test_object
;
1936 if (!pCoSwitchCallContext
)
1938 skip("CoSwitchCallContext not present\n");
1944 test_object
= HeapAlloc(GetProcessHeap(), 0, sizeof(Test_CallContext
));
1945 test_object
->IUnknown_iface
.lpVtbl
= &TestCallContext_Vtbl
;
1946 test_object
->refs
= 1;
1948 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
1949 ok(hr
== RPC_E_CALL_COMPLETE
, "Expected RPC_E_CALL_COMPLETE, got 0x%08x\n", hr
);
1951 pUnk
= (IUnknown
*)0xdeadbeef;
1952 hr
= pCoSwitchCallContext(&test_object
->IUnknown_iface
, &pUnk
);
1953 ok_ole_success(hr
, "CoSwitchCallContext");
1954 ok(pUnk
== NULL
, "expected NULL, got %p\n", pUnk
);
1955 refs
= IUnknown_AddRef(&test_object
->IUnknown_iface
);
1956 ok(refs
== 2, "Expected refcount 2, got %d\n", refs
);
1957 IUnknown_Release(&test_object
->IUnknown_iface
);
1959 pUnk
= (IUnknown
*)0xdeadbeef;
1960 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
1961 ok_ole_success(hr
, "CoGetCallContext");
1962 ok(pUnk
== &test_object
->IUnknown_iface
, "expected %p, got %p\n",
1963 &test_object
->IUnknown_iface
, pUnk
);
1964 refs
= IUnknown_AddRef(&test_object
->IUnknown_iface
);
1965 ok(refs
== 3, "Expected refcount 3, got %d\n", refs
);
1966 IUnknown_Release(&test_object
->IUnknown_iface
);
1967 IUnknown_Release(pUnk
);
1969 pUnk
= (IUnknown
*)0xdeadbeef;
1970 hr
= pCoSwitchCallContext(NULL
, &pUnk
);
1971 ok_ole_success(hr
, "CoSwitchCallContext");
1972 ok(pUnk
== &test_object
->IUnknown_iface
, "expected %p, got %p\n",
1973 &test_object
->IUnknown_iface
, pUnk
);
1974 refs
= IUnknown_AddRef(&test_object
->IUnknown_iface
);
1975 ok(refs
== 2, "Expected refcount 2, got %d\n", refs
);
1976 IUnknown_Release(&test_object
->IUnknown_iface
);
1978 hr
= CoGetCallContext(&IID_IUnknown
, (void**)&pUnk
);
1979 ok(hr
== RPC_E_CALL_COMPLETE
, "Expected RPC_E_CALL_COMPLETE, got 0x%08x\n", hr
);
1981 IUnknown_Release(&test_object
->IUnknown_iface
);
1986 static void test_CoGetContextToken(void)
1994 DWORD tid
, exitcode
;
1996 if (!pCoGetContextToken
)
1998 win_skip("CoGetContextToken not present\n");
2003 hr
= pCoGetContextToken(&token
);
2004 ok(hr
== CO_E_NOTINITIALIZED
, "Expected CO_E_NOTINITIALIZED, got 0x%08x\n", hr
);
2005 ok(token
== 0xdeadbeef, "Expected 0, got 0x%lx\n", token
);
2007 /* show that COM doesn't have to be initialized for multi-threaded apartments if another
2008 thread has already done so */
2010 info
.wait
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
2011 ok(info
.wait
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
2013 info
.stop
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
2014 ok(info
.stop
!= NULL
, "CreateEvent failed with error %d\n", GetLastError());
2016 thread
= CreateThread(NULL
, 0, ole_initialize_thread
, &info
, 0, &tid
);
2017 ok(thread
!= NULL
, "CreateThread failed with error %d\n", GetLastError());
2019 ok( !WaitForSingleObject(info
.wait
, 10000), "wait timed out\n" );
2022 hr
= pCoGetContextToken(&token
);
2023 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2025 SetEvent(info
.stop
);
2026 ok( !WaitForSingleObject(thread
, 10000), "wait timed out\n" );
2028 GetExitCodeThread(thread
, &exitcode
);
2030 ok(hr
== S_OK
, "thread should have returned S_OK instead of 0x%08x\n", hr
);
2032 CloseHandle(thread
);
2033 CloseHandle(info
.wait
);
2034 CloseHandle(info
.stop
);
2038 hr
= pCoGetContextToken(NULL
);
2039 ok(hr
== E_POINTER
, "Expected E_POINTER, got 0x%08x\n", hr
);
2042 hr
= pCoGetContextToken(&token
);
2043 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2044 ok(token
, "Expected token != 0\n");
2046 refs
= IUnknown_AddRef((IUnknown
*)token
);
2047 todo_wine
ok(refs
== 1, "Expected 1, got %u\n", refs
);
2049 hr
= pCoGetObjectContext(&IID_IObjContext
, (void **)&ctx
);
2050 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2051 todo_wine
ok(ctx
== (IObjContext
*)token
, "Expected interface pointers to be the same\n");
2053 refs
= IObjContext_AddRef(ctx
);
2054 todo_wine
ok(refs
== 3, "Expected 3, got %u\n", refs
);
2056 refs
= IObjContext_Release(ctx
);
2057 todo_wine
ok(refs
== 2, "Expected 2, got %u\n", refs
);
2059 refs
= IUnknown_Release((IUnknown
*)token
);
2060 ok(refs
== 1, "Expected 1, got %u\n", refs
);
2062 /* CoGetContextToken does not add a reference */
2064 hr
= pCoGetContextToken(&token
);
2065 ok(hr
== S_OK
, "Expected S_OK, got 0x%08x\n", hr
);
2066 ok(token
, "Expected token != 0\n");
2067 todo_wine
ok(ctx
== (IObjContext
*)token
, "Expected interface pointers to be the same\n");
2069 refs
= IObjContext_AddRef(ctx
);
2070 ok(refs
== 2, "Expected 1, got %u\n", refs
);
2072 refs
= IObjContext_Release(ctx
);
2073 ok(refs
== 1, "Expected 0, got %u\n", refs
);
2075 refs
= IObjContext_Release(ctx
);
2076 ok(refs
== 0, "Expected 0, got %u\n", refs
);
2081 static void test_TreatAsClass(void)
2085 static GUID deadbeef
= {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}};
2086 static const char deadbeefA
[] = "{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}";
2087 IInternetProtocol
*pIP
= NULL
;
2088 HKEY clsidkey
, deadbeefkey
;
2091 if (!pCoGetTreatAsClass
)
2093 win_skip("CoGetTreatAsClass not present\n");
2096 hr
= pCoGetTreatAsClass(&deadbeef
,&out
);
2097 ok (hr
== S_FALSE
, "expected S_FALSE got %x\n",hr
);
2098 ok (IsEqualGUID(&out
,&deadbeef
), "expected to get same clsid back\n");
2100 lr
= RegOpenKeyExA(HKEY_CLASSES_ROOT
, "CLSID", 0, KEY_READ
, &clsidkey
);
2101 ok(!lr
, "Couldn't open CLSID key, error %d\n", lr
);
2103 lr
= RegCreateKeyExA(clsidkey
, deadbeefA
, 0, NULL
, 0, KEY_WRITE
, NULL
, &deadbeefkey
, NULL
);
2105 win_skip("CoGetTreatAsClass() tests will be skipped (failed to create a test key, error %d)\n", lr
);
2106 RegCloseKey(clsidkey
);
2110 hr
= pCoTreatAsClass(&deadbeef
, &deadbeef
);
2111 ok(hr
== REGDB_E_WRITEREGDB
, "CoTreatAsClass gave wrong error: %08x\n", hr
);
2113 hr
= pCoTreatAsClass(&deadbeef
, &CLSID_FileProtocol
);
2114 if(hr
== REGDB_E_WRITEREGDB
){
2115 win_skip("Insufficient privileges to use CoTreatAsClass\n");
2118 ok(hr
== S_OK
, "CoTreatAsClass failed: %08x\n", hr
);
2120 hr
= pCoGetTreatAsClass(&deadbeef
, &out
);
2121 ok(hr
== S_OK
, "CoGetTreatAsClass failed: %08x\n",hr
);
2122 ok(IsEqualGUID(&out
, &CLSID_FileProtocol
), "expected to get substituted clsid\n");
2124 OleInitialize(NULL
);
2126 hr
= CoCreateInstance(&deadbeef
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IInternetProtocol
, (void **)&pIP
);
2127 if(hr
== REGDB_E_CLASSNOTREG
)
2129 win_skip("IE not installed so can't test CoCreateInstance\n");
2133 ok(hr
== S_OK
, "CoCreateInstance failed: %08x\n", hr
);
2135 IInternetProtocol_Release(pIP
);
2139 hr
= pCoTreatAsClass(&deadbeef
, &CLSID_NULL
);
2140 ok(hr
== S_OK
, "CoTreatAsClass failed: %08x\n", hr
);
2142 hr
= pCoGetTreatAsClass(&deadbeef
, &out
);
2143 ok(hr
== S_FALSE
, "expected S_FALSE got %08x\n", hr
);
2144 ok(IsEqualGUID(&out
, &deadbeef
), "expected to get same clsid back\n");
2146 /* bizarrely, native's CoTreatAsClass takes some time to take effect in CoCreateInstance */
2149 hr
= CoCreateInstance(&deadbeef
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IInternetProtocol
, (void **)&pIP
);
2150 ok(hr
== REGDB_E_CLASSNOTREG
, "CoCreateInstance gave wrong error: %08x\n", hr
);
2153 IInternetProtocol_Release(pIP
);
2157 RegCloseKey(deadbeefkey
);
2158 RegDeleteKeyA(clsidkey
, deadbeefA
);
2159 RegCloseKey(clsidkey
);
2162 static void test_CoInitializeEx(void)
2166 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2167 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2169 /* Calling OleInitialize for the first time should yield S_OK even with
2170 * apartment already initialized by previous CoInitialize(Ex) calls. */
2171 hr
= OleInitialize(NULL
);
2172 ok(hr
== S_OK
, "OleInitialize failed with error 0x%08x\n", hr
);
2174 /* Subsequent calls to OleInitialize should return S_FALSE */
2175 hr
= OleInitialize(NULL
);
2176 ok(hr
== S_FALSE
, "Expected S_FALSE, hr = 0x%08x\n", hr
);
2184 static void test_OleInitialize_InitCounting(void)
2188 REFCLSID rclsid
= &CLSID_InternetZoneManager
;
2190 /* 1. OleInitialize fails but OleUnintialize is still called: apartment stays inited */
2191 hr
= pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
2192 ok(hr
== S_OK
, "CoInitializeEx(COINIT_MULTITHREADED) failed with error 0x%08x\n", hr
);
2194 hr
= OleInitialize(NULL
);
2195 ok(hr
== RPC_E_CHANGED_MODE
, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", RPC_E_CHANGED_MODE
, hr
);
2198 pUnk
= (IUnknown
*)0xdeadbeef;
2199 hr
= CoCreateInstance(rclsid
, NULL
, 0x17, &IID_IUnknown
, (void **)&pUnk
);
2200 ok(hr
== S_OK
, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", S_OK
, hr
);
2201 if (pUnk
) IUnknown_Release(pUnk
);
2205 /* 2. Extra multiple OleUninitialize: apartment stays inited until CoUnitialize */
2206 hr
= CoInitialize(NULL
);
2207 ok(hr
== S_OK
, "CoInitialize() failed with error 0x%08x\n", hr
);
2209 hr
= OleInitialize(NULL
);
2210 ok(hr
== S_OK
, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", S_OK
, hr
);
2215 pUnk
= (IUnknown
*)0xdeadbeef;
2216 hr
= CoCreateInstance(rclsid
, NULL
, 0x17, &IID_IUnknown
, (void **)&pUnk
);
2217 ok(hr
== S_OK
, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", S_OK
, hr
);
2218 if (pUnk
) IUnknown_Release(pUnk
);
2222 pUnk
= (IUnknown
*)0xdeadbeef;
2223 hr
= CoCreateInstance(rclsid
, NULL
, 0x17, &IID_IUnknown
, (void **)&pUnk
);
2224 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", CO_E_NOTINITIALIZED
, hr
);
2225 if (pUnk
) IUnknown_Release(pUnk
);
2227 /* 3. CoUninitialize does not formally deinit Ole */
2228 hr
= CoInitialize(NULL
);
2229 ok(hr
== S_OK
, "CoInitialize() failed with error 0x%08x\n", hr
);
2231 hr
= OleInitialize(NULL
);
2232 ok(hr
== S_OK
, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", S_OK
, hr
);
2237 pUnk
= (IUnknown
*)0xdeadbeef;
2238 hr
= CoCreateInstance(rclsid
, NULL
, 0x17, &IID_IUnknown
, (void **)&pUnk
);
2239 ok(hr
== CO_E_NOTINITIALIZED
, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", CO_E_NOTINITIALIZED
, hr
);
2240 /* COM is not initialized anymore */
2241 if (pUnk
) IUnknown_Release(pUnk
);
2243 hr
= OleInitialize(NULL
);
2244 ok(hr
== S_FALSE
, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", S_FALSE
, hr
);
2245 /* ... but native OleInit returns S_FALSE as if Ole is considered initialized */
2251 static void test_OleRegGetMiscStatus(void)
2258 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_ICON
, NULL
);
2259 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2261 status
= 0xdeadbeef;
2262 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_ICON
, &status
);
2263 ok(hr
== REGDB_E_CLASSNOTREG
, "got 0x%08x\n", hr
);
2264 ok(status
== 0, "got 0x%08x\n", status
);
2267 hr
= OleRegGetMiscStatus(&CLSID_StdFont
, DVASPECT_ICON
, &status
);
2268 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2269 ok(status
== 0, "got 0x%08x\n", status
);
2271 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
2274 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_ICON
, &status
);
2275 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2276 ok(status
== OLEMISC_RECOMPOSEONRESIZE
, "got 0x%08x\n", status
);
2278 /* context data takes precedence over registration info */
2280 hr
= OleRegGetMiscStatus(&CLSID_StdFont
, DVASPECT_ICON
, &status
);
2281 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2282 ok(status
== OLEMISC_RECOMPOSEONRESIZE
, "got 0x%08x\n", status
);
2284 /* there's no such attribute in context */
2286 hr
= OleRegGetMiscStatus(&CLSID_Testclass
, DVASPECT_DOCPRINT
, &status
);
2287 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2288 ok(status
== 0, "got 0x%08x\n", status
);
2290 pDeactivateActCtx(0, cookie
);
2291 pReleaseActCtx(handle
);
2295 static void test_OleRegGetUserType(void)
2297 static const WCHAR stdfont_usertypeW
[] = {'S','t','a','n','d','a','r','d',' ','F','o','n','t',0};
2298 static const WCHAR stdfont2_usertypeW
[] = {'C','L','S','I','D','_','S','t','d','F','o','n','t',0};
2299 static const WCHAR clsidkeyW
[] = {'C','L','S','I','D',0};
2300 static const WCHAR defvalueW
[] = {'D','e','f','a','u','l','t',' ','N','a','m','e',0};
2301 static const WCHAR auxvalue0W
[] = {'A','u','x',' ','N','a','m','e',' ','0',0};
2302 static const WCHAR auxvalue2W
[] = {'A','u','x',' ','N','a','m','e',' ','2',0};
2303 static const WCHAR auxvalue3W
[] = {'A','u','x',' ','N','a','m','e',' ','3',0};
2304 static const WCHAR auxvalue4W
[] = {'A','u','x',' ','N','a','m','e',' ','4',0};
2306 static const char auxvalues
[][16] = {
2314 HKEY clsidhkey
, hkey
, auxhkey
, classkey
;
2315 DWORD form
, ret
, disposition
;
2323 for (form
= 0; form
<= USERCLASSTYPE_APPNAME
+1; form
++) {
2324 hr
= OleRegGetUserType(&CLSID_Testclass
, form
, NULL
);
2325 ok(hr
== E_INVALIDARG
, "form %u: got 0x%08x\n", form
, hr
);
2327 str
= (void*)0xdeadbeef;
2328 hr
= OleRegGetUserType(&CLSID_Testclass
, form
, &str
);
2329 ok(hr
== REGDB_E_CLASSNOTREG
, "form %u: got 0x%08x\n", form
, hr
);
2330 ok(str
== NULL
, "form %u: got %p\n", form
, str
);
2332 /* same string returned for StdFont for all form types */
2334 hr
= OleRegGetUserType(&CLSID_StdFont
, form
, &str
);
2335 ok(hr
== S_OK
, "form %u: got 0x%08x\n", form
, hr
);
2336 ok(!lstrcmpW(str
, stdfont_usertypeW
) || !lstrcmpW(str
, stdfont2_usertypeW
) /* winxp */,
2337 "form %u, got %s\n", form
, wine_dbgstr_w(str
));
2341 if ((handle
= activate_context(actctx_manifest
, &cookie
)))
2343 for (form
= 0; form
<= USERCLASSTYPE_APPNAME
+1; form
++) {
2344 str
= (void*)0xdeadbeef;
2345 hr
= OleRegGetUserType(&CLSID_Testclass
, form
, &str
);
2346 ok(hr
== REGDB_E_CLASSNOTREG
, "form %u: got 0x%08x\n", form
, hr
);
2347 ok(str
== NULL
, "form %u: got %s\n", form
, wine_dbgstr_w(str
));
2349 /* same string returned for StdFont for all form types */
2351 hr
= OleRegGetUserType(&CLSID_StdFont
, form
, &str
);
2352 ok(hr
== S_OK
, "form %u: got 0x%08x\n", form
, hr
);
2353 ok(!lstrcmpW(str
, stdfont_usertypeW
) || !lstrcmpW(str
, stdfont2_usertypeW
) /* winxp */,
2354 "form %u, got %s\n", form
, wine_dbgstr_w(str
));
2358 pDeactivateActCtx(0, cookie
);
2359 pReleaseActCtx(handle
);
2362 /* test using registered CLSID */
2363 StringFromGUID2(&CLSID_non_existent
, clsidW
, sizeof(clsidW
)/sizeof(clsidW
[0]));
2365 ret
= RegCreateKeyExW(HKEY_CLASSES_ROOT
, clsidkeyW
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &clsidhkey
, &disposition
);
2368 ret
= RegCreateKeyExW(clsidhkey
, clsidW
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &classkey
, NULL
);
2370 RegCloseKey(clsidhkey
);
2373 if (ret
== ERROR_ACCESS_DENIED
)
2375 win_skip("Failed to create test key, skipping some of OleRegGetUserType() tests.\n");
2379 ok(!ret
, "failed to create a key, error %d\n", ret
);
2381 ret
= RegSetValueExW(classkey
, NULL
, 0, REG_SZ
, (const BYTE
*)defvalueW
, sizeof(defvalueW
));
2382 ok(!ret
, "got error %d\n", ret
);
2384 ret
= RegCreateKeyExA(classkey
, "AuxUserType", 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &auxhkey
, NULL
);
2385 ok(!ret
, "got error %d\n", ret
);
2387 /* populate AuxUserType */
2388 for (i
= 0; i
<= 4; i
++) {
2391 sprintf(name
, "AuxUserType\\%d", i
);
2392 ret
= RegCreateKeyExA(classkey
, name
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
);
2393 ok(!ret
, "got error %d\n", ret
);
2395 ret
= RegSetValueExA(hkey
, NULL
, 0, REG_SZ
, (const BYTE
*)auxvalues
[i
], strlen(auxvalues
[i
]));
2396 ok(!ret
, "got error %d\n", ret
);
2401 hr
= OleRegGetUserType(&CLSID_non_existent
, 0, &str
);
2402 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2403 ok(!lstrcmpW(str
, auxvalue0W
), "got %s\n", wine_dbgstr_w(str
));
2407 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_FULL
, &str
);
2408 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2409 ok(!lstrcmpW(str
, defvalueW
), "got %s\n", wine_dbgstr_w(str
));
2413 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_SHORT
, &str
);
2414 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2415 ok(!lstrcmpW(str
, auxvalue2W
), "got %s\n", wine_dbgstr_w(str
));
2419 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_APPNAME
, &str
);
2420 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2421 ok(!lstrcmpW(str
, auxvalue3W
), "got %s\n", wine_dbgstr_w(str
));
2425 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_APPNAME
+1, &str
);
2426 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2427 ok(!lstrcmpW(str
, auxvalue4W
), "got %s\n", wine_dbgstr_w(str
));
2431 hr
= OleRegGetUserType(&CLSID_non_existent
, USERCLASSTYPE_APPNAME
+2, &str
);
2432 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2433 ok(!lstrcmpW(str
, defvalueW
), "got %s\n", wine_dbgstr_w(str
));
2436 /* registry cleanup */
2437 for (i
= 0; i
<= 4; i
++)
2440 sprintf(name
, "%d", i
);
2441 RegDeleteKeyA(auxhkey
, name
);
2443 RegCloseKey(auxhkey
);
2444 RegDeleteKeyA(classkey
, "AuxUserType");
2445 RegCloseKey(classkey
);
2446 RegDeleteKeyW(clsidhkey
, clsidW
);
2447 RegCloseKey(clsidhkey
);
2448 if (disposition
== REG_CREATED_NEW_KEY
)
2449 RegDeleteKeyA(HKEY_CLASSES_ROOT
, "CLSID");
2452 static void test_CoCreateGuid(void)
2456 hr
= CoCreateGuid(NULL
);
2457 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2460 static void CALLBACK
apc_test_proc(ULONG_PTR param
)
2465 static DWORD CALLBACK
release_semaphore_thread( LPVOID arg
)
2467 HANDLE handle
= arg
;
2468 if (WaitForSingleObject(handle
, 200) == WAIT_TIMEOUT
)
2469 ReleaseSemaphore(handle
, 1, NULL
);
2473 static DWORD CALLBACK
send_message_thread(LPVOID arg
)
2477 SendMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2481 static DWORD CALLBACK
post_message_thread(LPVOID arg
)
2485 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2489 static const char cls_name
[] = "cowait_test_class";
2490 static DWORD CALLBACK
test_CoWaitForMultipleHandles_thread(LPVOID arg
)
2492 HANDLE
*handles
= arg
;
2499 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2500 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2502 hWnd
= CreateWindowExA(0, cls_name
, "Test (thread)", WS_TILEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
2503 ok(hWnd
!= 0, "CreateWindowExA failed %u\n", GetLastError());
2506 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2507 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2508 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2509 ok(index
==0 || index
==0xdeadbeef/* Win 8 */, "expected index 0, got %u\n", index
);
2510 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2511 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2514 PostMessageA(hWnd
, WM_USER
, 0, 0);
2515 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2516 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2517 ok(index
==0 || index
==0xdeadbeef/* Win 8 */, "expected index 0, got %u\n", index
);
2518 success
= PeekMessageA(&msg
, hWnd
, WM_USER
, WM_USER
, PM_REMOVE
);
2519 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2521 DestroyWindow(hWnd
);
2526 static void test_CoWaitForMultipleHandles(void)
2528 HANDLE handles
[2], thread
;
2536 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2537 ok(hr
== S_OK
, "CoInitializeEx failed with error 0x%08x\n", hr
);
2539 memset(&wc
, 0, sizeof(wc
));
2540 wc
.cbSize
= sizeof(wc
);
2541 wc
.style
= CS_VREDRAW
| CS_HREDRAW
;
2542 wc
.hInstance
= GetModuleHandleA(0);
2543 wc
.hCursor
= LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
);
2544 wc
.hbrBackground
= NULL
;
2545 wc
.lpszClassName
= cls_name
;
2546 wc
.lpfnWndProc
= DefWindowProcA
;
2547 success
= RegisterClassExA(&wc
) != 0;
2548 ok(success
, "RegisterClassExA failed %u\n", GetLastError());
2550 hWnd
= CreateWindowExA(0, cls_name
, "Test", WS_TILEDWINDOW
, 0, 0, 640, 480, 0, 0, 0, 0);
2551 ok(hWnd
!= 0, "CreateWindowExA failed %u\n", GetLastError());
2552 handles
[0] = CreateSemaphoreA(NULL
, 1, 1, NULL
);
2553 ok(handles
[0] != 0, "CreateSemaphoreA failed %u\n", GetLastError());
2554 handles
[1] = CreateSemaphoreA(NULL
, 1, 1, NULL
);
2555 ok(handles
[1] != 0, "CreateSemaphoreA failed %u\n", GetLastError());
2557 /* test without flags */
2559 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2560 hr
= CoWaitForMultipleHandles(0, 50, 0, handles
, NULL
);
2561 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
2562 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2563 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2566 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2567 hr
= CoWaitForMultipleHandles(0, 50, 0, NULL
, &index
);
2568 ok(hr
== E_INVALIDARG
, "expected E_INVALIDARG, got 0x%08x\n", hr
);
2569 ok(index
== 0, "expected index 0, got %u\n", index
);
2570 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2571 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2574 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2575 hr
= CoWaitForMultipleHandles(0, 50, 0, handles
, &index
);
2576 ok(hr
== RPC_E_NO_SYNC
, "expected RPC_E_NO_SYNC, got 0x%08x\n", hr
);
2577 ok(index
== 0, "expected index 0, got %u\n", index
);
2578 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2579 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2582 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2583 hr
= CoWaitForMultipleHandles(0, 50, 1, handles
, &index
);
2584 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2585 ok(index
== 0, "expected index 0, got %u\n", index
);
2586 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2587 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2590 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2591 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2592 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2593 ok(index
== 1, "expected index 1, got %u\n", index
);
2594 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2595 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2598 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2599 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2600 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2601 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2602 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2603 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2605 /* test PostMessageA/SendMessageA from a different thread */
2608 thread
= CreateThread(NULL
, 0, post_message_thread
, hWnd
, 0, &tid
);
2609 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2610 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2611 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2612 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2613 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2614 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2615 index
= WaitForSingleObject(thread
, 200);
2616 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2617 CloseHandle(thread
);
2620 thread
= CreateThread(NULL
, 0, send_message_thread
, hWnd
, 0, &tid
);
2621 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2622 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2623 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2624 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2625 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2626 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2627 index
= WaitForSingleObject(thread
, 200);
2628 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2629 CloseHandle(thread
);
2631 ReleaseSemaphore(handles
[0], 1, NULL
);
2632 ReleaseSemaphore(handles
[1], 1, NULL
);
2634 /* test with COWAIT_WAITALL */
2637 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2638 hr
= CoWaitForMultipleHandles(COWAIT_WAITALL
, 50, 2, handles
, &index
);
2639 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2640 ok(index
== 0, "expected index 0, got %u\n", index
);
2641 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2642 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2645 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2646 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2647 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2648 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2649 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2650 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2652 ReleaseSemaphore(handles
[0], 1, NULL
);
2653 ReleaseSemaphore(handles
[1], 1, NULL
);
2655 /* test with COWAIT_ALERTABLE */
2658 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2659 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 1, handles
, &index
);
2660 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2661 ok(index
== 0, "expected index 0, got %u\n", index
);
2662 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2663 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2666 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2667 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 2, handles
, &index
);
2668 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2669 ok(index
== 1, "expected index 1, got %u\n", index
);
2670 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2671 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2674 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2675 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 2, handles
, &index
);
2676 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2677 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2678 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2679 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2682 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2683 success
= QueueUserAPC(apc_test_proc
, GetCurrentThread(), 0);
2684 ok(success
, "QueueUserAPC failed %u\n", GetLastError());
2685 hr
= CoWaitForMultipleHandles(COWAIT_ALERTABLE
, 50, 2, handles
, &index
);
2686 ok(hr
== S_OK
, "expected S_OK, got 0x%08x\n", hr
);
2687 ok(index
== WAIT_IO_COMPLETION
, "expected index WAIT_IO_COMPLETION, got %u\n", index
);
2688 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2689 ok(success
, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
2691 /* test with COWAIT_INPUTAVAILABLE (semaphores are still locked) */
2694 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2695 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_NOREMOVE
);
2696 ok(success
, "PeekMessageA returned FALSE\n");
2697 hr
= CoWaitForMultipleHandles(0, 50, 2, handles
, &index
);
2698 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2699 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2700 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2701 ok(!success
, "CoWaitForMultipleHandles didn't pump any messages\n");
2704 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2705 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_NOREMOVE
);
2706 ok(success
, "PeekMessageA returned FALSE\n");
2707 thread
= CreateThread(NULL
, 0, release_semaphore_thread
, handles
[1], 0, &tid
);
2708 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2709 hr
= CoWaitForMultipleHandles(COWAIT_INPUTAVAILABLE
, 50, 2, handles
, &index
);
2710 ok(hr
== RPC_S_CALLPENDING
|| broken(hr
== E_INVALIDARG
) || broken(hr
== S_OK
) /* Win 8 */,
2711 "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2712 if (hr
!= S_OK
) ReleaseSemaphore(handles
[1], 1, NULL
);
2713 ok(index
== 0 || broken(index
== 1) /* Win 8 */, "expected index 0, got %u\n", index
);
2714 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2715 ok(!success
|| broken(success
&& hr
== E_INVALIDARG
),
2716 "CoWaitForMultipleHandles didn't pump any messages\n");
2717 index
= WaitForSingleObject(thread
, 200);
2718 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2719 CloseHandle(thread
);
2721 /* test behaviour of WM_QUIT (semaphores are still locked) */
2723 PostMessageA(hWnd
, WM_QUIT
, 40, 0);
2724 memset(&msg
, 0, sizeof(msg
));
2725 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2726 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2727 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2728 ok(msg
.wParam
== 40, "expected msg.wParam = 40, got %lu\n", msg
.wParam
);
2729 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2730 ok(!success
, "PeekMessageA succeeded\n");
2733 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2734 PostMessageA(hWnd
, WM_QUIT
, 41, 0);
2735 thread
= CreateThread(NULL
, 0, post_message_thread
, hWnd
, 0, &tid
);
2736 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2737 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2738 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2739 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2740 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2742 ok(success
|| broken(!success
) /* Win 2000/XP/8 */, "PeekMessageA failed, error %u\n", GetLastError());
2743 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2744 ok(!success
, "PeekMessageA succeeded\n");
2745 memset(&msg
, 0, sizeof(msg
));
2746 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2748 ok(!success
|| broken(success
) /* Win 2000/XP/8 */, "PeekMessageA succeeded\n");
2751 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2752 ok(msg
.wParam
== 41, "expected msg.wParam = 41, got %lu\n", msg
.wParam
);
2754 index
= WaitForSingleObject(thread
, 200);
2755 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2756 CloseHandle(thread
);
2759 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2760 PostMessageA(hWnd
, WM_QUIT
, 42, 0);
2761 thread
= CreateThread(NULL
, 0, send_message_thread
, hWnd
, 0, &tid
);
2762 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2763 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2764 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2765 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2766 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2767 ok(!success
, "CoWaitForMultipleHandles didn't pump all WM_DDE_FIRST messages\n");
2768 memset(&msg
, 0, sizeof(msg
));
2769 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2770 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2771 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2772 ok(msg
.wParam
== 42, "expected msg.wParam = 42, got %lu\n", msg
.wParam
);
2773 index
= WaitForSingleObject(thread
, 200);
2774 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2775 CloseHandle(thread
);
2777 PostQuitMessage(43);
2778 memset(&msg
, 0, sizeof(msg
));
2779 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2780 ok(success
|| broken(!success
) /* Win 8 */, "PeekMessageA failed, error %u\n", GetLastError());
2782 win_skip("PostQuitMessage didn't queue a WM_QUIT message, skipping tests\n");
2785 ok(msg
.message
== WM_QUIT
, "expected msg.message = WM_QUIT, got %u\n", msg
.message
);
2786 ok(msg
.wParam
== 43, "expected msg.wParam = 43, got %lu\n", msg
.wParam
);
2787 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2788 ok(!success
, "PeekMessageA succeeded\n");
2791 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2792 PostQuitMessage(44);
2793 thread
= CreateThread(NULL
, 0, post_message_thread
, hWnd
, 0, &tid
);
2794 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2795 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2796 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2797 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2798 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2799 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2800 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2802 ok(!success
, "PeekMessageA succeeded\n");
2803 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2805 ok(!success
, "CoWaitForMultipleHandles didn't remove WM_QUIT messages\n");
2806 index
= WaitForSingleObject(thread
, 200);
2807 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2808 CloseHandle(thread
);
2811 PostMessageA(hWnd
, WM_DDE_FIRST
, 0, 0);
2812 PostQuitMessage(45);
2813 thread
= CreateThread(NULL
, 0, send_message_thread
, hWnd
, 0, &tid
);
2814 ok(thread
!= NULL
, "CreateThread failed, error %u\n", GetLastError());
2815 hr
= CoWaitForMultipleHandles(0, 100, 2, handles
, &index
);
2816 ok(hr
== RPC_S_CALLPENDING
, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr
);
2817 ok(index
== 0 || broken(index
== 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index
);
2818 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2819 ok(success
, "PeekMessageA failed, error %u\n", GetLastError());
2820 success
= PeekMessageA(&msg
, hWnd
, WM_DDE_FIRST
, WM_DDE_FIRST
, PM_REMOVE
);
2822 ok(!success
, "PeekMessageA succeeded\n");
2823 success
= PeekMessageA(&msg
, hWnd
, WM_QUIT
, WM_QUIT
, PM_REMOVE
);
2824 ok(!success
, "CoWaitForMultipleHandles didn't remove WM_QUIT messages\n");
2825 index
= WaitForSingleObject(thread
, 200);
2826 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2827 CloseHandle(thread
);
2830 /* test message pumping when CoWaitForMultipleHandles is called from non main apartment thread */
2831 thread
= CreateThread(NULL
, 0, test_CoWaitForMultipleHandles_thread
, handles
, 0, &tid
);
2832 index
= WaitForSingleObject(thread
, 500);
2833 ok(index
== WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
2834 CloseHandle(thread
);
2836 CloseHandle(handles
[0]);
2837 CloseHandle(handles
[1]);
2838 DestroyWindow(hWnd
);
2840 success
= UnregisterClassA(cls_name
, GetModuleHandleA(0));
2841 ok(success
, "UnregisterClass failed %u\n", GetLastError());
2846 static void test_CoGetMalloc(void)
2851 if (0) /* crashes on native */
2852 hr
= CoGetMalloc(0, NULL
);
2854 imalloc
= (void*)0xdeadbeef;
2855 hr
= CoGetMalloc(0, &imalloc
);
2856 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2857 ok(imalloc
== NULL
, "got %p\n", imalloc
);
2859 imalloc
= (void*)0xdeadbeef;
2860 hr
= CoGetMalloc(MEMCTX_SHARED
, &imalloc
);
2861 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2862 ok(imalloc
== NULL
, "got %p\n", imalloc
);
2864 imalloc
= (void*)0xdeadbeef;
2865 hr
= CoGetMalloc(MEMCTX_MACSYSTEM
, &imalloc
);
2866 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2867 ok(imalloc
== NULL
, "got %p\n", imalloc
);
2869 imalloc
= (void*)0xdeadbeef;
2870 hr
= CoGetMalloc(MEMCTX_UNKNOWN
, &imalloc
);
2871 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2872 ok(imalloc
== NULL
, "got %p\n", imalloc
);
2874 imalloc
= (void*)0xdeadbeef;
2875 hr
= CoGetMalloc(MEMCTX_SAME
, &imalloc
);
2876 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
2877 ok(imalloc
== NULL
, "got %p\n", imalloc
);
2880 hr
= CoGetMalloc(MEMCTX_TASK
, &imalloc
);
2881 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
2882 ok(imalloc
!= NULL
, "got %p\n", imalloc
);
2883 IMalloc_Release(imalloc
);
2886 static void test_CoGetApartmentType(void)
2888 APTTYPEQUALIFIER qualifier
;
2892 if (!pCoGetApartmentType
)
2894 win_skip("CoGetApartmentType not present\n");
2898 hr
= pCoGetApartmentType(NULL
, NULL
);
2899 ok(hr
== E_INVALIDARG
, "CoGetApartmentType succeeded, error: 0x%08x\n", hr
);
2902 hr
= pCoGetApartmentType(&type
, NULL
);
2903 ok(hr
== E_INVALIDARG
, "CoGetApartmentType succeeded, error: 0x%08x\n", hr
);
2904 ok(type
== 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", type
);
2906 qualifier
= 0xdeadbeef;
2907 hr
= pCoGetApartmentType(NULL
, &qualifier
);
2908 ok(hr
== E_INVALIDARG
, "CoGetApartmentType succeeded, error: 0x%08x\n", hr
);
2909 ok(qualifier
== 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", qualifier
);
2912 qualifier
= 0xdeadbeef;
2913 hr
= pCoGetApartmentType(&type
, &qualifier
);
2914 ok(hr
== CO_E_NOTINITIALIZED
, "CoGetApartmentType succeeded, error: 0x%08x\n", hr
);
2915 ok(type
== APTTYPE_CURRENT
, "Expected APTTYPE_CURRENT, got %u\n", type
);
2916 ok(qualifier
== APTTYPEQUALIFIER_NONE
, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier
);
2919 qualifier
= 0xdeadbeef;
2920 hr
= pCoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
2921 ok(hr
== S_OK
, "CoInitializeEx failed, error: 0x%08x\n", hr
);
2922 hr
= pCoGetApartmentType(&type
, &qualifier
);
2923 ok(hr
== S_OK
, "CoGetApartmentType failed, error: 0x%08x\n", hr
);
2924 ok(type
== APTTYPE_MAINSTA
, "Expected APTTYPE_MAINSTA, got %u\n", type
);
2925 ok(qualifier
== APTTYPEQUALIFIER_NONE
, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier
);
2929 qualifier
= 0xdeadbeef;
2930 hr
= pCoInitializeEx(NULL
, COINIT_MULTITHREADED
);
2931 ok(hr
== S_OK
, "CoInitializeEx failed, error: 0x%08x\n", hr
);
2932 hr
= pCoGetApartmentType(&type
, &qualifier
);
2933 ok(hr
== S_OK
, "CoGetApartmentType failed, error: 0x%08x\n", hr
);
2934 ok(type
== APTTYPE_MTA
, "Expected APTTYPE_MTA, got %u\n", type
);
2935 ok(qualifier
== APTTYPEQUALIFIER_NONE
, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier
);
2940 static HRESULT WINAPI
testspy_QI(IMallocSpy
*iface
, REFIID riid
, void **obj
)
2942 if (IsEqualIID(riid
, &IID_IMallocSpy
) || IsEqualIID(riid
, &IID_IUnknown
))
2945 IMallocSpy_AddRef(iface
);
2949 return E_NOINTERFACE
;
2952 static ULONG WINAPI
testspy_AddRef(IMallocSpy
*iface
)
2957 static ULONG WINAPI
testspy_Release(IMallocSpy
*iface
)
2962 static SIZE_T WINAPI
testspy_PreAlloc(IMallocSpy
*iface
, SIZE_T cb
)
2964 ok(0, "unexpected call\n");
2968 static void* WINAPI
testspy_PostAlloc(IMallocSpy
*iface
, void *ptr
)
2970 ok(0, "unexpected call\n");
2974 static void* WINAPI
testspy_PreFree(IMallocSpy
*iface
, void *ptr
, BOOL spyed
)
2976 ok(0, "unexpected call\n");
2980 static void WINAPI
testspy_PostFree(IMallocSpy
*iface
, BOOL spyed
)
2982 ok(0, "unexpected call\n");
2985 static SIZE_T WINAPI
testspy_PreRealloc(IMallocSpy
*iface
, void *ptr
, SIZE_T cb
, void **newptr
, BOOL spyed
)
2987 ok(0, "unexpected call\n");
2991 static void* WINAPI
testspy_PostRealloc(IMallocSpy
*iface
, void *ptr
, BOOL spyed
)
2993 ok(0, "unexpected call\n");
2997 static void* WINAPI
testspy_PreGetSize(IMallocSpy
*iface
, void *ptr
, BOOL spyed
)
2999 ok(0, "unexpected call\n");
3003 static SIZE_T WINAPI
testspy_PostGetSize(IMallocSpy
*iface
, SIZE_T actual
, BOOL spyed
)
3005 ok(0, "unexpected call\n");
3009 static void* WINAPI
testspy_PreDidAlloc(IMallocSpy
*iface
, void *ptr
, BOOL spyed
)
3011 ok(0, "unexpected call\n");
3015 static int WINAPI
testspy_PostDidAlloc(IMallocSpy
*iface
, void *ptr
, BOOL spyed
, int actual
)
3017 ok(0, "unexpected call\n");
3021 static void WINAPI
testspy_PreHeapMinimize(IMallocSpy
*iface
)
3023 ok(0, "unexpected call\n");
3026 static void WINAPI
testspy_PostHeapMinimize(IMallocSpy
*iface
)
3028 ok(0, "unexpected call\n");
3031 static const IMallocSpyVtbl testspyvtbl
=
3041 testspy_PostRealloc
,
3043 testspy_PostGetSize
,
3044 testspy_PreDidAlloc
,
3045 testspy_PostDidAlloc
,
3046 testspy_PreHeapMinimize
,
3047 testspy_PostHeapMinimize
3050 static IMallocSpy testspy
= { &testspyvtbl
};
3052 static void test_IMallocSpy(void)
3057 hr
= CoRegisterMallocSpy(NULL
);
3058 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3060 hr
= CoRevokeMallocSpy();
3061 ok(hr
== CO_E_OBJNOTREG
, "got 0x%08x\n", hr
);
3063 hr
= CoRegisterMallocSpy(&testspy
);
3064 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3066 hr
= CoRegisterMallocSpy(NULL
);
3067 ok(hr
== E_INVALIDARG
, "got 0x%08x\n", hr
);
3069 hr
= CoRegisterMallocSpy(&testspy
);
3070 ok(hr
== CO_E_OBJISREG
, "got 0x%08x\n", hr
);
3073 hr
= CoGetMalloc(MEMCTX_TASK
, &imalloc
);
3074 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3075 ok(imalloc
!= NULL
, "got %p\n", imalloc
);
3077 IMalloc_Free(imalloc
, NULL
);
3079 IMalloc_Release(imalloc
);
3081 hr
= CoRevokeMallocSpy();
3082 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
3084 hr
= CoRevokeMallocSpy();
3085 ok(hr
== CO_E_OBJNOTREG
, "got 0x%08x\n", hr
);
3088 static void init_funcs(void)
3090 HMODULE hOle32
= GetModuleHandleA("ole32");
3091 HMODULE hAdvapi32
= GetModuleHandleA("advapi32");
3092 HMODULE hkernel32
= GetModuleHandleA("kernel32");
3094 pCoGetObjectContext
= (void*)GetProcAddress(hOle32
, "CoGetObjectContext");
3095 pCoSwitchCallContext
= (void*)GetProcAddress(hOle32
, "CoSwitchCallContext");
3096 pCoGetTreatAsClass
= (void*)GetProcAddress(hOle32
,"CoGetTreatAsClass");
3097 pCoTreatAsClass
= (void*)GetProcAddress(hOle32
,"CoTreatAsClass");
3098 pCoGetContextToken
= (void*)GetProcAddress(hOle32
, "CoGetContextToken");
3099 pCoGetApartmentType
= (void*)GetProcAddress(hOle32
, "CoGetApartmentType");
3100 pRegDeleteKeyExA
= (void*)GetProcAddress(hAdvapi32
, "RegDeleteKeyExA");
3101 pRegOverridePredefKey
= (void*)GetProcAddress(hAdvapi32
, "RegOverridePredefKey");
3102 pCoInitializeEx
= (void*)GetProcAddress(hOle32
, "CoInitializeEx");
3104 pActivateActCtx
= (void*)GetProcAddress(hkernel32
, "ActivateActCtx");
3105 pCreateActCtxW
= (void*)GetProcAddress(hkernel32
, "CreateActCtxW");
3106 pDeactivateActCtx
= (void*)GetProcAddress(hkernel32
, "DeactivateActCtx");
3107 pIsWow64Process
= (void*)GetProcAddress(hkernel32
, "IsWow64Process");
3108 pReleaseActCtx
= (void*)GetProcAddress(hkernel32
, "ReleaseActCtx");
3115 if (!pCoInitializeEx
)
3117 trace("You need DCOM95 installed to run this test\n");
3121 if (!pCreateActCtxW
)
3122 win_skip("Activation contexts are not supported, some tests will be skipped.\n");
3124 test_ProgIDFromCLSID();
3125 test_CLSIDFromProgID();
3126 test_CLSIDFromString();
3127 test_IIDFromString();
3128 test_StringFromGUID2();
3129 test_CoCreateInstance();
3131 test_CoGetClassObject();
3132 test_CoCreateInstanceEx();
3133 test_CoRegisterMessageFilter();
3134 test_CoRegisterPSClsid();
3135 test_CoGetPSClsid();
3136 test_CoUnmarshalInterface();
3137 test_CoGetInterfaceAndReleaseStream();
3138 test_CoMarshalInterface();
3139 test_CoMarshalInterThreadInterfaceInStream();
3140 test_CoRegisterClassObject();
3141 test_registered_object_thread_affinity();
3142 test_CoFreeUnusedLibraries();
3143 test_CoGetObjectContext();
3144 test_CoGetCallContext();
3145 test_CoGetContextToken();
3146 test_TreatAsClass();
3147 test_CoInitializeEx();
3148 test_OleInitialize_InitCounting();
3149 test_OleRegGetMiscStatus();
3150 test_CoCreateGuid();
3151 test_CoWaitForMultipleHandles();
3153 test_OleRegGetUserType();
3154 test_CoGetApartmentType();