CComClassFactorySingleton Class

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

This class derives from CComClassFactory and uses CComObjectGlobal to construct a single object.

System_CAPS_ICON_important.jpg Important

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

template<class T>  class CComClassFactorySingleton :  public CComClassFactory

Parameters

T
Your class.

CComClassFactorySingleton derives from CComClassFactory and uses CComObjectGlobal to construct a single object. Each call to the CreateInstance method simply queries this object for an interface pointer.

Public Methods

NameDescription
CComClassFactorySingleton::CreateInstanceQueries m_spObj for an interface pointer.

Public Data Members

NameDescription
CComClassFactorySingleton::m_spObjThe CComObjectGlobal object constructed by CComClassFactorySingleton.

ATL objects normally acquire a class factory by deriving from CComCoClass. This class includes the macro DECLARE_CLASSFACTORY, which declares CComClassFactory as the default class factory. To use CComClassFactorySingleton, specify the DECLARE_CLASSFACTORY_SINGLETON macro in your object's class definition. For example:

class ATL_NO_VTABLE CMySingletonClass :
   public CComObjectRootEx<CComSingleThreadModel>,
   public CComCoClass<CMySingletonClass, &CLSID_MySingletonClass>,
   public IMySingletonClass
{
public:
   DECLARE_CLASSFACTORY_SINGLETON(CMySingletonClass)

   // Remainder of class declaration omitted.

CComObjectRootBase

CComObjectRootEx

IClassFactory

CComClassFactory

CComClassFactorySingleton

Header: atlcom.h

Calls QueryInterface through m_spObj to retrieve an interface pointer.

STDMETHOD(CreateInstance)(LPUNKNOWN pUnkOuter,
    REFIID riid,
    void** ppvObj);

Parameters

pUnkOuter
[in] If the object is being created as part of an aggregate, then pUnkOuter must be the outer unknown. Otherwise, pUnkOuter must be NULL.

riid
[in] The IID of the requested interface. If pUnkOuter is non- NULL, riid must be IID_IUnknown.

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

Return Value

A standard HRESULT value.

The CComObjectGlobal object constructed by CComClassFactorySingleton.

CComPtr<IUnknown> m_spObj;

Remarks

Each call to the CreateInstance method simply queries this object for an interface pointer.

Note that the current form of m_spObj presents a breaking change from the way that CComClassFactorySingleton worked in previous versions of ATL. In previous versions the CComClassFactorySingleton object was created at the same time as the class factory, during server initialization. In Visual C++.NET 2003, the object is created lazily, on the first request. This change could cause errors in programs that rely on early initialization.

IClassFactory
CComClassFactory2 Class
CComClassFactoryAutoThread Class
CComObjectRootEx Class
CComGlobalsThreadModel
Class Overview

Show: