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


场景:

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;




你可能感兴趣的:(fail,atl,createInstance,CComObject)