description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CAtlExeModuleT Class |
CAtlExeModuleT Class |
11/04/2016 |
|
|
82245f3d-91d4-44fa-aa86-7cc7fbd758d9 |
This class represents the module for an application.
template <class T>
class ATL_NO_VTABLE CAtlExeModuleT : public CAtlModuleT<T>
T
Your class derived from CAtlExeModuleT
.
Name | Description |
---|---|
CAtlExeModuleT::CAtlExeModuleT | The constructor. |
CAtlExeModuleT::~CAtlExeModuleT | The destructor. |
Name | Description |
---|---|
CAtlExeModuleT::InitializeCom | Initializes COM. |
CAtlExeModuleT::ParseCommandLine | Parses the command line and performs registration if necessary. |
CAtlExeModuleT::PostMessageLoop | This method is called immediately after the message loop exits. |
CAtlExeModuleT::PreMessageLoop | This method is called immediately before entering the message loop. |
CAtlExeModuleT::RegisterClassObjects | Registers the class object. |
CAtlExeModuleT::RevokeClassObjects | Revokes the class object. |
CAtlExeModuleT::Run | This method executes code in the EXE module to initialize, run the message loop, and clean up. |
CAtlExeModuleT::RunMessageLoop | This method executes the message loop. |
CAtlExeModuleT::UninitializeCom | Uninitializes COM. |
CAtlExeModuleT::Unlock | Decrements the module's lock count. |
CAtlExeModuleT::WinMain | This method implements the code required to run an EXE. |
Name | Description |
---|---|
CAtlExeModuleT::m_bDelayShutdown | A flag indicating that there should be a delay shutting down the module. |
CAtlExeModuleT::m_dwPause | A pause value used to ensure all objects are released before shutdown. |
CAtlExeModuleT::m_dwTimeOut | A 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.
CAtlExeModuleT
Header: atlbase.h
The constructor.
CAtlExeModuleT() throw();
If the EXE module could not be initialized, WinMain will immediately return without further processing.
The destructor.
~CAtlExeModuleT() throw();
Frees all allocated resources.
Initializes COM.
static HRESULT InitializeCom() throw();
Returns S_OK on success, or an error HRESULT on failure.
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;
See the CAtlExeModuleT Overview for details.
A pause value used to ensure all objects are gone before shutdown.
DWORD m_dwPause;
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;
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();
lpCmdLine
The command line passed to the application.
pnRetCode
The HRESULT corresponding to the registration (if it took place).
Return true if the application should continue to run, otherwise false.
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();
Returns S_OK on success, or an error HRESULT on failure.
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();
nShowCmd
The value passed as the nShowCmd parameter in WinMain.
Returns S_OK on success, or an error HRESULT on failure.
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();
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.
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();
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();
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.
Returns S_OK on success, or an error HRESULT on failure.
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();
This method can be overridden to change the behavior of the message loop.
Uninitializes COM.
static void UninitializeCom() throw();
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();
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();
nShowCmd
Specifies how the window is to be shown. This parameter can be one of the values discussed in the WinMain section.
Returns the executable's return value.
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