Last active
August 29, 2015 14:17
-
-
Save kkm/474c70713ab93e40308e to your computer and use it in GitHub Desktop.
dshow device list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <dshow.h> | |
#pragma comment(lib, "strmiids") | |
HRESULT EnumerateDevices(REFGUID category, IEnumMoniker **ppEnum) | |
{ | |
// Create the System Device Enumerator. | |
ICreateDevEnum *pDevEnum; | |
HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, | |
CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDevEnum)); | |
if (SUCCEEDED(hr)) | |
{ | |
// Create an enumerator for the category. | |
hr = pDevEnum->CreateClassEnumerator(category, ppEnum, 0); | |
if (hr == S_FALSE) | |
{ | |
hr = VFW_E_NOT_FOUND; // The category is empty. Treat as an error. | |
} | |
pDevEnum->Release(); | |
} | |
return hr; | |
} | |
void DisplayDeviceInformation(IEnumMoniker *pEnum) | |
{ | |
IMoniker *pMoniker = NULL; | |
while (pEnum->Next(1, &pMoniker, NULL) == S_OK) | |
{ | |
IPropertyBag *pPropBag; | |
HRESULT hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag)); | |
if (FAILED(hr)) | |
{ | |
pMoniker->Release(); | |
continue; | |
} | |
VARIANT var; | |
VariantInit(&var); | |
// Get description or friendly name. | |
hr = pPropBag->Read(L"Description", &var, 0); | |
if (FAILED(hr)) | |
{ | |
hr = pPropBag->Read(L"FriendlyName", &var, 0); | |
} | |
if (SUCCEEDED(hr)) | |
{ | |
printf("%S\n", var.bstrVal); | |
VariantClear(&var); | |
} | |
hr = pPropBag->Write(L"FriendlyName", &var); | |
// WaveInID applies only to audio capture devices. | |
hr = pPropBag->Read(L"WaveInID", &var, 0); | |
if (SUCCEEDED(hr)) | |
{ | |
printf("WaveIn ID: %d\n", var.lVal); | |
VariantClear(&var); | |
} | |
hr = pPropBag->Read(L"DevicePath", &var, 0); | |
if (SUCCEEDED(hr)) | |
{ | |
// The device path is not intended for display. | |
printf("Device path: %S\n", var.bstrVal); | |
VariantClear(&var); | |
} | |
pPropBag->Release(); | |
pMoniker->Release(); | |
} | |
} | |
void main() | |
{ | |
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); | |
if (SUCCEEDED(hr)) | |
{ | |
IEnumMoniker *pEnum; | |
hr = EnumerateDevices(CLSID_VideoInputDeviceCategory, &pEnum); | |
if (SUCCEEDED(hr)) | |
{ | |
DisplayDeviceInformation(pEnum); | |
pEnum->Release(); | |
} | |
hr = EnumerateDevices(CLSID_AudioInputDeviceCategory, &pEnum); | |
if (SUCCEEDED(hr)) | |
{ | |
DisplayDeviceInformation(pEnum); | |
pEnum->Release(); | |
} | |
CoUninitialize(); | |
} | |
system("pause"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment