Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

com

atl

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?

like image 797
liyang Avatar asked Sep 16 '25 08:09

liyang


1 Answers

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.

like image 125
Roman R. Avatar answered Sep 19 '25 00:09

Roman R.