combase: Move CoCreateInstanceEx().

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-08-13 08:29:33 +01:00 committed by Alexandre Julliard
parent 32de022093
commit 81694b6292
4 changed files with 46 additions and 96 deletions

View File

@ -1306,3 +1306,47 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, IUnknown *out
*obj = multi_qi.pItf;
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);
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);
}

View File

@ -81,7 +81,7 @@
@ stdcall CoCreateFreeThreadedMarshaler(ptr ptr)
@ stdcall CoCreateGuid(ptr)
@ stdcall CoCreateInstance(ptr ptr long ptr ptr)
@ stdcall CoCreateInstanceEx(ptr ptr long ptr long ptr) ole32.CoCreateInstanceEx
@ stdcall CoCreateInstanceEx(ptr ptr long ptr long ptr)
@ stub CoCreateInstanceFromApp
@ stub CoCreateObjectInContext
@ stub CoDeactivateObject

View File

@ -2918,100 +2918,6 @@ HRESULT WINAPI CoResumeClassObjects(void)
return S_OK;
}
static void init_multi_qi(DWORD count, MULTI_QI *mqi, HRESULT hr)
{
ULONG i;
for (i = 0; i < count; i++)
{
mqi[i].pItf = NULL;
mqi[i].hr = hr;
}
}
static HRESULT return_multi_qi(IUnknown *unk, DWORD count, MULTI_QI *mqi, BOOL include_unk)
{
ULONG index = 0, fetched = 0;
if (include_unk)
{
mqi[0].hr = S_OK;
mqi[0].pItf = unk;
index = fetched = 1;
}
for (; index < count; index++)
{
mqi[index].hr = IUnknown_QueryInterface(unk, mqi[index].pIID, (void**)&mqi[index].pItf);
if (mqi[index].hr == S_OK)
fetched++;
}
if (!include_unk)
IUnknown_Release(unk);
if (fetched == 0)
return E_NOINTERFACE;
return fetched == count ? S_OK : CO_S_NOTALLINTERFACES;
}
/***********************************************************************
* CoCreateInstanceEx [OLE32.@]
*/
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstanceEx(
REFCLSID rclsid,
LPUNKNOWN pUnkOuter,
DWORD dwClsContext,
COSERVERINFO* pServerInfo,
ULONG cmq,
MULTI_QI* pResults)
{
IUnknown *unk = NULL;
IClassFactory *cf;
CLSID clsid;
HRESULT hres;
TRACE("(%s %p %x %p %u %p)\n", debugstr_guid(rclsid), pUnkOuter, dwClsContext, pServerInfo, cmq, pResults);
if (!cmq || !pResults)
return E_INVALIDARG;
if (pServerInfo)
FIXME("() non-NULL pServerInfo not supported!\n");
init_multi_qi(cmq, pResults, E_NOINTERFACE);
hres = CoGetTreatAsClass(rclsid, &clsid);
if(FAILED(hres))
clsid = *rclsid;
/*
* Get a class factory to construct the object we want.
*/
hres = CoGetClassObject(&clsid, dwClsContext, NULL, &IID_IClassFactory, (void**)&cf);
if (FAILED(hres))
return hres;
/*
* Create the object and don't forget to release the factory
*/
hres = IClassFactory_CreateInstance(cf, pUnkOuter, pResults[0].pIID, (void**)&unk);
IClassFactory_Release(cf);
if (FAILED(hres))
{
if (hres == CLASS_E_NOAGGREGATION && pUnkOuter)
FIXME("Class %s does not support aggregation\n", debugstr_guid(&clsid));
else
FIXME("no instance created for interface %s of class %s, hres is 0x%08x\n",
debugstr_guid(pResults[0].pIID),
debugstr_guid(&clsid),hres);
return hres;
}
return return_multi_qi(unk, cmq, pResults, TRUE);
}
/***********************************************************************
* CoLoadLibrary (OLE32.@)
*

View File

@ -13,7 +13,7 @@
@ stdcall CoCreateFreeThreadedMarshaler(ptr ptr) combase.CoCreateFreeThreadedMarshaler
@ stdcall CoCreateGuid(ptr) combase.CoCreateGuid
@ stdcall CoCreateInstance(ptr ptr long ptr ptr) combase.CoCreateInstance
@ stdcall CoCreateInstanceEx(ptr ptr long ptr long ptr)
@ stdcall CoCreateInstanceEx(ptr ptr long ptr long ptr) combase.CoCreateInstanceEx
@ stdcall CoDecrementMTAUsage(ptr)
@ stdcall CoDisableCallCancellation(ptr)
@ stdcall CoDisconnectObject(ptr long)