4

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?

Roman R.
  • 68,205
  • 6
  • 94
  • 158
liyang
  • 41
  • 1
  • 8

1 Answers1

7

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:

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

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.

Community
  • 1
  • 1
Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • @lyang You should mark this as the solution. It gives points to the person who answered. – Jamie Feb 18 '19 at 03:18
  • 2
    It seems that you can also use CComObjectNoLock but that doesn't lock the module. Use CComCreator then to create the object (but this increments the reference count contrary to CComObject::CreateInstance). – gast128 Dec 02 '19 at 16:02