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;

}

[1839 byte] By [Chongkai] at [2007-12-23]
# 1

Are you doing a debug build or a release build? In a release build, it probably optimizes hr away.

LGS at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 2

Thanks. you are right. I'm doing a release build. After I disable optimization, it's ok now.

Thanks again.

Chongkai at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 3
I don't have this problem and I don't use the FAILED macro.
DouglasJordan at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 4

so what method do you use?

If HRESULT value is removed by optimization, code relying on SUCCEEDED or FAILED macros will fail, so will forms such as (hr == S_OK)

Chongkai at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...
# 5

Just because the optimized code doesn't create a variable on the stack to hold hr, that doesn't mean it isn't processing it correctly.

If you are concerned, you can always review the assember code.

LGS at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,DirectShow Development...

Software Development for Windows Vista

Site Classified