void DirectShowAudioEndpointControl::updateEndpoints() { IMalloc *oleMalloc = 0; if (m_deviceEnumerator && CoGetMalloc(1, &oleMalloc) == S_OK) { IEnumMoniker *monikers = 0; if (m_deviceEnumerator->CreateClassEnumerator( CLSID_AudioRendererCategory, &monikers, 0) == S_OK) { for (IMoniker *moniker = 0; monikers->Next(1, &moniker, 0) == S_OK; moniker->Release()) { OLECHAR *string = 0; if (moniker->GetDisplayName(m_bindContext, 0, &string) == S_OK) { QString deviceId = QString::fromWCharArray(string); oleMalloc->Free(string); moniker->AddRef(); m_devices.insert(deviceId, moniker); if (m_defaultEndpoint.isEmpty() || deviceId.endsWith(QLatin1String("Default DirectSound Device"))) { m_defaultEndpoint = deviceId; } } } monikers->Release(); } oleMalloc->Release(); } }
int CCaptureVideo::EnumDevices(CArray<CString, CString>& arList) { int nCount = 0; //枚举视频扑捉设备 ICreateDevEnum *pCreateDevEnum; HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,IID_ICreateDevEnum, (void**)&pCreateDevEnum); if (hr != NOERROR)return -1; CComPtr<IEnumMoniker> pEm; hr = pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,&pEm, 0); if (hr != NOERROR)return -1; pEm->Reset(); ULONG cFetched; IMoniker *pM; while(hr = pEm->Next(1, &pM, &cFetched), hr==S_OK) { IPropertyBag *pBag; hr = pM->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag); if(SUCCEEDED(hr)) { VARIANT var; var.vt = VT_BSTR; hr = pBag->Read(L"FriendlyName", &var, NULL); if (hr == NOERROR) { char szStr[2048]; nCount++; WideCharToMultiByte(CP_ACP,0,var.bstrVal, -1, szStr, 2048, NULL, NULL); arList.Add( CString(szStr) ); SysFreeString(var.bstrVal); pM->AddRef(); } pBag->Release(); } pM->Release(); } return nCount; }
HRESULT GetCaptureFilter(REFCLSID CLSID_DeviceCategory, LPCTSTR lpFriendlyName, void** ppCapture) { ICreateDevEnum *pCreateDevEnum = 0; HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum , NULL , CLSCTX_INPROC_SERVER , IID_ICreateDevEnum , (void**)&pCreateDevEnum); if (FAILED(hr)) return hr; IEnumMoniker* pEnumMoniker = 0; hr = pCreateDevEnum->CreateClassEnumerator(CLSID_DeviceCategory, &pEnumMoniker, 0); if (FAILED(hr)) { pCreateDevEnum->Release(); return hr; } pEnumMoniker->Reset(); BOOL bFound = FALSE; IMoniker* pMoniker = NULL; while ((pEnumMoniker->Next(1, &pMoniker, NULL) == S_OK )&& (!bFound)) { IPropertyBag *pBag = NULL; hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag); if (SUCCEEDED(hr)) { VARIANT var = { 0 }; var.vt = VT_BSTR; hr = pBag->Read(_T("FriendlyName"), &var, NULL); if (SUCCEEDED(hr)) { if (!_tcscmp(var.bstrVal, lpFriendlyName)) { hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)ppCapture); pMoniker->AddRef(); bFound = TRUE; } pBag->Release(); } } pMoniker->Release(); }//end while pEnumMoniker->Release(); pCreateDevEnum->Release(); if (*ppCapture == NULL) return E_FAIL; if (FAILED(hr)) return hr; return bFound ? S_OK : S_FALSE; }