Επεξεργασία

Κοινή χρήση μέσω


CComObjectGlobal Class

This class manages a reference count on the module containing your Base object.

Syntax

template<class Base>
class CComObjectGlobal : public Base

Parameters

Base
Your class, derived from CComObjectRoot or CComObjectRootEx, as well as from any other interface you want to support on the object.

Members

Public Constructors

Name Description
CComObjectGlobal::CComObjectGlobal The constructor.
CComObjectGlobal::~CComObjectGlobal The destructor.

Public Methods

Name Description
CComObjectGlobal::AddRef Implements a global AddRef.
CComObjectGlobal::QueryInterface Implements a global QueryInterface.
CComObjectGlobal::Release Implements a global Release.

Public Data Members

Name Description
CComObjectGlobal::m_hResFinalConstruct Contains the HRESULT returned during construction of the CComObjectGlobal object.

Remarks

CComObjectGlobal manages a reference count on the module containing your Base object. CComObjectGlobal ensures your object will not be deleted as long as the module is not released. Your object will only be removed when the reference count on the entire module goes to zero.

For example, using CComObjectGlobal, a class factory can hold a common global object that is shared by all its clients.

Inheritance Hierarchy

Base

CComObjectGlobal

Requirements

Header: atlcom.h

CComObjectGlobal::AddRef

Increments the reference count of the object by 1.

STDMETHOD_(ULONG, AddRef)();

Return Value

A value that may be useful for diagnostics and testing.

Remarks

By default, AddRef calls _Module::Lock, where _Module is the global instance of CComModule or a class derived from it.

CComObjectGlobal::CComObjectGlobal

The constructor. Calls FinalConstruct and then sets m_hResFinalConstruct to the HRESULT returned by FinalConstruct.

CComObjectGlobal(void* = NULL));

Remarks

If you have not derived your base class from CComObjectRoot, you must supply your own FinalConstruct method. The destructor calls FinalRelease.

CComObjectGlobal::~CComObjectGlobal

The destructor.

CComObjectGlobal();

Remarks

Frees all allocated resources and calls FinalRelease.

CComObjectGlobal::m_hResFinalConstruct

Contains the HRESULT from calling FinalConstruct during construction of the CComObjectGlobal object.

HRESULT m_hResFinalConstruct;

CComObjectGlobal::QueryInterface

Retrieves a pointer to the requested interface pointer.

STDMETHOD(QueryInterface)(REFIID iid, void** ppvObject);

Parameters

iid
[in] The GUID of the interface being requested.

ppvObject
[out] A pointer to the interface pointer identified by iid, or NULL if the interface is not found.

Return Value

A standard HRESULT value.

Remarks

QueryInterface only handles interfaces in the COM map table.

CComObjectGlobal::Release

Decrements the reference count of the object by 1.

STDMETHOD_(ULONG, Release)();

Return Value

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

Remarks

By default, Release calls _Module::Unlock, where _Module is the global instance of CComModule or a class derived from it.

See also

CComObjectStack Class
CComAggObject Class
CComObject Class
Class Overview