gpt4 book ai didi

c++ - CoCreateInstance 返回 E_INVALIDARG

转载 作者:行者123 更新时间:2023-11-30 04:01:32 25 4
gpt4 key购买 nike

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

它归结为从 CoCreateInstance 返回的 HRESULT 是 E_INVALIDARG。我已尽可能多地更改参数以尝试使其正常工作,但仍然无法正常工作。所以请看一眼,希望有人能指出一些我忽略的简单问题。

//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_Interface 的地址并将其传递给 CoCreateInstance。事实上,您只是为最后一个参数传递了一个 NULL 指针。

关于c++ - CoCreateInstance 返回 E_INVALIDARG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25667915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com