问题
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