atl: Properly fail on an aggregation attempt.
This commit is contained in:
parent
e070173ac6
commit
efd0eead07
@ -698,21 +698,22 @@ static const IRegistrarVtbl RegistrarVtbl = {
|
|||||||
Registrar_ResourceUnregister,
|
Registrar_ResourceUnregister,
|
||||||
};
|
};
|
||||||
|
|
||||||
static HRESULT Registrar_create(const IUnknown *pUnkOuter, REFIID riid, void **ppvObject)
|
/* Exported only by newer ATL versions */
|
||||||
|
static HRESULT AtlCreateRegistrar(IRegistrar **ret)
|
||||||
{
|
{
|
||||||
Registrar *ret;
|
Registrar *registrar;
|
||||||
|
|
||||||
if(!IsEqualGUID(&IID_IUnknown, riid) && !IsEqualGUID(&IID_IRegistrar, riid))
|
registrar = HeapAlloc(GetProcessHeap(), 0, sizeof(*registrar));
|
||||||
return E_NOINTERFACE;
|
if(!registrar)
|
||||||
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
ret = HeapAlloc(GetProcessHeap(), 0, sizeof(Registrar));
|
registrar->IRegistrar_iface.lpVtbl = &RegistrarVtbl;
|
||||||
ret->IRegistrar_iface.lpVtbl = &RegistrarVtbl;
|
registrar->ref = 1;
|
||||||
ret->ref = 1;
|
registrar->rep = NULL;
|
||||||
ret->rep = NULL;
|
|
||||||
*ppvObject = ret;
|
|
||||||
|
|
||||||
InterlockedIncrement(&dll_count);
|
InterlockedIncrement(&dll_count);
|
||||||
|
|
||||||
|
*ret = ®istrar->IRegistrar_iface;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -746,10 +747,25 @@ static ULONG WINAPI RegistrarCF_Release(IClassFactory *iface)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT WINAPI RegistrarCF_CreateInstance(IClassFactory *iface, LPUNKNOWN pUnkOuter,
|
static HRESULT WINAPI RegistrarCF_CreateInstance(IClassFactory *iface, LPUNKNOWN pUnkOuter,
|
||||||
REFIID riid, void **ppvObject)
|
REFIID riid, void **ppv)
|
||||||
{
|
{
|
||||||
TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppvObject);
|
IRegistrar *registrar;
|
||||||
return Registrar_create(pUnkOuter, riid, ppvObject);
|
HRESULT hres;
|
||||||
|
|
||||||
|
TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
|
||||||
|
|
||||||
|
if(pUnkOuter) {
|
||||||
|
*ppv = NULL;
|
||||||
|
return CLASS_E_NOAGGREGATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
hres = AtlCreateRegistrar(®istrar);
|
||||||
|
if(FAILED(hres))
|
||||||
|
return hres;
|
||||||
|
|
||||||
|
hres = IRegistrar_QueryInterface(registrar, riid, ppv);
|
||||||
|
IRegistrar_Release(registrar);
|
||||||
|
return hres;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT WINAPI RegistrarCF_LockServer(IClassFactory *iface, BOOL lock)
|
static HRESULT WINAPI RegistrarCF_LockServer(IClassFactory *iface, BOOL lock)
|
||||||
@ -801,10 +817,13 @@ static HRESULT do_register_dll_server(IRegistrar *pRegistrar, LPCOLESTR wszDll,
|
|||||||
static const WCHAR wszModule[] = {'M','O','D','U','L','E',0};
|
static const WCHAR wszModule[] = {'M','O','D','U','L','E',0};
|
||||||
static const WCHAR wszRegistry[] = {'R','E','G','I','S','T','R','Y',0};
|
static const WCHAR wszRegistry[] = {'R','E','G','I','S','T','R','Y',0};
|
||||||
|
|
||||||
if (pRegistrar)
|
if(pRegistrar) {
|
||||||
registrar = pRegistrar;
|
registrar = pRegistrar;
|
||||||
else
|
}else {
|
||||||
Registrar_create(NULL, &IID_IRegistrar, (void**)®istrar);
|
hres = AtlCreateRegistrar(®istrar);
|
||||||
|
if(FAILED(hres))
|
||||||
|
return hres;
|
||||||
|
}
|
||||||
|
|
||||||
IRegistrar_AddReplacement(registrar, wszModule, wszDll);
|
IRegistrar_AddReplacement(registrar, wszModule, wszDll);
|
||||||
|
|
||||||
|
@ -135,11 +135,23 @@ static void test_registrar(void)
|
|||||||
IRegistrar_Release(registrar);
|
IRegistrar_Release(registrar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_aggregation(void)
|
||||||
|
{
|
||||||
|
IUnknown *unk = (IUnknown*)0xdeadbeef;
|
||||||
|
HRESULT hres;
|
||||||
|
|
||||||
|
hres = CoCreateInstance(&CLSID_Registrar, (IUnknown*)0xdeadbeef, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
|
||||||
|
&IID_IUnknown, (void**)&unk);
|
||||||
|
ok(hres == CLASS_E_NOAGGREGATION, "CoCreateInstance failed: %08x, expected CLASS_E_NOAGGREGATION\n", hres);
|
||||||
|
ok(!unk, "unk = %p\n", unk);
|
||||||
|
}
|
||||||
|
|
||||||
START_TEST(registrar)
|
START_TEST(registrar)
|
||||||
{
|
{
|
||||||
CoInitialize(NULL);
|
CoInitialize(NULL);
|
||||||
|
|
||||||
test_registrar();
|
test_registrar();
|
||||||
|
test_aggregation();
|
||||||
|
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user