Introduction
Let's ensure we understand the foundational concepts before delving further into the subjects. Here is a brief introduction if you are unfamiliar with ATL.
The Active Template Library (ATL) is a Microsoft library that provides a set of C++ templates to simplify the development of COM objects and other Windows-based applications.

The article explains the details of Class factories class-CComClassFactoryAutoThreadt in ATL. Let's get started.
CComClassFactoryAutoThread Class
This class enables the creation of objects in numerous apartments by implementing the IClassFactory interface.
Note: Applications that run in the Windows Runtime cannot use this class or any of its members.
Syntax
class CComClassFactoryAutoThread
: public IClassFactory,
public CComObjectRootEx<CComGlobalsThreadModel>
Members
Public Methods
Name |
Description |
CComClassFactoryAutoThread::CreateInstance |
Creates an object with the given CLSID. |
CComClassFactoryAutoThread::LockServer |
Locks the class factory in memory. |
Remarks
The members of this class and this class cannot be used in Windows Runtime apps. Similar to CComClassFactory, CComClassFactoryAutoThread enables the creation of objects in several residences. Derive your EXE module from CComAutoThreadModule to utilise this feature.
By inheriting from CComCoClass, ATL objects often obtain a class factory. The macro DECLARE CLASSFACTORY, which names CComClassFactory as the default class factory, is included in this class. Include the DECLARE CLASSFACTORY AUTO THREAD macro in the class definition of your object if you want to use CComClassFactoryAutoThread. For instance:
class ATL_NO_VTABLE CMyAutoClass :
public CComObjectRootEx<CComMultiThreadModel>,
public CComCoClass<CMyAutoClass, &CLSID_MyAutoClass>,
public IMyAutoClass
{
public:
DECLARE_CLASSFACTORY_AUTO_THREAD()
Inheritance Hierarchy

Requirements
Header: atlcom.h