共用方式為


CComContainedObject Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CComContainedObject Class.

This class implements IUnknown by delegating to the owner object's IUnknown.

Important

This class and its members cannot be used in applications that execute in the Windows Runtime.

Syntax

template<class Base>  
class CComContainedObject : public Base

Parameters

Base
Your class, derived from CComObjectRoot or CComObjectRootEx.

Members

Public Constructors

Name Description
CComContainedObject::CComContainedObject The constructor. Initializes the member pointer to the owner object's IUnknown.
CComContainedObject::~CComContainedObject The destructor.

Public Methods

Name Description
CComContainedObject::AddRef Increments the reference count on the owner object.
CComContainedObject::GetControllingUnknown Retrieves the owner object's IUnknown.
CComContainedObject::QueryInterface Retrieves a pointer to the interface requested on the owner object.
CComContainedObject::Release Decrements the reference count on the owner object.

Remarks

ATL uses CComContainedObject in classes CComAggObject, CComPolyObject, and CComCachedTearOffObject. CComContainedObject implements IUnknown by delegating to the owner object's IUnknown. (The owner is either the outer object of an aggregation, or the object for which a tear-off interface is being created.) CComContainedObject calls CComObjectRootEx's OuterQueryInterface, OuterAddRef, and OuterRelease, all inherited through Base.

Inheritance Hierarchy

Base

CComContainedObject

Requirements

Header: atlcom.h

CComContainedObject::AddRef

Increments the reference count on the owner object.

STDMETHOD_(ULONG, AddRef)();

Return Value

A value that may be useful for diagnostics or testing.

CComContainedObject::CComContainedObject

The constructor.

CComContainedObject(void* pv);

Parameters

pv
[in] The owner object's IUnknown.

Remarks

Sets the m_pOuterUnknown member pointer (inherited through the Base class) to pv.

CComContainedObject::~CComContainedObject

The destructor.

~CComContainedObject();

Remarks

Frees all allocated resources.

CComContainedObject::GetControllingUnknown

Returns the m_pOuterUnknown member pointer (inherited through the Base class) that holds the owner object's IUnknown.

IUnknown* GetControllingUnknown();

Return Value

The owner object's IUnknown.

Remarks

This method may be virtual if Base has declared the DECLARE_GET_CONTROLLING_UNKNOWN macro.

CComContainedObject::QueryInterface

Retrieves a pointer to the interface requested on the owner object.

STDMETHOD(QueryInterface)(REFIID iid, void** ppvObject);
template <class Q>
HRESULT STDMETHODCALLTYPE QueryInterface(Q** pp);

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.

pp
[out] A pointer to the interface pointer identified by type Q. If the object does not support this interface, pp is set to NULL.

Return Value

A standard HRESULT value.

CComContainedObject::Release

Decrements the reference count on the owner object.

STDMETHOD_(ULONG, Release)();

Return Value

In debug builds, Release returns a value that may be useful for diagnostics or testing. In non-debug builds, Release always returns 0.

See Also

Class Overview