IltmmVideoFormats::get_Count Example for C++
HRESULT hr;
long lIndex, lCount, lSelection, lWidth, lHeight, lCompression, lBitCount;
VARIANT_BOOL vSelected;
BSTR SubTypeName, SubTypeFriendlyName, Subtype;
IltmmVideoFormats* pVidCapFormats = NULL;
IltmmVideoFormat* pVidFormat = NULL;
hr = m_capture->get_VideoCaptureFormats(&pVidCapFormats);
if (FAILED(hr))
return hr;
hr = pVidCapFormats->get_Count (&lCount);
if (FAILED(hr))
{
pVidCapFormats->Release();
pVidCapFormats = NULL;
return hr;
}
hr = pVidCapFormats->get_Selection (&lSelection);
if (FAILED(hr))
{
pVidCapFormats->Release();
pVidCapFormats = NULL;
return hr;
}
if (lSelection != 0)
{
hr = pVidCapFormats->put_Selection (0);
if (FAILED(hr))
{
pVidCapFormats->Release();
pVidCapFormats = NULL;
return hr;
}
}
hr = pVidCapFormats->Item (0, &pVidFormat);
if (FAILED(hr))
{
pVidCapFormats->Release();
pVidCapFormats = NULL;
return hr;
}
hr = pVidFormat->get_Selected (&vSelected);
if (FAILED(hr))
{
pVidFormat->Release();
pVidFormat = NULL;
pVidCapFormats->Release();
pVidCapFormats = NULL;
return hr;
}
if (vSelected == VARIANT_FALSE)
{
hr = pVidFormat->put_Selected (VARIANT_TRUE);
if (FAILED(hr))
{
pVidFormat->Release();
pVidFormat = NULL;
pVidCapFormats->Release();
pVidCapFormats = NULL;
return hr;
}
}
hr = pVidFormat->get_SubTypeName (&SubTypeName);
SysFreeString(SubTypeName);
if (FAILED(hr))
{
pVidFormat->Release();
pVidFormat = NULL;
pVidCapFormats->Release();
pVidCapFormats = NULL;
return hr;
}
hr = pVidFormat->get_SubTypeFriendlyName (&SubTypeFriendlyName);
SysFreeString(SubTypeFriendlyName);
if (FAILED(hr))
{
pVidFormat->Release();
pVidFormat = NULL;
pVidCapFormats->Release();
pVidCapFormats = NULL;
return hr;
}
hr = pVidFormat->get_Width (&lWidth);
if (FAILED(hr))
{
pVidFormat->Release();
pVidFormat = NULL;
pVidCapFormats->Release();
pVidCapFormats = NULL;
return hr;
}
hr = pVidFormat->get_Height (&lHeight);
if (FAILED(hr))
{
pVidFormat->Release();
pVidFormat = NULL;
pVidCapFormats->Release();
pVidCapFormats = NULL;
return hr;
}
hr = pVidFormat->get_Compression (&lCompression);
if (FAILED(hr))
{
pVidFormat->Release();
pVidFormat = NULL;
pVidCapFormats->Release();
pVidCapFormats = NULL;
return hr;
}
hr = pVidFormat->get_BitCount (&lBitCount);
if (FAILED(hr))
{
pVidFormat->Release();
pVidFormat = NULL;
pVidCapFormats->Release();
pVidCapFormats = NULL;
return hr;
}
Subtype = SysAllocString(ltmmMEDIASUBTYPE_RGB24);
hr = pVidCapFormats->Find (Subtype, 1024, 768, &lIndex);
SysFreeString(Subtype);
if (FAILED(hr))
{
pVidFormat->Release();
pVidFormat = NULL;
pVidCapFormats->Release();
pVidCapFormats = NULL;
return hr;
}
pVidFormat->Release();
pVidFormat = NULL;
pVidCapFormats->Release();
pVidCapFormats = NULL;