Compartir a través de


CComPolyObject Class

This class implements IUnknown for an aggregated or nonaggregated object.

template< 
   class contained  
> 
class CComPolyObject : public IUnknown, public CComObjectRootEx 
   < contained::_ThreadModel::ThreadModelNoCS >

Parameters

Members

Public Constructors

Name

Description

CComPolyObject::CComPolyObject

The constructor.

CComPolyObject::~CComPolyObject

The destructor.

Public Methods

Name

Description

CComPolyObject::AddRef

Increments the object's reference count.

CComPolyObject::CreateInstance

(Static) Allows you to create a new CComPolyObject< contained > object without the overhead of CoCreateInstance.

CComPolyObject::FinalConstruct

Performs final initialization of m_contained.

CComPolyObject::FinalRelease

Performs final destruction of m_contained.

CComPolyObject::QueryInterface

Retrieves a pointer to the requested interface.

CComPolyObject::Release

Decrements the object's reference count.

Public Data Members

Name

Description

CComPolyObject::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.

Remarks

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 a 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 Project 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.

Inheritance Hierarchy

CComObjectRootBase

CComObjectRootEx

IUnknown

CComPolyObject

Requirements

Header: atlcom.h

See Also

Reference

CComObjectRootEx Class

DECLARE_POLY_AGGREGATABLE

Other Resources

ATL Class Overview