Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ CoCreateInstance返回E_INVALIDARG_C++_Com_Afx - Fatal编程技术网

C++ CoCreateInstance返回E_INVALIDARG

C++ CoCreateInstance返回E_INVALIDARG,c++,com,afx,C++,Com,Afx,我在这里试图做的只是创建一个接口的实例。真的应该是这么简单。我一直在关注任何在线材料,阅读我能找到但却无法解决这个问题的材料 它归结为从作为E_INVALIDARG的CoCreateInstance返回的HRESULT。我已经尽我所能改变了参数,试图让它工作,但仍然无法得到它。所以,请看一眼,希望有人能指出一些简单的东西,我看过头了 //Instantiate the sink class and hold a pointer to it. m_pSink = new CSink();

我在这里试图做的只是创建一个接口的实例。真的应该是这么简单。我一直在关注任何在线材料,阅读我能找到但却无法解决这个问题的材料

它归结为从作为E_INVALIDARG的CoCreateInstance返回的HRESULT。我已经尽我所能改变了参数,试图让它工作,但仍然无法得到它。所以,请看一眼,希望有人能指出一些简单的东西,我看过头了

//Instantiate the sink class and hold a pointer to it.
    m_pSink = new CSink();

    HRESULT hr = CoInitialize(NULL);

    //Get a pointer to sinks IUnknown, no AddRef. CMySink implements only
    //dispinterface and the IUnknown and IDispatch pointers will be same.
    LPUNKNOWN pUnkSink = m_pSink->GetIDispatch(FALSE); 

    CLSID clsidInterface;
    hr = CLSIDFromProgID(L"Automation.AutomationInterface", &clsidInterface);

    ICALib::IAutomationInterface *p_Interface = NULL;
    hr = CoCreateInstance(clsidInterface, NULL, CLSCTX_LOCAL_SERVER, ICALib::IID_IAutomationInterface, (void**)p_Interface);

    if (hr != S_OK) // Show a message box if the Instance of the interface is not created and do not create the object.
    {
        CMessageBox(CMessageBox::WARNING_OK).Show(IDS_WARNING_BADLICENSE);
        m_failedToCreate = TRUE;
        this->~CMainClass();
        return;
    }

    //Establish a connection between source and sink.
    //m_pUnkSrc is IUnknown of server obtained by CoCreateInstance().
    //m_dwCookie is a cookie identifying the connection, and is needed to terminate the connection.
    BOOL result = AfxConnectionAdvise(p_Interface, m_pSink->GetGUID(), pUnkSink, FALSE, &m_dwCookie);

(由于法律责任,此代码中未显示实际姓名)

您需要获取
p\u接口的地址
并将其传递给
CoCreateInstance
。天哪,你只是传递了一个空指针来表示最后一个参数。

神圣垃圾,我不敢相信我已经错过了,非常感谢:DTo避免这种错误,考虑使用McRooT,但是<代码> ->~CuCurCube();代码>相当可疑