HRESULT CVideoSource::EnumVideoDevices()
{
// Create the System Device Enumerator.
HRESULT hr = CoCreateInstance( CLSID_SystemDeviceEnum,
NULL,
CLSCTX_INPROC_SERVER,
IID_ICreateDevEnum,
reinterpret_cast<void**>(&m_pDevEnum)
);
if (FAILED(hr))
{
return hr;
}
// Create an enumerator for the video capture category.
hr = m_pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,&m_pEnumMoniker, 0);
//if (!SUCCEEDED(hr)||pEnum)
if (hr == S_FALSE)
{
//there is not video device
return hr;
}
//先传递清除原有的视频信息
USES_CONVERSION;
SendMessage(AfxGetMainWnd()->m_hWnd, LB_DELETESTRING, 0, (LPARAM)OLE2T(L"release-video"));
int iVideoCardID = 0;
IMoniker *pMoniker = NULL;
while (m_pEnumMoniker->Next(1, &pMoniker, NULL) == S_OK)
{
IPropertyBag *pPropBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void**)(&pPropBag));
if (FAILED(hr))
{
pMoniker->Release();
continue; // Skip this one, maybe the next one will work.
}
// Find the description or friendly name.
VARIANT varName;
VariantInit(&varName);
//hr = pPropBag->Read(L"Description", &varName, 0);
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
if (FAILED(hr))
{
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
}
if (SUCCEEDED(hr))
{
// Add it to the application's list box.
//SendMessage(hTrackbar, TBM_SETPOS, TRUE, Val);
USES_CONVERSION;
//char chCardID[100];
//sprintf(chCardID,"%d:%s",iVideoCardID++,varName.bstrVal);
//(long)SendMessage(AfxGetMainWnd()->m_hWnd, TBM_SETPOS, 0, (LPARAM)OLE2T(T2W(chCardID)));
//(long)SendMessage(AfxGetMainWnd()->m_hWnd, TBM_SETRANGE, 0, (LPARAM)OLE2T(varName.bstrVal));
//SendMessage(AfxGetMainWnd()->m_hWnd, WM_FGNOTIFY, 0, (LPARAM)OLE2T(varName.bstrVal));
SendMessage(AfxGetMainWnd()->m_hWnd, LB_ADDSTRING, 0, (LPARAM)OLE2T(varName.bstrVal));
//dlgConfigVideo.AddVideoSrc(iVideoCardID++,(TCHAR*)varName.bstrVal);
//m_listDev.AddTail((TCHAR*)varName.bstrVal);
//m_listDev.Append(iVideoCardID++,(TCHAR*)varName.bstrVal);
VariantClear(&varName);
}
pPropBag->Release();
pMoniker->Release();
}
return hr;
}