DirectShow console output and save video device name

Source: Internet
Author: User

Tag:directshow   c++    console     camera    

#include "windows.h" #include "TCHAR.h" #include <dshow.h> #include <vector> #include <iostream># Include <cwctype> #define MAX_FRIENDLY_NAME_LENGTH #define MAX_MONIKER_NAME_LENGTH 256typedef struct _TDE   Vicename{wchar Friendlyname[max_friendly_name_length];     Device friendly name WCHAR monikername[max_moniker_name_length]; Device moniker name} tdevicename;int _tmain (int argc, _tchar* argv[]) {tdevicename name; HRESULT hr;//Initialize std::vector<tdevicename> vectordevices;vectordevices.clear ();//Initialize com hr = CoInitializeEx ( NULL, coinit_apartmentthreaded), if (FAILED (HR)) {return hr;} Create a System device Enumerator instance icreatedevenum *psysdevenum = Null;hr = CoCreateInstance (Clsid_systemdeviceenum, NULL, CLSCTX_INPROC_ SERVER, Iid_icreatedevenum, (void * *) &psysdevenum), if (FAILED (HR)) {couninitialize (); return HR;} Get device class Enumerator ienummoniker *penumcat = Null;hr = Psysdevenum->createclassenumerator (clsid_videoinputdevicecategory, & Amp;penumcat, 0); if (hr = = S_OK) {//Enumerate device names IMoniker *pmOniker = NULL; ULONG Cfetched;while (Penumcat->next (1, &pmoniker, &cfetched) = = S_OK) {IPropertyBag *ppropbag;hr = pMoniker- >bindtostorage (null, NULL, Iid_ipropertybag, (void *) &ppropbag), if (SUCCEEDED (HR)) {//Get device friendly name VARIANT varName; VariantInit (&varname); hr = Ppropbag->read (L "FriendlyName", &varname, NULL); if (SUCCEEDED (HR)) { StringCchCopy (name. FriendlyName, Max_friendly_name_length, varname.bstrval); Std::wcout << NAME. FriendlyName << std::endl;//get device moniker name Lpolestr poledisplayname = reinterpret_cast<lpolestr> ( CoTaskMemAlloc (Max_moniker_name_length * 2)); if (poledisplayname! = null) {hr = Pmoniker->getdisplayname (null, NULL, &poledisplayname), if (SUCCEEDED (HR)) {stringcchcopy (name). Monikername, Max_moniker_name_length, poledisplayname); Vectordevices.push_back (NAME);} CoTaskMemFree (Poledisplayname);}} VariantClear (&varname);pP ropbag->release ();} Pmoniker->release ();} End for while Penumcat->release ();} Psysdevenum->rElease (); CoUninitialize ();}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

DirectShow console output and save video device name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.