描述:
我编写了一个关于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类型的值 .
我很着急,希望高人给予指点 .