#import "C:\Program Files\ComPlus Applications\{6A6E8291-291D-4168-8D50-34A2DF360B25}\iPushReqCheck.dll" no_namespace named_guidsint main(int argc, char* argv[])
{
short pRlt = 0;
HRESULT hr =CoInitialize(NULL);
if (FAILED(hr))
{
return 0;
}
_variant_t vtNum,vtDes;
IReqCheckPtr pIReqCheck = NULL;
hr = pIReqCheck.CreateInstance(__uuidof(IReqCheck));
if (FAILED(hr))//没有调用成功,
{
return 0;
}
pRlt = pIReqCheck->PushReqCheck("1",&vtNum,&vtDes);
printf("PushReqCheck-->%d!\r\n",pRlt);
CoUninitialize();
return 0;
}
结果hr返回了错误信息 -2147221164 请问是什么原因??
{
short pRlt = 0;
HRESULT hr =CoInitialize(NULL);
if (FAILED(hr))
{
return 0;
}
_variant_t vtNum,vtDes;
IReqCheckPtr pIReqCheck = NULL;
hr = pIReqCheck.CreateInstance(__uuidof(IReqCheck));
if (FAILED(hr))//没有调用成功,
{
return 0;
}
pRlt = pIReqCheck->PushReqCheck("1",&vtNum,&vtDes);
printf("PushReqCheck-->%d!\r\n",pRlt);
CoUninitialize();
return 0;
}
结果hr返回了错误信息 -2147221164 请问是什么原因??
HRESULT hr=CoCreateInstance( CLSID_ComTest, NULL,
CLSCTX_INPROC_SERVER,
IID_IComTest,
reinterpret_cast<void**>(&pCom));
//check return code
if (FAILED(hr))
{
MessageBox("Could not create instance","Error in CoCreateInstance",MB_OK);
}
else
{
//Use the interface
这样看看!
总有人在这个上面犯错误,CreateInstance要求的是类的GUID,你却给的接口的GUID,那当然创建不出来了。
改成
pIReqCheck.CreateInstance(__uuidof(ReqCheck));
应该差不多了!
rclsid
[in] CLSID associated with the data and code that will be used to create the object. pUnkOuter [in] If NULL, indicates that the object is not being created as part of an aggregate. If non-NULL, pointer to the aggregate object's IUnknown interface (the controlling IUnknown). dwClsContext [in] Context in which the code that manages the newly created object will run. The values are taken from the enumeration CLSCTX. riid [in] Reference to the identifier of the interface to be used to communicate with the object. ppv [out] Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppv contains the requested interface pointer. Upon failure, *ppv contains NULL.