关于一个Warning 的问题 .有谁能解决 ~~~~~~~~~~~~~~

victorliu168 2004-11-08 10:45:11
我编写了一个关于com的测试程式.
设定

一 In process DLL
二 Support MFC
三 Connection Point

问题:
一 我的关于Events 的定义
[id(1), helpstring("method OnReceive")] HRESULT OnReceive(VARIANT * buf);
二 wizard 生成的代码:
HRESULT Fire_OnReceive(VARIANT * buf)
{
CComVariant varResult;
T* pT = static_cast<T*>(this);
int nConnectionIndex;
CComVariant* pvars = new CComVariant[1];
int nConnections = m_vec.GetSize();

for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
{
pT->Lock();
CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex);
pT->Unlock();
IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);
if (pDispatch != NULL)
{
VariantClear(&varResult);
pvars[0] = buf; // 警告在这里
DISPPARAMS disp = { pvars, NULL, 1, 0 };
pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL);
}
}
delete[] pvars;
return varResult.scode;

}
三 .问题
如果我要调用Fire_OnReceive的时候就会出现如下的警告
f:\victor\磁盘文档\downloads\vc\exsample for vc\testpro1\testpro1cp.h(26) : warning C4800: 'struct tagVARIANT *' : forcing value to bool 'true' or 'false' (performance warning)
f:\victor\磁盘文档\downloads\vc\exsample for vc\testpro1\testpro1cp.h(10) : while compiling class-template member function 'long __thiscall CProxy_ITestEvents<class CTest>::Fire_OnReceive(struct tagVARIANT *)'
结果我在使用com的时候在处理这个event的时候传进来的参数不是我要的却是一个boolean类型的值 .



我很着急,希望高人给予指点 .
...全文
116 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
victorliu168 2004-11-09
  • 打赏
  • 举报
回复
这个问题是因为vc的wizard 存在bug
pvars[0] = buf; //bug 就在这里。这样作是不对的。
正确的做法应该是这样:VariantCopy(pvars,buf);这样就ok了。没有warning。而且client端调用正常。
快乐鹦鹉 2004-11-08
  • 打赏
  • 举报
回复
汗。。。。。。
说说原因吧
victorliu168 2004-11-08
  • 打赏
  • 举报
回复
to all:
你们说的都不对阿.
这个问题我已经解决了.谢谢以上两位.
danyueer 2004-11-08
  • 打赏
  • 举报
回复
应该是调用的地方和头文件声明的不一致
快乐鹦鹉 2004-11-08
  • 打赏
  • 举报
回复
HRESULT Fire_OnReceive(VARIANT * buf)
看看头文件中这个函数是如何申明的呢

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧