AlexandruC
AlexandruC

Reputation: 3637

CAppModule vs CAtlExeModuleT , getting the application message loop

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

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?

Upvotes: 5

Views: 3859

Answers (1)

Roman Ryltsov
Roman Ryltsov

Reputation: 69706

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

Upvotes: 10

Related Questions