CComAutoThreadModule Class

As of ATL 7.0, CComAutoThreadModule is obsolete: see ATL Module Classes for more details.

Important

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

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

Parameters

Members

Methods

CreateInstance

Selects a thread and then creates an object in the associated apartment.

GetDefaultThreads

(Static) Dynamically calculates the number of threads for the module based on the number of processors.

Init

Creates the module's threads.

Lock

Increments the lock count on the module and on the current thread.

Unlock

Decrements the lock count on the module and on the current thread.

Data Members

Data Members

dwThreadID

Contains the identifier of the current thread.

m_Allocator

Manages thread selection.

m_nThreads

Contains the number of threads in the module.

m_pApartments

Manages the module's apartments.

Remarks

Note

This class is obsolete, having been replaced by the CAtlAutoThreadModule and CAtlModule derived classes. The information that follows is for use with older releases of ATL.

CComAutoThreadModule derives from CComModule to implement a thread-pooled, apartment-model COM server for EXEs and Windows 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 (the ATL Project Wizard in Visual Studio .NET) 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<CComSimpleThreadAllocator>::Unlock();
      if (l == 0)
         PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
      return l;
   }

   DWORD dwThreadID;
};

Inheritance Hierarchy

_ATL_MODULE

CAtlModule

IAtlAutoThreadModule

CAtlModuleT

CAtlAutoThreadModuleT

CComModule

CComAutoThreadModule

Requirements

Header: atlbase.h

See Also

Reference

ATL Module Classes

Other Resources

ATL Class Overview