Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.62 KB | None | 0 0
  1. #include <windows.h>
  2. #include <dshow.h>
  3.  
  4. #pragma comment(lib, "strmiids")
  5.  
  6. HRESULT EnumerateDevices(REFGUID category, IEnumMoniker **ppEnum)
  7. {
  8.     // Create the System Device Enumerator.
  9.     ICreateDevEnum *pDevEnum;
  10.     HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
  11.         CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDevEnum));
  12.  
  13.     if (SUCCEEDED(hr))
  14.     {
  15.         // Create an enumerator for the category.
  16.         hr = pDevEnum->CreateClassEnumerator(category, ppEnum, 0);
  17.         if (hr == S_FALSE)
  18.         {
  19.             hr = VFW_E_NOT_FOUND;  // The category is empty. Treat as an error.
  20.         }
  21.         pDevEnum->Release();
  22.     }
  23.     return hr;
  24. }
  25.  
  26.  
  27. void DisplayDeviceInformation(IEnumMoniker *pEnum)
  28. {
  29.     IMoniker *pMoniker = NULL;
  30.  
  31.     while (pEnum->Next(1, &pMoniker, NULL) == S_OK)
  32.     {
  33.         IPropertyBag *pPropBag;
  34.         HRESULT hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
  35.         if (FAILED(hr))
  36.         {
  37.             pMoniker->Release();
  38.             continue;
  39.         }
  40.  
  41.         VARIANT var;
  42.         VariantInit(&var);
  43.  
  44.         // Get description or friendly name.
  45.         hr = pPropBag->Read(L"Description", &var, 0);
  46.         if (FAILED(hr))
  47.         {
  48.             hr = pPropBag->Read(L"FriendlyName", &var, 0);
  49.         }
  50.         if (SUCCEEDED(hr))
  51.         {
  52.             printf("%S\n", var.bstrVal);
  53.             VariantClear(&var);
  54.         }
  55.  
  56.         hr = pPropBag->Write(L"FriendlyName", &var);
  57.  
  58.         // WaveInID applies only to audio capture devices.
  59.         hr = pPropBag->Read(L"WaveInID", &var, 0);
  60.         if (SUCCEEDED(hr))
  61.         {
  62.             printf("WaveIn ID: %d\n", var.lVal);
  63.             VariantClear(&var);
  64.         }
  65.  
  66.         hr = pPropBag->Read(L"DevicePath", &var, 0);
  67.         if (SUCCEEDED(hr))
  68.         {
  69.             // The device path is not intended for display.
  70.             printf("Device path: %S\n", var.bstrVal);
  71.             VariantClear(&var);
  72.         }
  73.  
  74.         pPropBag->Release();
  75.         pMoniker->Release();
  76.     }
  77. }
  78.  
  79. void main()
  80. {
  81.     HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  82.     if (SUCCEEDED(hr))
  83.     {
  84.         IEnumMoniker *pEnum;
  85.  
  86.         hr = EnumerateDevices(CLSID_VideoInputDeviceCategory, &pEnum);
  87.         if (SUCCEEDED(hr))
  88.         {
  89.             DisplayDeviceInformation(pEnum);
  90.             pEnum->Release();
  91.         }
  92.         hr = EnumerateDevices(CLSID_AudioInputDeviceCategory, &pEnum);
  93.         if (SUCCEEDED(hr))
  94.         {
  95.             DisplayDeviceInformation(pEnum);
  96.             pEnum->Release();
  97.         }
  98.         CoUninitialize();
  99.     }
  100. }
  101. //gcc dev.c -lole32 -loleaut32
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement