Listing video input device names
This page shows you how to get names of video camera (desktop camera, DV camera, etc) and TV tuner device. Please note that error handling codes are omitted to keep the sample code simple.
Sample code
The following sample code will display FriendlyName of each video input device. For example, if the first detected video capture device is a DV camera, this sample will display a MessageBox with the message, "Microsoft DV Camera and VCR".
#include <stdio.h>
#include <dshow.h>
int
main()
{
ICreateDevEnum *pCreateDevEnum = NULL;
IEnumMoniker *pEnumMoniker = NULL;
IMoniker *pMoniker = NULL;
ULONG nFetched = 0;
// Initialize COM
CoInitialize(NULL);
// Create CreateDevEnum to list device
CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
IID_ICreateDevEnum, (PVOID *)&pCreateDevEnum);
// Create EnumMoniker to list VideoInputDevice
pCreateDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
&pEnumMoniker, 0);
if (pEnumMoniker == NULL) {
// this will be shown if there is no capture device
printf("no device\n");
return 0;
}
// reset EnumMoniker
pEnumMoniker->Reset();
// get each Moniker
while (pEnumMoniker->Next(1, &pMoniker, &nFetched) == S_OK) {
// get the device friendly name:
IPropertyBag *pPropertyBag;
TCHAR devname[128];
// bind to IPropertyBag
pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
(void **)&pPropertyBag);
// container for Friendly name
VARIANT varFriendlyName;
varFriendlyName.vt = VT_BSTR;
// get FriendlyName
pPropertyBag->Read(L"FriendlyName", &varFriendlyName, 0);
// copy FriendlyName
#ifdef UNICODE
// for UNICODE
_tcscpy(devname, varFriendlyName.bstrVal);
#else
// not UNICODE
WideCharToMultiByte(CP_ACP, 0,
varFriendlyName.bstrVal, -1, devname, sizeof(devname), 0, 0);
#endif
// display result
MessageBox(NULL, devname, "DEVICE NAME", MB_OK);
// release
VariantClear(&varFriendlyName);
// release
pMoniker->Release();
pPropertyBag->Release();
}
// release
pEnumMoniker->Release();
pCreateDevEnum->Release();
// finish COM
CoUninitialize();
return 0;
}
This sample only shows the FriendlyName. This can be used to display list of available capture devcies.