Question

I am trying to get the message loop from a ATL::CAppModule in my project, there seems to be none, so:

  • I've tried defining CAppModule, with extern CAppModule _Module; in "stdafx.h" and CAppModule _Module; in my .cpp file, it compiles, linkes and at the perform registration step I get an assertion in atlbase.h here ATLASSERT(_pAtlModule == NULL); which means that the CAppModule has already been declared.

But I can't seem to find another CAppModule instantiation, instead I see a CAtlExeModuleT instantiation (it is not my code..).

now.. from what I've searched I haven t found a way to get the message loop from a CAtlExeModuleT object. Are they different things or am I missing something?

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top