CComAutoThreadModule

template< class ThreadAllocator = CComSimpleThreadAllocator >
class CComAutoThreadModule : public CComModule

Parameters

ThreadAllocator

[in] The class managing thread selection. The default value is CComSimpleThreadAllocator.

CComAutoThreadModule derives from CComModule to implement a thread-pooled, apartment-model COM server for EXEs and Windows NT services. CComAutoThreadModule uses CComApartment to manage an apartment for each thread in the module.

Derive your module from CComAutoThreadModule when you want to create objects in multiple apartments. You must also include the DECLARE_CLASSFACTORY_AUTO_THREAD macro in your object’s class definition to specify CComClassFactoryAutoThread as the class factory.

By default, the ATL COM AppWizard will derive your module from CComModule. To use CComAutoThreadModule, modify the class definition. For example:

class CMyModule : 
public CComAutoThreadModule<CComSimpleThreadAllocator>
{
public:
   LONG Unlock( )
   {
      LONG l = CComAutoThreadModule<ComSimpleThreadAllocator>::Unlock( );
      if (l == 0)
         PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
      return l;
   }

   DWORD dwThreadID;
};

For more information about the AppWizard, see the article Creating an ATL Project.

#include <atlbase.h>

Class Members