There is a mix of issues here. CAppModule
is a WTL class. _pAtlModule
is static/global ATL variable that points to module singleton class.
You cannot fix ATL _pAtlModule
problem with WTL CAppModule
because the two are unrelated (atlthough have certain similarity between).
To fix the _pAtlModule
problem you need an ATL module instance. The simplest is to add CComModule
static:
CComModule _Module; // <-- Here you go
int _tmain(int argc, _TCHAR* argv[])
{
//...
Because CComModule
itself is here for backward compatibility only, it would be the better to use CAtlExeModuleT
(and friends) instead, however WTL will not work this way because WTL's CAppModule
inherits from CComModule
. The global instance of CAppModule
will also be the instance for ATL CComModule
:
CAppModule _Module;
int _tmain(int argc, _TCHAR* argv[])
{
// ...
_Module.Init(...
CMessageLoop MessageLoop;
_Module.AddMessageLoop(&MessageLoop);
// ...
and then later on some application object:
CMessageLoop* pMessageLoop = _Module.GetMessageLoop();
the GetMessageLoop
call will retrieve the message loop you added earlier.
Having this ATL/WTL issue resolved, you can move on to the WTL message loop thing, where you expect PreTranslateMessage
to be called on modal dialog message loop and it won't be called there because it is not expected to work this way (CMessageLoop
calls message filter chain, and modal dialog's loop don't).