COM functions don't return HRESULT values?
Following is a method to init TV capture device. but I don't know what has caused a very strange thing. Anywhere an HRESULT return value is expected, I cannot see a value.
I debug it in Visual studio and set breakpoint, and I cannot see any value for hr.
see note in the code,
FAILED(hr) is true and it comes to "return hr;" but it doesn't really return, it goes on to the following code.
What's the possible cause?
HRESULT TVControl::InitDevice()
{
ICreateDevEnum *pDevEnum = NULL;
IEnumMoniker *pEnum = NULL;
// Create the System Device Enumerator.
HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
reinterpret_cast<void**>(&pDevEnum));
if(FAILED(hr))//note
{
return hr;
}
// Create an enumerator for the video capture category.
hr = pDevEnum->CreateClassEnumerator(
CLSID_VideoInputDeviceCategory,
&pEnum, 0);
if(NULL == pEnum || FAILED(hr))
{
SAFE_RELEASE(pDevEnum);
return hr;
}
IMoniker *pMoniker = NULL;
while (pEnum->Next(1, &pMoniker, NULL) == S_OK)
{
hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&m_pCap);
if(FAILED(hr))
{
pMoniker->Release();
continue;
}
hr = m_pGraph->AddFilter(m_pCap, L"Capture Filter");
if(FAILED(hr))
{
SAFE_RELEASE(pMoniker);
SAFE_RELEASE(m_pCap);
continue;
}
SAFE_RELEASE(pMoniker);
SAFE_RELEASE(pDevEnum);
SAFE_RELEASE(pEnum);
return hr;
}
SAFE_RELEASE(pMoniker);
SAFE_RELEASE(pDevEnum);
SAFE_RELEASE(pEnum);
return -1;
}

