combase: Implement CoCreateInstanceFromApp().

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2020-09-09 12:44:28 +03:00 committed by Alexandre Julliard
parent c487f21b6b
commit 76b50a01a0
8 changed files with 217 additions and 65 deletions

View File

@ -8,7 +8,7 @@
@ stdcall CoCreateGuid(ptr) ole32.CoCreateGuid
@ stdcall CoCreateInstance(ptr ptr long ptr ptr) ole32.CoCreateInstance
@ stdcall CoCreateInstanceEx(ptr ptr long ptr long ptr) ole32.CoCreateInstanceEx
@ stub CoCreateInstanceFromApp
@ stdcall CoCreateInstanceFromApp(ptr ptr long ptr long ptr) ole32.CoCreateInstanceFromApp
@ stub CoDecodeProxy
@ stdcall CoDecrementMTAUsage(ptr) ole32.CoDecrementMTAUsage
@ stdcall CoDisableCallCancellation(ptr) ole32.CoDisableCallCancellation

View File

@ -8,7 +8,7 @@
@ stdcall CoCreateGuid(ptr) ole32.CoCreateGuid
@ stdcall CoCreateInstance(ptr ptr long ptr ptr) ole32.CoCreateInstance
@ stdcall CoCreateInstanceEx(ptr ptr long ptr long ptr) ole32.CoCreateInstanceEx
@ stub CoCreateInstanceFromApp
@ stdcall CoCreateInstanceFromApp(ptr ptr long ptr long ptr) ole32.CoCreateInstanceFromApp
@ stub CoDecodeProxy
@ stdcall CoDecrementMTAUsage(ptr) ole32.CoDecrementMTAUsage
@ stdcall CoDisableCallCancellation(ptr) ole32.CoDisableCallCancellation

View File

@ -1527,53 +1527,19 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, IUnknown *out
}
/***********************************************************************
* CoCreateInstanceEx (combase.@)
* CoCreateInstanceFromApp (combase.@)
*/
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstanceEx(REFCLSID rclsid, IUnknown *outer, DWORD cls_context,
COSERVERINFO *server_info, ULONG count, MULTI_QI *results)
HRESULT WINAPI CoCreateInstanceFromApp(REFCLSID rclsid, IUnknown *outer, DWORD cls_context,
void *server_info, ULONG count, MULTI_QI *results)
{
IClassFactory *factory;
IUnknown *unk = NULL;
CLSID clsid;
HRESULT hr;
TRACE("%s, %p, %#x, %p, %u, %p\n", debugstr_guid(rclsid), outer, cls_context, server_info,
count, results);
TRACE("%s, %p, %#x, %p, %u, %p\n", debugstr_guid(rclsid), outer, cls_context, server_info, count, results);
if (!count || !results)
return E_INVALIDARG;
if (server_info)
FIXME("Server info is not supported.\n");
init_multi_qi(count, results, E_NOINTERFACE);
hr = CoGetTreatAsClass(rclsid, &clsid);
if (FAILED(hr))
clsid = *rclsid;
hr = CoGetClassObject(&clsid, cls_context, NULL, &IID_IClassFactory, (void **)&factory);
if (FAILED(hr))
return hr;
hr = IClassFactory_CreateInstance(factory, outer, results[0].pIID, (void **)&unk);
IClassFactory_Release(factory);
if (FAILED(hr))
{
if (hr == CLASS_E_NOAGGREGATION && outer)
FIXME("Class %s does not support aggregation\n", debugstr_guid(&clsid));
else
FIXME("no instance created for interface %s of class %s, hr %#x.\n",
debugstr_guid(results[0].pIID), debugstr_guid(&clsid), hr);
return hr;
}
return return_multi_qi(unk, count, results, TRUE);
return CoCreateInstanceEx(rclsid, outer, cls_context | CLSCTX_APPCONTAINER, server_info,
count, results);
}
/***********************************************************************
* CoGetClassObject (combase.@)
*/
HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(REFCLSID rclsid, DWORD clscontext,
static HRESULT com_get_class_object(REFCLSID rclsid, DWORD clscontext,
COSERVERINFO *server_info, REFIID riid, void **obj)
{
struct class_reg_data clsreg = { 0 };
@ -1581,8 +1547,6 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(REFCLSID rclsid, DWORD clscont
IUnknown *registered_obj;
struct apartment *apt;
TRACE("%s, %s\n", debugstr_guid(rclsid), debugstr_guid(riid));
if (!obj)
return E_INVALIDARG;
@ -1601,7 +1565,7 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(REFCLSID rclsid, DWORD clscont
{
if (IsEqualCLSID(rclsid, &CLSID_InProcFreeMarshaler) ||
IsEqualCLSID(rclsid, &CLSID_GlobalOptions) ||
IsEqualCLSID(rclsid, &CLSID_ManualResetEvent) ||
(!(clscontext & CLSCTX_APPCONTAINER) && IsEqualCLSID(rclsid, &CLSID_ManualResetEvent)) ||
IsEqualCLSID(rclsid, &CLSID_StdGlobalInterfaceTable))
{
apartment_release(apt);
@ -1637,7 +1601,7 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(REFCLSID rclsid, DWORD clscont
* First, try and see if we can't match the class ID with one of the
* registered classes.
*/
if ((registered_obj = com_get_registered_class_object(apt, rclsid, clscontext)))
if (!(clscontext & CLSCTX_APPCONTAINER) && (registered_obj = com_get_registered_class_object(apt, rclsid, clscontext)))
{
hr = IUnknown_QueryInterface(registered_obj, riid, obj);
IUnknown_Release(registered_obj);
@ -1737,6 +1701,60 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(REFCLSID rclsid, DWORD clscont
return hr;
}
/***********************************************************************
* CoCreateInstanceEx (combase.@)
*/
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstanceEx(REFCLSID rclsid, IUnknown *outer, DWORD cls_context,
COSERVERINFO *server_info, ULONG count, MULTI_QI *results)
{
IClassFactory *factory;
IUnknown *unk = NULL;
CLSID clsid;
HRESULT hr;
TRACE("%s, %p, %#x, %p, %u, %p\n", debugstr_guid(rclsid), outer, cls_context, server_info, count, results);
if (!count || !results)
return E_INVALIDARG;
if (server_info)
FIXME("Server info is not supported.\n");
init_multi_qi(count, results, E_NOINTERFACE);
clsid = *rclsid;
if (!(cls_context & CLSCTX_APPCONTAINER))
CoGetTreatAsClass(rclsid, &clsid);
if (FAILED(hr = com_get_class_object(&clsid, cls_context, NULL, &IID_IClassFactory, (void **)&factory)))
return hr;
hr = IClassFactory_CreateInstance(factory, outer, results[0].pIID, (void **)&unk);
IClassFactory_Release(factory);
if (FAILED(hr))
{
if (hr == CLASS_E_NOAGGREGATION && outer)
FIXME("Class %s does not support aggregation\n", debugstr_guid(&clsid));
else
FIXME("no instance created for interface %s of class %s, hr %#x.\n",
debugstr_guid(results[0].pIID), debugstr_guid(&clsid), hr);
return hr;
}
return return_multi_qi(unk, count, results, TRUE);
}
/***********************************************************************
* CoGetClassObject (combase.@)
*/
HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(REFCLSID rclsid, DWORD clscontext,
COSERVERINFO *server_info, REFIID riid, void **obj)
{
TRACE("%s, %#x, %s\n", debugstr_guid(rclsid), clscontext, debugstr_guid(riid));
return com_get_class_object(rclsid, clscontext, server_info, riid, obj);
}
/***********************************************************************
* CoFreeUnusedLibraries (combase.@)
*/

View File

@ -82,7 +82,7 @@
@ stdcall CoCreateGuid(ptr)
@ stdcall CoCreateInstance(ptr ptr long ptr ptr)
@ stdcall CoCreateInstanceEx(ptr ptr long ptr long ptr)
@ stub CoCreateInstanceFromApp
@ stdcall CoCreateInstanceFromApp(ptr ptr long ptr long ptr)
@ stub CoCreateObjectInContext
@ stub CoDeactivateObject
@ stub CoDecodeProxy

View File

@ -14,6 +14,7 @@
@ stdcall CoCreateGuid(ptr) combase.CoCreateGuid
@ stdcall CoCreateInstance(ptr ptr long ptr ptr) combase.CoCreateInstance
@ stdcall CoCreateInstanceEx(ptr ptr long ptr long ptr) combase.CoCreateInstanceEx
@ stdcall CoCreateInstanceFromApp(ptr ptr long ptr long ptr) combase.CoCreateInstanceFromApp
@ stdcall CoDecrementMTAUsage(ptr) combase.CoDecrementMTAUsage
@ stdcall CoDisableCallCancellation(ptr) combase.CoDisableCallCancellation
@ stdcall CoDisconnectObject(ptr long) combase.CoDisconnectObject

View File

@ -80,6 +80,8 @@ static HRESULT (WINAPI * pCoIncrementMTAUsage)(CO_MTA_USAGE_COOKIE *cookie);
static HRESULT (WINAPI * pCoDecrementMTAUsage)(CO_MTA_USAGE_COOKIE cookie);
static LONG (WINAPI * pRegDeleteKeyExA)(HKEY, LPCSTR, REGSAM, DWORD);
static LONG (WINAPI * pRegOverridePredefKey)(HKEY key, HKEY override);
static HRESULT (WINAPI * pCoCreateInstanceFromApp)(REFCLSID clsid, IUnknown *outer, DWORD clscontext,
void *reserved, DWORD count, MULTI_QI *results);
static BOOL (WINAPI *pIsWow64Process)(HANDLE, LPBOOL);
@ -2244,6 +2246,23 @@ static void test_TreatAsClass(void)
pIP = NULL;
}
if (pCoCreateInstanceFromApp)
{
MULTI_QI mqi = { 0 };
mqi.pIID = &IID_IInternetProtocol;
hr = pCoCreateInstanceFromApp(&deadbeef, NULL, CLSCTX_INPROC_SERVER, NULL, 1, &mqi);
ok(hr == REGDB_E_CLASSNOTREG, "Unexpected hr %#x.\n", hr);
hr = CoCreateInstance(&deadbeef, NULL, CLSCTX_INPROC_SERVER | CLSCTX_APPCONTAINER, &IID_IInternetProtocol,
(void **)&pIP);
ok(hr == REGDB_E_CLASSNOTREG, "Unexpected hr %#x.\n", hr);
hr = CoCreateInstance(&deadbeef, NULL, CLSCTX_INPROC_SERVER, &IID_IInternetProtocol, (void **)&pIP);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
IUnknown_Release(pIP);
}
hr = pCoTreatAsClass(&deadbeef, &CLSID_NULL);
ok(hr == S_OK, "CoTreatAsClass failed: %08x\n", hr);
@ -3943,6 +3962,7 @@ static void init_funcs(void)
pCoGetApartmentType = (void*)GetProcAddress(hOle32, "CoGetApartmentType");
pCoIncrementMTAUsage = (void*)GetProcAddress(hOle32, "CoIncrementMTAUsage");
pCoDecrementMTAUsage = (void*)GetProcAddress(hOle32, "CoDecrementMTAUsage");
pCoCreateInstanceFromApp = (void*)GetProcAddress(hOle32, "CoCreateInstanceFromApp");
pRegDeleteKeyExA = (void*)GetProcAddress(hAdvapi32, "RegDeleteKeyExA");
pRegOverridePredefKey = (void*)GetProcAddress(hAdvapi32, "RegOverridePredefKey");
@ -4075,6 +4095,107 @@ static void test_mta_usage(void)
test_apt_type(APTTYPE_CURRENT, APTTYPEQUALIFIER_NONE);
}
static void test_CoCreateInstanceFromApp(void)
{
static const CLSID *supported_classes[] =
{
&CLSID_InProcFreeMarshaler,
&CLSID_GlobalOptions,
&CLSID_StdGlobalInterfaceTable,
};
static const CLSID *unsupported_classes[] =
{
&CLSID_ManualResetEvent,
};
unsigned int i;
IUnknown *unk;
DWORD cookie;
MULTI_QI mqi;
HRESULT hr;
HANDLE handle;
ULONG_PTR actctx_cookie;
if (!pCoCreateInstanceFromApp)
{
win_skip("CoCreateInstanceFromApp() is not available.\n");
return;
}
CoInitialize(NULL);
for (i = 0; i < ARRAY_SIZE(supported_classes); ++i)
{
memset(&mqi, 0, sizeof(mqi));
mqi.pIID = &IID_IUnknown;
hr = pCoCreateInstanceFromApp(supported_classes[i], NULL, CLSCTX_INPROC_SERVER, NULL, 1, &mqi);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
IUnknown_Release(mqi.pItf);
hr = CoCreateInstance(supported_classes[i], NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&unk);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
IUnknown_Release(unk);
}
for (i = 0; i < ARRAY_SIZE(unsupported_classes); ++i)
{
memset(&mqi, 0, sizeof(mqi));
mqi.pIID = &IID_IUnknown;
hr = pCoCreateInstanceFromApp(unsupported_classes[i], NULL, CLSCTX_INPROC_SERVER, NULL, 1, &mqi);
ok(hr == REGDB_E_CLASSNOTREG, "Unexpected hr %#x.\n", hr);
hr = CoCreateInstance(unsupported_classes[i], NULL, CLSCTX_INPROC_SERVER | CLSCTX_APPCONTAINER,
&IID_IUnknown, (void **)&unk);
ok(hr == REGDB_E_CLASSNOTREG, "Unexpected hr %#x.\n", hr);
hr = CoCreateInstance(unsupported_classes[i], NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&unk);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
IUnknown_Release(unk);
}
/* Locally registered classes are filtered out. */
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory, CLSCTX_INPROC_SERVER,
REGCLS_MULTIPLEUSE, &cookie);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
hr = CoGetClassObject(&CLSID_WineOOPTest, CLSCTX_INPROC_SERVER, NULL, &IID_IClassFactory, (void **)&unk);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
hr = CoGetClassObject(&CLSID_WineOOPTest, CLSCTX_INPROC_SERVER | CLSCTX_APPCONTAINER, NULL,
&IID_IClassFactory, (void **)&unk);
todo_wine
ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
hr = CoCreateInstance(&CLSID_WineOOPTest, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&unk);
ok(hr == E_NOINTERFACE, "Unexpected hr %#x.\n", hr);
hr = CoCreateInstance(&CLSID_WineOOPTest, NULL, CLSCTX_INPROC_SERVER | CLSCTX_APPCONTAINER,
&IID_IUnknown, (void **)&unk);
ok(hr == REGDB_E_CLASSNOTREG, "Unexpected hr %#x.\n", hr);
memset(&mqi, 0, sizeof(mqi));
mqi.pIID = &IID_IUnknown;
hr = pCoCreateInstanceFromApp(&CLSID_WineOOPTest, NULL, CLSCTX_INPROC_SERVER, NULL, 1, &mqi);
ok(hr == REGDB_E_CLASSNOTREG, "Unexpected hr %#x.\n", hr);
hr = CoRevokeClassObject(cookie);
ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
/* Activation context */
if ((handle = activate_context(actctx_manifest, &actctx_cookie)))
{
hr = CoCreateInstance(&IID_Testiface7, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&unk);
ok(hr == 0x80001235, "Unexpected hr %#x.\n", hr);
hr = CoCreateInstance(&IID_Testiface7, NULL, CLSCTX_INPROC_SERVER | CLSCTX_APPCONTAINER,
&IID_IUnknown, (void **)&unk);
ok(hr == 0x80001235, "Unexpected hr %#x.\n", hr);
deactivate_context(handle, actctx_cookie);
}
CoUninitialize();
}
START_TEST(compobj)
{
init_funcs();
@ -4124,6 +4245,7 @@ START_TEST(compobj)
test_implicit_mta();
test_CoGetCurrentProcess();
test_mta_usage();
test_CoCreateInstanceFromApp();
DeleteFileA( testlib );
}

View File

@ -319,6 +319,8 @@ HRESULT WINAPI CoCreateInstanceEx(REFCLSID rclsid,
COSERVERINFO* pServerInfo,
ULONG cmq,
MULTI_QI* pResults);
HRESULT WINAPI CoCreateInstanceFromApp(REFCLSID clsid, IUnknown *outer, DWORD clscontext, void *reserved,
DWORD count, MULTI_QI *results);
HRESULT WINAPI CoGetInstanceFromFile(COSERVERINFO* pServerInfo, CLSID* pClsid, IUnknown* punkOuter, DWORD dwClsCtx, DWORD grfMode, OLECHAR* pwszName, DWORD dwCount, MULTI_QI* pResults);
HRESULT WINAPI CoGetInstanceFromIStorage(COSERVERINFO* pServerInfo, CLSID* pClsid, IUnknown* punkOuter, DWORD dwClsCtx, IStorage* pstg, DWORD dwCount, MULTI_QI* pResults);

View File

@ -336,22 +336,31 @@ cpp_quote("#define ROTFLAGS_ALLOWANYCLIENT 0x2")
cpp_quote("#endif")
typedef enum tagCLSCTX {
CLSCTX_INPROC_SERVER = 0x1,
CLSCTX_INPROC_HANDLER = 0x2,
CLSCTX_LOCAL_SERVER = 0x4,
CLSCTX_INPROC_SERVER16 = 0x8,
CLSCTX_REMOTE_SERVER = 0x10,
CLSCTX_INPROC_HANDLER16 = 0x20,
CLSCTX_INPROC_SERVERX86 = 0x40,
CLSCTX_INPROC_HANDLERX86 = 0x80,
CLSCTX_ESERVER_HANDLER = 0x100,
CLSCTX_NO_CODE_DOWNLOAD = 0x400,
CLSCTX_NO_CUSTOM_MARSHAL = 0x1000,
CLSCTX_ENABLE_CODE_DOWNLOAD = 0x2000,
CLSCTX_NO_FAILURE_LOG = 0x4000,
CLSCTX_DISABLE_AAA = 0x8000,
CLSCTX_ENABLE_AAA = 0x10000,
CLSCTX_FROM_DEFAULT_CONTEXT = 0x20000
CLSCTX_INPROC_SERVER = 0x00000001,
CLSCTX_INPROC_HANDLER = 0x00000002,
CLSCTX_LOCAL_SERVER = 0x00000004,
CLSCTX_INPROC_SERVER16 = 0x00000008,
CLSCTX_REMOTE_SERVER = 0x00000010,
CLSCTX_INPROC_HANDLER16 = 0x00000020,
CLSCTX_INPROC_SERVERX86 = 0x00000040,
CLSCTX_INPROC_HANDLERX86 = 0x00000080,
CLSCTX_ESERVER_HANDLER = 0x00000100,
CLSCTX_NO_CODE_DOWNLOAD = 0x00000400,
CLSCTX_NO_CUSTOM_MARSHAL = 0x00001000,
CLSCTX_ENABLE_CODE_DOWNLOAD = 0x00002000,
CLSCTX_NO_FAILURE_LOG = 0x00004000,
CLSCTX_DISABLE_AAA = 0x00008000,
CLSCTX_ENABLE_AAA = 0x00010000,
CLSCTX_FROM_DEFAULT_CONTEXT = 0x00020000,
CLSCTX_ACTIVATE_X86_SERVER = 0x00040000,
CLSCTX_ACTIVATE_32_BIT_SERVER = CLSCTX_ACTIVATE_X86_SERVER,
CLSCTX_ACTIVATE_64_BIT_SERVER = 0x00080000,
CLSCTX_ENABLE_CLOAKING = 0x00100000,
CLSCTX_APPCONTAINER = 0x00400000,
CLSCTX_ACTIVATE_AAA_AS_IU = 0x00800000,
CLSCTX_RESERVED6 = 0x01000000,
CLSCTX_ACTIVATE_ARM32_SERVER = 0x02000000,
CLSCTX_PS_DLL = 0x80000000,
} CLSCTX;
cpp_quote("#define CLSCTX_INPROC (CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER)")