如何使用CAtlComModule实现COM事件接收器?

her*_*ube 3 c++ com atl

我尝试重构现有的和有效的 COM事件接收器实现.事件接收器类是用C++编写的,驻留在使用不推荐使用的CComModule类的DLL中.重构的目标是用CComModule新的ATL 7.0类CAtlComModule替换.

现有实现在.cpp文件中的某处声明了一个全局变量:

CComModule _Module;
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,变量具有通常的"神奇"名称_Module.但是,缺少惯常的初始化,没有调用,CComModule::Init()DLL项目中也没有COM对象映射.事件接收器仍然有效,其事件处理程序方法被正确调用.

缺乏任何文档如何过渡CComModuleCAtlComModule,我天真地尝试将变量声明更改为:

CAtlComModule _Module;
Run Code Online (Sandbox Code Playgroud)

但是它没有用完:更改后事件接收器停止工作,即它的事件处理程序方法不再被调用.

有谁知道迁移到应该执行的步骤CAtlComModule?到目前为止,我无法在MSDN或谷歌上找到解决方案,但也许我看起来不正确...

顺便说一句:如果有必要,我可以提供有关事件接收器实现的更多细节,但到目前为止我觉得问题不在这个领域.

Igo*_*nik 5

最简单的"新风格"替代品CComModule如下所示:

class MyModule : public CAtlDllModuleT<MyModule> {};
MyModule _Module;
Run Code Online (Sandbox Code Playgroud)