Revisiting COM Aggregation Rules with ADSI Extensions
The following is a quick review of COM aggregation rules along with ADSI extension rules.
- The CreateInstance method returns a pointer to an IUnknown interface which does not delegate any function calls to the aggregator.
- The IUnknown::QueryInterface method returns pointers to the interfaces it supports, and errors for interfaces it does not support.
- The IUnknown::AddRef method increments the reference count on the aggregated extension object itself.
- The IUnkown::Release method decrements the reference count on the aggregated extension object itself and destroys itself when the reference count is 0.
- The extension object should store the IUnknown pointer of the aggregator (such as m_pOuterUnknown) during the implementation of the CreateInstance method.
- All interfaces that the extension object supports, including IADsExtension, should inherit from IUnknown, which delegates all function calls back to the aggregator.
IUnknown::QueryInterface calls m_pOuterUnknown->QueryInterface
IUnknown::AddRef calls m_pOuterUnknown->AddRef
IUnknown::Release calls m_pOuterUnknown->Release
Extension writers can choose any internal implementation they prefer as long as they obey standard COM aggregation rules. Please note that an extension object does not have to work as a standalone object. Extensions are designed to work as aggregates. However, an extension can be written to work as both a standalone object and as an aggregate.
In addition to standard COM aggregation support, an extension object may support IADsExtension for more advanced features. If late binding is supported, the extension should do the following:
- Delegate functions for IDispatch back to the aggregator.
- Implement the IDispatch functionality in IADsExtension.