_pAtlModule指针为null,当我尝试使用CComObject函数CreateInstance [英] _pAtlModule pointer is null when i try to CreateInstance using the CComObject function

查看:1779
本文介绍了_pAtlModule指针为null,当我尝试使用CComObject函数CreateInstance的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OPC(OLE过程控制)客户端程序,使用异步CALLBACK方法从PLC使用KepServer获取数据。但我遇到了问题:

  CComObject< COPCDataCallback> * pCOPCDataCallback; //回调对象的指针

//使用ATL模板创建回调对象实例
CComObject< COPCDataCallback> :: CreateInstance(& pCOPCDataCallback);

,然后停在此处:

  _pAtlModule-> Lock(); 

这在atlcom.h



如何使用 microsoft.com/en-us/library/x1c35cc3rel =nofollow> ATL类 CComObject ,假设您有一个ATL项目,其中定义了ATL模块类,例如 CAtlExeModuleT 基于EXE应用程序。



没有定义模块类/实例,没有初始化全局内部 _pAtlModule 变量,因此存在问题。



添加ATL支持的方法之一是使用IDE,通常如果您现有的项目是基于MFC的:





另一种方法是如果您的项目使用WTL,则添加 CAppModule 实例:





然后第三种方法是使用Visual Studio向导创建一个匹配类型(EXE或DLL)的新的干净ATL项目,并检查代码 CAtlDllModuleT CAtlExeModuleT 类,然后在现有项目中重复。


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?

解决方案

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.

这篇关于_pAtlModule指针为null,当我尝试使用CComObject函数CreateInstance的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆