OuterCOMObj
XX
InnerCOMObj
IUnknown
m_pInnerUnk
InnerCOMObj implements interface YY. class COuterCOMObj : public XX{ IUnknown *m_pInnerUnk; /* This holds the non-delegating IUnknown for InnerCOMObj */ HRESULT hr = E_NOINTERFACE; HRESULT QueryInterface(REFIID riid, VOID **ppv) { /* See if the caller is asking for interface IX0 which is implemented in the outer object */ if (riid == IID_XX) { *ppv = (IX0 *) this; hr = S_OK; } /* See if the caller wants YY which is implemented in aggregated object IO1 */ else if (riid == IID_YY) { /* If so - call the non-delegating IUnknown in aggregated object InnerCOMObj*/ hr = m_pInnerUnk->QueryInterface(riid, ppv); } else return E_NOINTERFACE; if (FAILED(hr)) return hr; ((*IUnknown ) ppv)->AddRef(); return S_OK; } ... };