COM聚合

Scroll Down

自动聚合

BEGIN_COM_MAP(CBase)
	COM_INTERFACE_ENTRY(IBase)
	COM_INTERFACE_ENTRY_AUTOAGGREGATE(IID_IDrive,m_spunkTest,CLSID_Drive)
END_COM_MAP()

	DECLARE_GET_CONTROLLING_UNKNOWN()

	void FinalRelease()
	{
		m_spunkTest.Release();
	}

public:

	CComPtr<IUnknown> m_spunkTest;

手动聚合

BEGIN_COM_MAP(CBase)
	COM_INTERFACE_ENTRY(IBase)
	COM_INTERFACE_ENTRY_AGGREGATE(IID_IDrive, m_spunkDrive)
END_COM_MAP()

	DECLARE_GET_CONTROLLING_UNKNOWN()
	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		HRESULT hr;
		hr = CoCreateInstance(CLSID_Drive, GetControllingUnknown(), CLSCTX_INPROC_SERVER, IID_IUnknown, (void**)&m_spunkDrive);
		return hr;
	}
	void FinalRelease()
	{
		m_spunkDrive.Release();
	}
public:
	CComPtr<IUnknown> m_spunkDrive;

以上两种均为计划聚合,下面的为盲目聚合
COM_INTERFACE_ENTRY_AGGREGATE_BLIND
COM_INTERFACE_ENTRY_AUTOAGGREGATE_BLIND