description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | |||||
---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CComClassFactory Class |
CComClassFactory Class |
11/04/2016 |
|
|
e56dacf7-d5c4-4c42-aef4-a86d91981a1b |
This class implements the IClassFactory interface.
class CComClassFactory
: public IClassFactory,
public CComObjectRootEx<CComGlobalsThreadModel>
Name | Description |
---|---|
CComClassFactory::CreateInstance | Creates an object of the specified CLSID. |
CComClassFactory::LockServer | Locks the class factory in memory. |
CComClassFactory
implements the IClassFactory interface, which contains methods for creating an object of a particular CLSID, as well as locking the class factory in memory to allow new objects to be created more quickly. IClassFactory
must be implemented for every class that you register in the system registry and to which you assign a CLSID.
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 override this default, specify one of the DECLARE_CLASSFACTORY
XXX macros in your class definition. For example, the DECLARE_CLASSFACTORY_EX macro uses the specified class for the class factory:
[!code-cppNVC_ATL_COM#8]
The above class definition specifies that CMyClassFactory
will be used as the object's default class factory. CMyClassFactory
must derive from CComClassFactory
and override CreateInstance
.
ATL provides three other macros that declare a class factory:
-
DECLARE_CLASSFACTORY2 Uses CComClassFactory2, which controls creation through a license.
-
DECLARE_CLASSFACTORY_AUTO_THREAD Uses CComClassFactoryAutoThread, which creates objects in multiple apartments.
-
DECLARE_CLASSFACTORY_SINGLETON Uses CComClassFactorySingleton, which constructs a single CComObjectGlobal object.
Header: atlcom.h
Creates an object of the specified CLSID and retrieves an interface pointer to this object.
STDMETHOD(CreateInstance)(LPUNKNOWN pUnkOuter, REFIID riid, void** ppvObj);
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.
A standard HRESULT value.
Increments and decrements the module lock count by calling _Module::Lock
and _Module::Unlock
, respectively.
STDMETHOD(LockServer)(BOOL fLock);
fLock
[in] If TRUE, the lock count is incremented; otherwise, the lock count is decremented.
A standard HRESULT value.
_Module
refers to the global instance of CComModule or a class derived from it.
Calling LockServer
allows a client to hold onto a class factory so that multiple objects can be created quickly.
CComObjectRootEx Class
CComGlobalsThreadModel
Class Overview