2013-10-07 3 views
0

초보자로서 COM 개념을 배우는 것은 매우 어렵습니다. 다음 오류를 설명해주십시오. 다음과 같은 함수 본문이있는 com 코드가있는 이유는 무엇입니까?COM 함수는 E_POINTER를 반환합니다

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일까요?

+1

운이 좋으면'E_POINTER'가됩니다. 'inputTagInterface'는 초기화되지 않은 포인터 변수입니다. 이것은 COM과 전혀 관련이 없습니다. 이것은 매우 기본적인 C++입니다. COM은 오류 코드를 반환합니다 (가능한 경우). C++이 충돌합니다 (그렇지 않은 경우 제외). – IInspectable

+0

답장을 보내 주셔서 감사합니다 @IInspectable 내가 전달하는 매개 변수가 초기화되지 않는다는 것을 의미합니까? –

+0

@IInspectable 어떻게 매개 변수를 초기화 하시겠습니까? –

답변

1

"Garbage In, Garbage Out", 함수에 임의의 포인터를 전달하면 잘못된 호출이 발생하므로 이상한 일이 다시 발생합니다.

잘못된 일이 있습니다 : 당신의 E_POINTER 이후

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); 

CCollectionBase::QueryInterface 방법에서오고, 난 당신이 인용하지 않은 코드에 다른 문제가 있다고 가정합니다.

관련 문제