Last active
August 29, 2015 14:00
-
-
Save bugparty/11117863 to your computer and use it in GitHub Desktop.
A working example of DirectShow Listing Video Input Devices
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 <stdio.h> | |
#include <dshow.h> | |
#pragma comment(lib, "strmiids") | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
ICreateDevEnum *pSysDevEnum = NULL; | |
HRESULT hr = CoInitialize(NULL); | |
hr = CoCreateInstance(CLSID_SystemDeviceEnum,NULL, CLSCTX_INPROC_SERVER, | |
IID_ICreateDevEnum, (void **)&pSysDevEnum); | |
if(FAILED(hr)){ | |
wprintf(L"failed to init CoCreateInstance\n"); | |
//getchar(); | |
return hr; | |
} | |
IEnumMoniker * pEnumCat = NULL; | |
//Obtain a class enumerator for the video input category. | |
hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, | |
&pEnumCat, 0); | |
if( hr == S_OK){ | |
//Enumerate the moniker | |
IMoniker *pMoniker = NULL; | |
ULONG cFetched; | |
while(pEnumCat->Next(1,&pMoniker,&cFetched) == S_OK){ | |
IPropertyBag *pPropBag; | |
hr = pMoniker->BindToStorage(0,0, IID_IPropertyBag, | |
(void**)&pPropBag); | |
if(SUCCEEDED(hr)) | |
{ | |
//Retrieve the filter`s friendly name. | |
VARIANT varName,varDesc,varPath; | |
VariantInit(&varName); | |
VariantInit(&varDesc); | |
VariantInit(&varPath); | |
hr = pPropBag->Read(L"FriendlyName", &varName, 0); | |
if(SUCCEEDED(hr)){ | |
wprintf(L"the dev name is:\t%s\n", | |
varName.bstrVal); | |
} | |
hr = pPropBag->Read(L"Description", &varDesc, 0); | |
if(SUCCEEDED(hr)){ | |
wprintf(L"the dev desc is:\t%s\n", | |
varDesc.bstrVal); | |
} | |
hr = pPropBag->Read(L"DevicePath", &varPath, 0); | |
if(SUCCEEDED(hr)){ | |
wprintf(L"the dev path is:\t%s\n", | |
varPath.bstrVal); | |
} | |
VariantClear(&varName); | |
VariantClear(&varDesc); | |
VariantClear(&varPath); | |
} | |
pPropBag->Release(); | |
} | |
pEnumCat->Release(); | |
} | |
pSysDevEnum->Release(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment