Does ATL/WTL still require the use of a global _Module variable?
Asked Answered
C

2

5

I'm just starting up a new ATL/WTL project and I was wondering if the global _Module variable is still required?

Back a few years when I started working with WTL it was required (at least for ATL 3.0) that you define a global variable such as:

CAppModule _Module;

To get ATL to work correctly. But recently I've read somewhere that this may not be required anymore (yet the wizard generated code still uses it). Also I did a search through the Visual C++ include directories and it only picked up _Module in a few places - most notably the ATL COM registry stuff.

So do I still need to define a global variable to use ATL these days?

Cud answered 13/10, 2008 at 12:46 Comment(0)
G
7

Technically you do not need a global _Module instance since ATL/WTL version 7. Earlier ATL/WTL code referenced _Module by this specific name and expected you to declare a single instance of this object. This has since been replaced by a single instance object named _AtlBaseModule that is automatically declared for you in atlcore.h.

Having said that, though, some of the best WTL features are contained within CAppModule and its base class CComModule. Automatic COM registration, message loop handling, etc. So most non-trivial WTL based apps will still want a singleton instance of a CComModule base class. However, it doesn't need to be named _Module.

Glovsky answered 31/10, 2008 at 15:16 Comment(0)
W
1

In the sample projects of the latest WTL version, this is still used.

In stdafx.h:

extern CAppModule _Module;

In implementation files:

CAppModule _Module;
Welcy answered 14/10, 2008 at 6:58 Comment(2)
I did mention that the latest wizard generated code still uses it, same thing for the samples. Still doesn't answer my question though.Cud
Since you did not mention the WTL samples, which are more interesting than those in the VS folders, I thought it was completely appropriate to mention the.Welcy

© 2022 - 2024 — McMap. All rights reserved.