Retrieving the Filter
Top  Previous  Next

To instantiate ActiveGeni Video Capture Filter, you need to enumerate all video capture filters using the system device enumerator and match the filter name with "GenTL compliant camera":


IBaseFilter* pFilter;
HRESULT hr;

//locate the camera filter using system device enumerator

CComPtr< ICreateDevEnum > pCreateDevEnum;
pCreateDevEnum.CoCreateInstance( CLSID_SystemDeviceEnum );
if( !pCreateDevEnum )
return E_FAIL;
// enumerate video capture devices
CComPtr< IEnumMoniker > pEm;
pCreateDevEnum->CreateClassEnumerator( CLSID_VideoInputDeviceCategory, &pEm, 0 );
if( !pEm )
return E_FAIL;

pCreateDevEnum.Release();
pEm->Reset();
int noCapDevice=0;

while(true)
{
ULONG ulFetched = 0;
CComPtr< IMoniker > pM;
hr = pEm->Next( 1, &pM, &ulFetched );
if( hr != S_OK )
break;
//get the property bag interface from the moniker
CComPtr< IPropertyBag >pBag;
hr = pM->BindToStorage( 0, 0, IID_IPropertyBag, (void**)&pBag );
if( hr != S_OK )
{
pBag.Release();
continue;
}

//retrieve the name of the device
CComVariant var;
var.vt = VT_BSTR;
hr = pBag->Read(L"FriendlyName", &var, NULL );
if( hr != S_OK )
{
SysFreeString(var.bstrVal);
pBag.Release();
continue;
}

//is this ActiveGeni filter?
if( !memcmp( W2CA(var.bstrVal), "GenTL compliant camera", 26 ) )
{
hr = pM->BindToObject( 0, 0, IID_IBaseFilter, (void**)pFilter );
}
noCapDevice++;
pM.Release();
pBag.Release();
SysFreeString( var.bstrVal );
}
pEm.Release();