_pAtlModule pointer is null when i try to CreateInstance using the CComObject function

与世无争的帅哥 提交于 2019-12-24 13:26:11

问题


I am working on the OPC(OLE process Control)Client program,with the asynchronous CALLBACK methods to get data from PLC using the KepServer.But I encountered the issue:

CComObject<COPCDataCallback>* pCOPCDataCallback;    // Pointer to Callback Object

// Create Instance of Callback Object using an ATL template
CComObject<COPCDataCallback>::CreateInstance(&pCOPCDataCallback);

and then it stopped at here:

_pAtlModule->Lock();

this is in the atlcom.h

any ideas of how to solve this issue?


回答1:


When you are using ATL classes like CComObject, it is assumed that you have an ATL project, with "ATL module" class defined in it, such as CAtlExeModuleT based for EXE application.

With no module class/instance defined, there is no initialization of global internal _pAtlModule variable and hence the problem. You need to add the module class.

One of the ways to add ATL support is using IDE, typically if your existing project is MFC-based:

  • Adding ATL support to existing mfc application
  • How to get ATL support into an existing Windows application

Another way is to add CAppModule instance, if your project is using WTL:

  • CAppModule vs CAtlExeModuleT , getting the application message loop

Then third way is to create a new clean ATL project of matching type (EXE or DLL) using Visual Studio wizard, and to check the code around CAtlDllModuleT or CAtlExeModuleT classes, then to duplicate that in your existing project.



来源:https://stackoverflow.com/questions/33099122/patlmodule-pointer-is-null-when-i-try-to-createinstance-using-the-ccomobject-fu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!