#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 请问是什么原因??

解决方案 »

  1.   

    wltsui(『冷月无声』)....iPushReqCheck.dll 已经注册了啊我就是想在VC里面调用这个组件。。但是不成功
      

  2.   

    ICom* pCom=NULL;
    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
    这样看看!
      

  3.   

    wltsui(『冷月无声』)hr 返回的代码是:标记没有引用存储 
      

  4.   

    hr = pIReqCheck.CreateInstance(__uuidof(IReqCheck));
    总有人在这个上面犯错误,CreateInstance要求的是类的GUID,你却给的接口的GUID,那当然创建不出来了。
      

  5.   

    Analyst说的没错,你看一下Debug目录下面的iPushReqCheck.tlh文件,好好看一下,在这个里面能找到“struct /* coclass */ ReqCheck;”,所以你应该把pIReqCheck.CreateInstance(__uuidof(IReqCheck));
    改成
    pIReqCheck.CreateInstance(__uuidof(ReqCheck));
    应该差不多了!
      

  6.   

    kingcom:我操死你妈!不要以为只有你会用马甲!我也会!不要以为你多牛,我鼠标一点就封了你!
      

  7.   

    关键问题是你的com没有实现类工厂,所以需要直接调用cocreateinstance
      

  8.   

    你的参数对了吗:STDAPI CoCreateInstance(REFCLSID rclsid,  LPUNKNOWN pUnkOuter,DWORD dwClsContext,REFIID riid,LPVOID * ppv); Parameters 
    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.