I've been learning about aggregating COM objects.
I dont understand why we 'need' 2 IUnknowns (ie the delegating IUnknown and the Non-delegating IUnknown). Surely the same effect can be achieved with just the 1 usual IUnknown?
Eg,
The outer component implements interface IX and aggregates interface IY, which is implemented in the inner component. the inner component only implements IY. so, when the client queries the outer component for IY, the outer component then queries the inner conponent for IY and returns this to the client. if the client then queries IY for IX, this should succeed because although the inner component does not implement IX, it forwards the query onto the outer component.
So surely this can be achieved with the following code:
Inner::QueryInterface(REFIID iid, (void**)piid)
{
if(iid == IID_IY)
{
piid = static_cast < IY*>(this);
}
else
{
outerUnknown->QueryInterface(iid, piid);
}
}
so if the client then queries IY for IX, or IUnknown, it will get the outer components IX or IUnknown, which is what we want.
unless im missing something glaringly obvious! which i suspect i am.