You are creating a COM component. Other components may attempt to include this component by using aggregation. Therefore, the component that you are creating must support aggregation. Which action or actions must you design into the component? (Choose all that apply)
Multi Selection
A Implement external and internal versions of the IUnknown interface. B Cache a pointer to the enclosing COM component’s IUnknown interface. C Call the AddRef method on the enclosing COM component at activation. D Call the Release method on the enclosing COM component when its reference count falls to zero.
E Forward calls to the QueryInterface method to the enclosing COM component. F Return the value CLASS_E_NOAGGREGATION from the call the QueryInterface.
Multi Selection
A Implement external and internal versions of the IUnknown interface. B Cache a pointer to the enclosing COM component’s IUnknown interface. C Call the AddRef method on the enclosing COM component at activation. D Call the Release method on the enclosing COM component when its reference count falls to zero.
E Forward calls to the QueryInterface method to the enclosing COM component. F Return the value CLASS_E_NOAGGREGATION from the call the QueryInterface.
要做一个可聚合组件,只需要做两件事,第一是实现两套IUnknown接口(A),另外再用一个成员变量纪录UnknownOuter就可以了。
enclosed COM component:内部的
可被聚合的对象A中external IUnknown interface的定义如下:
HRESULT CA::QueryInterface(....)
{
if (m_pUnknownOut != NULL)
//Answer B and E is here!!!
return m_pUnknownOut->QueryInterface(...);
else
return NodelegatingQueryInterface(..);//internal IUnknown
}