CAtlExeModuleT Class

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

This class represents the module for an application.

template <class T>  
class ATL_NO_VTABLE CAtlExeModuleT : public CAtlModuleT<T>

Parameters

T
Your class derived from CAtlExeModuleT.

Public Constructors

NameDescription
CAtlExeModuleT::CAtlExeModuleTThe constructor.
CAtlExeModuleT::~CAtlExeModuleTThe destructor.

Public Methods

NameDescription
CAtlExeModuleT::InitializeComInitializes COM.
CAtlExeModuleT::ParseCommandLineParses the command line and performs registration if necessary.
CAtlExeModuleT::PostMessageLoopThis method is called immediately after the message loop exits.
CAtlExeModuleT::PreMessageLoopThis method is called immediately before entering the message loop.
CAtlExeModuleT::RegisterClassObjectsRegisters the class object.
CAtlExeModuleT::RevokeClassObjectsRevokes the class object.
CAtlExeModuleT::RunThis method executes code in the EXE module to initialize, run the message loop, and clean up.
CAtlExeModuleT::RunMessageLoopThis method executes the message loop.
CAtlExeModuleT::UninitializeComUninitializes COM.
CAtlExeModuleT::UnlockDecrements the module's lock count.
CAtlExeModuleT::WinMainThis method implements the code required to run an EXE.

Public Data Members

NameDescription
CAtlExeModuleT::m_bDelayShutdownA flag indicating that there should be a delay shutting down the module.
CAtlExeModuleT::m_dwPauseA pause value used to ensure all objects are released before shutdown.
CAtlExeModuleT::m_dwTimeOutA time-out value used to delay the unloading of the module.

CAtlExeModuleT represents the module for an application (EXE) and contains code that supports creating an EXE, processing the command line, registering class objects, running the message loop, and cleaning up on exit.

This class is designed to improve performance when COM objects in the EXE server are continually created and destroyed. After the last COM object is released, the EXE waits for a duration specified by the CAtlExeModuleT::m_dwTimeOut data member. If there is no activity during this period (that is, no COM objects are created), the shutdown process is initiated.

The CAtlExeModuleT::m_bDelayShutdown data member is a flag used to determine if the EXE should use the mechanism defined above. If it is set to false, then the module will terminate immediately.

For more information on modules in ATL, see ATL Module Classes.

_ATL_MODULE

CAtlModule

CAtlModuleT

CAtlExeModuleT

Header: atlbase.h

The constructor.

CAtlExeModuleT() throw();

Remarks

If the EXE module could not be initialized, WinMain will immediately return without further processing.

The destructor.

~CAtlExeModuleT() throw();

Remarks

Frees all allocated resources.

Initializes COM.

static HRESULT InitializeCom() throw();

Return Value

Returns S_OK on success, or an error HRESULT on failure.

Remarks

This method is called from the constructor and can be overridden to initialize COM in a manner different from the default implementation. The default implementation either calls CoInitializeEx(NULL, COINIT_MULTITHREADED) or CoInitialize(NULL) depending on the project configuration.

Overriding this method normally requires overriding CAtlExeModuleT::UninitializeCom.

A flag indicating that there should be a delay shutting down the module.

bool m_bDelayShutdown;

Remarks

See the CAtlExeModuleT Overview for details.

A pause value used to ensure all objects are gone before shutdown.

DWORD m_dwPause;

Remarks

Change this value after calling CAtlExeModuleT::InitializeCom to set the number of milliseconds used as the pause value for shutting down the server. The default value is 1000 milliseconds.

A time-out value used to delay the unloading of the module.

DWORD m_dwTimeOut;

Remarks

Change this value after calling CAtlExeModuleT::InitializeCom to define the number of milliseconds used as the time-out value for shutting down the server. The default value is 5000 milliseconds. See the CAtlExeModuleT Overview for more details.

Parses the command line and performs registration if necessary.

bool ParseCommandLine(LPCTSTR lpCmdLine, HRESULT* pnRetCode) throw();

Parameters

lpCmdLine
The command line passed to the application.

pnRetCode
The HRESULT corresponding to the registration (if it took place).

Return Value

Return true if the application should continue to run, otherwise false.

Remarks

This method is called from CAtlExeModuleT::WinMain and can be overridden to handle command-line switches. The default implementation checks for /RegServer and /UnRegServer command-line arguments and performs registration or unregistration.

This method is called immediately after the message loop exits.

HRESULT PostMessageLoop() throw();

Return Value

Returns S_OK on success, or an error HRESULT on failure.

Remarks

Override this method to perform custom application cleanup. The default implementation calls CAtlExeModuleT::RevokeClassObjects.

This method is called immediately before entering the message loop.

HRESULT PreMessageLoop(int nShowCmd) throw();

Parameters

nShowCmd
The value passed as the nShowCmd parameter in WinMain.

Return Value

Returns S_OK on success, or an error HRESULT on failure.

Remarks

Override this method to add custom initialization code for the application. The default implementation registers the class objects.

Registers the class object with OLE so other applications can connect to it.

HRESULT RegisterClassObjects(DWORD dwClsContext, DWORD dwFlags) throw();

Parameters

dwClsContext
Specifies the context in which the class object is to be run. Possible values are CLSCTX_INPROC_SERVER, CLSCTX_INPROC_HANDLER, or CLSCTX_LOCAL_SERVER.

dwFlags
Determines the connection types to the class object. Possible values are REGCLS_SINGLEUSE, REGCLS_MULTIPLEUSE, or REGCLS_MULTI_SEPARATE.

Return Value

Returns S_OK on success, S_FALSE if there were no classes to register, or an error HRESULT on failure.

Removes the class object.

HRESULT RevokeClassObjects() throw();

Return Value

Returns S_OK on success, S_FALSE if there were no classes to register, or an error HRESULT on failure.

This method executes code in the EXE module to initialize, run the message loop, and clean up.

HRESULT Run(int nShowCmd = SW_HIDE) throw();

Parameters

nShowCmd
Specifies how the window is to be shown. This parameter can be one of the values discussed in the WinMain section. Defaults to SW_HIDE.

Return Value

Returns S_OK on success, or an error HRESULT on failure.

Remarks

This method can be overridden. However, in practice is it better to override CAtlExeModuleT::PreMessageLoop, CAtlExeModuleT::RunMessageLoop, or CAtlExeModuleT::PostMessageLoop instead.

This method executes the message loop.

void RunMessageLoop() throw();

Remarks

This method can be overridden to change the behavior of the message loop.

Uninitializes COM.

static void UninitializeCom() throw();

Remarks

By default this method simply calls CoUninitialize and is called from the destructor. Override this method if you override CAtlExeModuleT::InitializeCom.

Decrements the module's lock count.

LONG Unlock() throw();

Return Value

Returns a value which may be useful for diagnostics or testing.

This method implements the code required to run an EXE.

int WinMain(int nShowCmd) throw();

Parameters

nShowCmd
Specifies how the window is to be shown. This parameter can be one of the values discussed in the WinMain section.

Return Value

Returns the executable's return value.

Remarks

This method can be overridden. If overriding CAtlExeModuleT::PreMessageLoop, CAtlExeModuleT::PostMessageLoop, or CAtlExeModuleT::RunMessageLoop doesn't provide enough flexibility, it's possible to override the WinMain function using this method.

ATLDuck Sample
CAtlModuleT Class
CAtlDllModuleT Class
Class Overview

Show: