EnumDevice.cpp
资源名称:PCBMatch.rar [点击查看]
上传用户:bxq2008bxq
上传日期:2022-07-18
资源大小:6138k
文件大小:2k
源码类别:
DirextX编程
开发平台:
Visual C++
- #include "StdAfx.h"
- #include "EnumDevice.h"
- CDeviceName::CDeviceName(void)
- :m_FriendName(_T(""))
- {
- }
- CDeviceName::~CDeviceName(void)
- {
- }
- CEnumDevice::CEnumDevice(void)
- {
- }
- CEnumDevice::~CEnumDevice(void)
- {
- }
- HRESULT CEnumDevice::EnumDevice(void)
- {
- ICreateDevEnum *pDevEnum = NULL;
- IEnumMoniker *pEnum = NULL;
- IMoniker *pMoniker = NULL;
- // Create the System Device Enumerator.
- HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
- CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
- reinterpret_cast<void**>(&pDevEnum));
- if (SUCCEEDED(hr))
- {
- // Create an enumerator for the video capture category.
- hr = pDevEnum->CreateClassEnumerator(
- CLSID_VideoInputDeviceCategory,
- &pEnum, 0);
- }
- if(SUCCEEDED(hr) && hr==S_OK)
- {
- //HWND hList; // Handle to the list box.
- while (pEnum->Next(1, &pMoniker, NULL) == S_OK)
- {
- IBaseFilter *pCap = NULL;
- 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"FriendlyName", &varName, 0);
- if (FAILED(hr))
- {
- hr = pPropBag->Read(L"Description", &varName, 0);
- }
- if (SUCCEEDED(hr))
- {
- // Add it
- hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&pCap);
- if (SUCCEEDED(hr))
- {
- CDeviceName *DeviceName = new CDeviceName();
- USES_CONVERSION;
- CString str(OLE2T(varName.bstrVal));
- DeviceName->m_FriendName = str;
- DeviceName->pSrc = pCap;
- outlist.Add(DeviceName);
- }
- VariantClear(&varName);
- }
- pPropBag->Release();
- pMoniker->Release();
- }
- pEnum->Release();
- pDevEnum->Release();
- }
- return hr;
- }
- IBaseFilter* CEnumDevice::GetCaptureDevice(int index)
- {
- IBaseFilter * tempCap = NULL;
- INT_PTR count = outlist.GetCount();
- if(index >= 0 && index <= count-1)
- {
- tempCap = outlist[index]->pSrc;
- for(int i=0;i<count;i++)
- {
- if( i != index)
- {
- outlist[i]->pSrc->Release();
- }
- delete outlist[i];
- }
- return tempCap;
- }
- else
- {
- return tempCap;
- }
- }