CComObjectGlobal 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 CComObjectGlobal Class.

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

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.

Public Constructors

NameDescription
CComObjectGlobal::CComObjectGlobalThe constructor.
CComObjectGlobal::~CComObjectGlobalThe destructor.

Public Methods

NameDescription
CComObjectGlobal::AddRefImplements a global AddRef.
CComObjectGlobal::QueryInterfaceImplements a global QueryInterface.
CComObjectGlobal::ReleaseImplements a global Release.

Public Data Members

NameDescription
CComObjectGlobal::m_hResFinalConstructContains the HRESULT returned during construction of the CComObjectGlobal object.

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.

Base

CComObjectGlobal

Header: atlcom.h

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.

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.

The destructor.

CComObjectGlobal();

Remarks

Frees all allocated resources and calls FinalRelease.

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

HRESULT m_hResFinalConstruct;

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.

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.

CComObjectStack Class
CComAggObject Class
CComObject Class
Class Overview

Show: