Revisiting COM Aggregation Rules with ADSI Extensions
The following is a brief review of COM aggregation and ADSI extension rules.
- The CreateInstance method returns a pointer to an IUnknown interface, as follows, that does not delegate any function calls to the aggregator.
The IUnknown::QueryInterface method returns pointers to the interfaces that 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.
Extension writers can choose any internal implementation they prefer as long as they obey standard COM aggregation rules. Be aware 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:
- Delegate functions for IDispatch back to the aggregator.
- Implement the IDispatch interface in IADsExtension.