[Windows]_[初级]_[CComObject fails to CreateInstance]

本文探讨了CComObject在调用CreateInstance时发生崩溃的问题,并提供了详细的解决方案。问题出现的原因在于程序中未定义自己的模块(_Module),解决方法是在程序中添加相应的模块定义。


场景:

1. CComObject在调用CreateInstance时崩溃了, 调试发现_pAtlModule是NULL.

2. 解决办法,在Main函数里添加.或者new CComModule, 总之在调用CComObject前先初始化_pAtlModule.

CComModule _Module;
_pAtlModule = &_Module;


转载:  原文地址


Hi,

I think the reason is: your program hasn't its own Module(_Module) defined in the code.

In the atlbase.h, there is:

class CAtlModule;
__declspec(selectany) CAtlModule* _pAtlModule = NULL;





In the CAtlModule's constructor, "this" module will be assigned to _pAtlModule, so your program should have its own Module, you could add below code in your program to solve this problem:

CComModule _Module;
extern __declspec(selectany) CAtlModule* _pAtlModule;
_pAtlModule = &_Module;




评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值