Как новичок очень сложно узнать 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);
но hr я получаю E_POINTER
. Почему это E_POINTER
?
"Garbage In, Garbage Out", вы передаете случайный указатель на функцию, вы ошибаетесь внутри, так что ожидайте странных вещей.
Неправильные вещи:
STDMETHODIMP CCollectionBase::put_InputCollectionInterface(
IUnknown *InputTagInterface)
{
ICollection* inputCollectionInterface;
// 1. You are calling QueryInterface() on the wrong object,
// most likely you were going to query the interface of
// interest of the argument pointer
if (!InputTagInterface) return E_NOINTERFACE;
HRESULT hr = InputTagInterface->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;
// 2. You need to initialize the value here to make sure you are passing
// valid non-NULL argument below
hr = InternalCollection->put_InputCollectionInterface(inputTagInterface);
Поскольку ваш E_POINTER
исходит из CCollectionBase::QueryInterface
, я полагаю, у вас есть другие проблемы в коде, который вы не указали.