【发布时间】:2013-11-07 05:29:38
【问题描述】:
作为新手,学习 COM 概念非常困难。请解释一下以下错误。为什么会发生这种情况,我有带有以下函数体的 com 代码。
STDMETHODIMP CCollectionBase::put_InputCollectionInterface(
IUnknown *InputTagInterface)
{
ICollection* inputCollectionInterface;
HRESULT hr = QueryInterface(__uuidof(ICollection),
(void**)&inputCollectionInterface);
if (FAILED(hr)) return hr;
//m_inputCollectionInterface is global variable of ICollection
m_inputCollectionInterface = inputCollectionInterface;
return S_OK;
}
我正在通过以下方式调用函数。
ITag* inputTagInterface;
//InternalCollection is ICollectionBase object
hr = InternalCollection->put_InputCollectionInterface(inputTagInterface);
但我得到的是E_POINTER。为什么是E_POINTER?
【问题讨论】:
-
你会得到
E_POINTER,因为你很幸运。inputTagInterface是一个未初始化的指针变量。这与 COM 完全无关——这是非常基本的 C++。 COM 返回一个错误代码(如果可以的话)。 C++ 崩溃(除非它不能)。 -
@IInspectable 感谢您的回复您的意思是说我传递的参数没有初始化?
-
@IInspectable 那么如何初始化参数呢?
-
看起来该参数未在 put_InputCollectionInterface 中使用,您是如何获得 InternalCollection 对象的?我怀疑后者是问题,而不是 inputTagInterface