ATL/WTL 是否仍然需要使用全局 _Module 变量?

发布于 2024-07-07 22:14:04 字数 325 浏览 4 评论 0原文

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

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

CAppModule _Module;

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝影如岚 2024-07-14 22:14:04

在最新的WTL版本的示例项目中,仍然使用这个。

在 stdafx.h 中:

extern CAppModule _Module;

在实现文件中:

CAppModule _Module;

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

In stdafx.h:

extern CAppModule _Module;

In implementation files:

CAppModule _Module;
恍梦境° 2024-07-14 22:14:04

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文