class CComClassFactoryAutoThread : public IClassFactory,
public CComObjectRootEx< CComGlobalsThreadModel >
CComClassFactoryAutoThread is similar to CComClassFactory, but allows objects to be created in multiple apartments. To take advantage of this support, derive your EXE module from CComAutoThreadModule.
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 CComClassFactoryAutoThread, specify the DECLARE_CLASSFACTORY_AUTO_THREAD macro in your object's class definition. For example:
class CMyClass : ..., public CComCoClass< ... > { public: DECLARE_CLASSFACTORY_AUTO_THREAD( )
... };
#include <atlcom.h>
See Also CComClassFactory2, CComClassFactorySingleton, CComObjectRootEx, CComGlobalsThreadModel, IClassFactory in the Win32 SDK
IClassFactory Methods | |
CreateInstance | Creates an object of the specified CLSID. |
LockServer | Locks the class factory in memory. |
CComClassFactoryAutoThread Overview
HRESULT CreateInstance( LPUNKNOWN pUnkOuter, REFIID riid, void** ppvObj );
Return Value
A standard HRESULT value.
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.
Remarks
Creates an object of the specified CLSID and retrieves an interface pointer to this object. If your module derives from CComAutoThreadModule, CreateInstance first selects a thread to create the object in the associated apartment.
CComClassFactoryAutoThread Overview | Class Members
See Also CoCreateInstance and CoGetClassObject in the Win32 SDK
HRESULT LockServer( BOOL fLock );
Return Value
A standard HRESULT value.
Parameters
fLock [in] If TRUE, the lock count is incremented; otherwise, the lock count is decremented.
Remarks
Increments and decrements the module lock count by calling _Module::Lock and _Module::Unlock, respectively. When using CComClassFactoryAutoThread, _Module typically refers to the global instance of CComAutoThreadModule.
Calling LockServer allows a client to hold onto a class factory so that multiple objects can be quickly created.
CComClassFactoryAutoThread Overview | Class Members
See Also CComAutoThreadModule::Lock, CComAutoThreadModule::Unlock