ATL/WTL 是否仍然需要使用全局 _Module 变量? [英] Does ATL/WTL still require the use of a global _Module variable?

查看:23
本文介绍了ATL/WTL 是否仍然需要使用全局 _Module 变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始一个新的 ATL/WTL 项目,我想知道是否仍然需要全局 _Module 变量?

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

几年前,当我开始使用 WTL 时,您需要(至少对于 ATL 3.0)定义一个全局变量,例如:

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;

为了让 ATL 正常工作.但最近我在某处读到这可能不再需要(但向导生成的代码仍然使用它).此外,我还搜索了 Visual C++ 包含目录,它只在少数几个地方找到了 _Module - 最显着的是 ATL COM 注册表内容.

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.

那么这些天我还需要定义一个全局变量来使用 ATL 吗?

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

推荐答案

从 ATL/WTL 版本 7 开始,从技术上讲,您不需要全局 _Module 实例.早期的 ATL/WTL 代码引用了 _Module 通过此特定名称并希望您声明此对象的单个实例.这已被名为 _AtlBaseModule 的单个实例对象所取代,该对象在 atlcore.h 中自动为您声明.

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.

话虽如此,一些最好的 WTL 特性包含在 CAppModule 及其基类 CComModule 中.自动 COM 注册、消息循环处理等.因此,大多数基于 WTL 的重要应用程序仍然需要 CComModule 基类的单例实例.但是,它不需要命名为_Module.

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.

这篇关于ATL/WTL 是否仍然需要使用全局 _Module 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆