template< class contained >
class CComPolyObject : public IUnknown, public CComObjectRootEx< contained::_ThreadModel::ThreadModelNoCS >
Parameters
contained Your class, derived from CComObjectRoot or CComObjectRootEx, as well as from any other interfaces you want to support on the object.
CComPolyObject implements IUnknown for an aggregated or nonaggregated object.
When an instance of CComPolyObject is created, the value of the outer unknown is checked. If it is NULL, IUnknown is implemented for an nonaggregated object. If the outer unknown is not NULL, IUnknown is implemented for an aggregated object.
The advantage of using CComPolyObject is that you avoid having both CComAggObject and CComObject in your module to handle the aggregated and nonaggregated cases. A single CComPolyObject object handles both cases. This means only one copy of the vtable and one copy of the functions exist in your module. If your vtable is large, this can substantially decrease your module size. However, if your vtable is small, using CComPolyObject can result in a slightly larger module size because it is not optimized for an aggregated or nonaggregated object, as are CComAggObject and CComObject.
If the DECLARE_POLY_AGGREGATABLE macro is specified in your object's class definition, CComPolyObject will be used to create your object. DECLARE_POLY_AGGREGATABLE will automatically be declared if you use the ATL Object Wizard to create a full control or Internet Explorer control.
If aggregated, the CComPolyObject object has its own IUnknown, separate from the outer object's IUnknown, and maintains its own reference count. CComPolyObject uses CComContainedObject to delegate to the outer unknown.
For more information about aggregation, see the article Fundamentals of ATL COM Objects.
#include <atlcom.h>
See Also CComObjectRootEx, DECLARE_POLY_AGGREGATABLE
Class Methods | |
CComPolyObject | Constructor. |
FinalConstruct | Performs final initialization of m_contained. |
FinalRelease | Performs final destruction of m_contained. |
IUnknown Methods | |
AddRef | Increments the reference count on the object. |
QueryInterface | Retrieves a pointer to the requested interface. |
Release | Decrements the reference count on the object. |
Data Members | |
m_contained | Delegates IUnknown calls to the outer unknown if the object is aggregated or to the IUnknown of the object if the object is not aggregated. |
ULONG AddRef( );
Return Value
A value that may be useful for diagnostics or testing.
Remarks
Increments the reference count on the object.
CComPolyObject Overview | Class Members
See Also CComPolyObject::Release
CComPolyObject( void* pv );
Parameters
pv [in] A pointer to the outer unknown if the object is to be aggregated, or NULL if the object if the object is not aggregated.
Remarks
The constructor. Initializes the CComContainedObject data member, m_contained, and increments the module lock count.
The destructor decrements the module lock count.
CComPolyObject Overview | Class Members
See Also CComPolyObject::FinalConstruct, CComPolyObject::FinalRelease
HRESULT FinalConstruct( );
Return Value
A standard HRESULT value.
Remarks
Called during the final stages of object construction, this method performs any final initialization on the m_contained data member.
CComPolyObject Overview | Class Members
See Also CComObjectRootEx::FinalConstruct, CComPolyObject::FinalRelease
void FinalRelease( );
Remarks
Called during object destruction, this method frees the m_contained data member.
CComPolyObject Overview | Class Members
See Also CComObjectRootEx::FinalRelease, CComPolyObject::FinalConstruct
HRESULT QueryInterface( REFIID iid, void** ppvObject );
Return Value
A standard HRESULT value.
Parameters
iid [in] The identifier of the interface being requested.
ppvObject [out] A pointer to the interface pointer identified by iid. If the object does not support this interface, ppvObject is set to NULL.
Remarks
Retrieves a pointer to the requested interface.
For an aggregated object, if the requested interface is IUnknown, QueryInterface returns a pointer to the aggregated object's own IUnknown and increments the reference count. Otherwise, this method queries for the interface through the CComContainedObject data member, m_contained.
CComPolyObject Overview | Class Members
ULONG Release( );
Return Value
In debug builds, Release returns a value that may be useful for diagnostics or testing. In nondebug builds, Release always returns 0.
Remarks
Decrements the reference count on the object.
CComPolyObject Overview | Class Members
See Also CComPolyObject::AddRef
CComContainedObject< contained > m_contained;
Parameters
contained [in] Your class, derived from CComObjectRoot and CComObjectRootEx, as well as from any other interfaces you want to support on the object.
Remarks
A CComContainedObject object derived from your class. IUnknown calls through m_contained are delegated to the outer unknown if the object is aggregated, or to the IUnknown of this object if the object is not aggregated.