标签:style io os ar for sp cti on c
}
HRESULT FindCaptureDevice(IBaseFilter ** ppSrcFilter)
{
HRESULT hr;
IBaseFilter * pSrc = NULL;
IMoniker *pMoniker;
ULONG cFetched;
if (!ppSrcFilter)
return E_POINTER;
// Create the system device enumerator
CComPtr <ICreateDevEnum> pDevEnum =NULL;
hr = CoCreateInstance (CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
IID_ICreateDevEnum, (void **) &pDevEnum);
if (FAILED(hr))
{
// Msg(TEXT("Couldn‘t create system enumerator! hr=0x%x"), hr);
return hr;
}
// Create an enumerator for the video capture devices
// CComPtr <IEnumMoniker> pClassEnum = NULL;
IEnumMoniker *pClassEnum=0;
hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &pClassEnum, 0);
if (FAILED(hr))
{
// Msg(TEXT("Couldn‘t create class enumerator! hr=0x%x"), hr);
return hr;
}
// If there are no enumerators for the requested type, then
// CreateClassEnumerator will succeed, but pClassEnum will be NULL.
if (pClassEnum == NULL)
{
MessageBox(ghApp,TEXT("No video capture device was detected.\r\n\r\n")
TEXT("This sample requires a video capture device, such as a USB WebCam,\r\n")
TEXT("to be installed and working properly. The sample will now close."),
TEXT("No Video Capture Hardware"), MB_OK | MB_ICONINFORMATION);
return E_FAIL;
}
// Use the first video capture device on the device list.
// Note that if the Next() call succeeds but there are no monikers,
// it will return S_FALSE (which is not a failure). Therefore, we
// check that the return code is S_OK instead of using SUCCEEDED() macro.
/*if (S_OK == (pClassEnum->Next (1, &pMoniker, &cFetched)))
{
// Bind Moniker to a filter object
hr = pMoniker->BindToObject(0,0,IID_IBaseFilter, (void**)&pSrc);
if (FAILED(hr))
{
// Msg(TEXT("Couldn‘t bind moniker to filter object! hr=0x%x"), hr);
return hr;
}
}
else
{
// Msg(TEXT("Unable to access video capture device!"));
return E_FAIL;
}*/
while(S_OK == (pClassEnum->Next (1, &pMoniker, &cFetched)))
{
IPropertyBag *pProp= 0;
pMoniker->BindToStorage(0,0,IID_IPropertyBag,(void**)&pProp);
VARIANT varName;
varName.vt = VT_BSTR;
hr=pProp->Read(L"FriendlyName",&varName,0);
if(hr == NOERROR)
{
CString str(varName.bstrVal);
if (str.Find("Virtual Camera",0)!=-1)
{
hr = pMoniker->BindToObject(0,0,IID_IBaseFilter, (void**)&pSrc);
if (FAILED(hr))
{
// Msg(TEXT("Couldn‘t bind moniker to filter object! hr=0x%x"), hr);
break;
}
break;
}
}
pMoniker->Release();
}
// Copy the found filter pointer to the output parameter.
// Do NOT Release() the reference, since it will still be used
// by the calling function.
*ppSrcFilter = pSrc;
return hr;
}
标签:style io os ar for sp cti on c
原文地址:http://blog.csdn.net/mao0514/article/details/39429125