CoCreateInstance Returning E_INVALIDARG
CoCreateInstance Returning E_INVALIDARG
我在这里尝试做的只是创建一个接口的实例。真的应该这么简单。一直在关注任何在线材料,阅读我能找到的材料,但我一生都无法解决这个问题。
归根结底,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指针。
相关文章:
- ZLib GZIP Returning Z_BUF_ERROR(-5)
- C++:寻找"returning address of local variable..."的更正
- cin.fail() not returning true
- "Warning : No return statement in function returning non-void"是什么意思?
- std::localtime returning null
- 为什么我收到以下错误:"returning reference to temporary [-Werror=return-local-addr]"
- GetComboBoxInfo returning false
- Returning std::vector with std::move
- 如何修复空虚拟方法的"warning: no return statement in function returning non-void [-Wreturn-type]"
- Returning std::make_pair with std::forward
- GetThreadContext() returning 87
- 为什么不触发"returning reference to temporary object"编译器警告?
- MoveFileEx - returning GetLastError(): 17
- 为什么 decltype 在 "auto returning" 函数中是必需的?
- Self-returning class?
- Qt findChild returning 0
- SDL_LoadBMP only returning NULL
- C++11 lambda returning lambda
- cvLoadImage Returning NULL
- xrces item returning NULL