1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- // 这段 MFC 示例源代码演示如何使用 MFC Microsoft Office Fluent 用户界面
- // ("Fluent UI"),该示例仅作为参考资料提供,
- // 用以补充《Microsoft 基础类参考》和
- // MFC C++ 库软件随附的相关电子文档。
- // 复制、使用或分发 Fluent UI 的许可条款是单独提供的。
- // 若要了解有关 Fluent UI 许可计划的详细信息,请访问
- // http://msdn.microsoft.com/officeui。
- //
- // 版权所有 (C) Microsoft Corporation
- // 保留所有权利。
- // stdafx.cpp : 只包括标准包含文件的源文件
- // FieldTestTool.pch 将作为预编译头
- // stdafx.obj 将包含预编译类型信息
- #include "stdafx.h"
- int EnumDevices(std::vector<TString> &vtDevices)
- {
- ICreateDevEnum *pDevEnum = NULL;
- IEnumMoniker *pEnum = NULL;
- HRESULT hr = NULL;
- CoInitialize(NULL);
- hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, reinterpret_cast<void**>(&pDevEnum));
- if (SUCCEEDED(hr))
- {
- hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,&pEnum,0);
- if (hr == S_OK)
- {
- //枚举捕获设备
- IMoniker *pMoniker = NULL;
- ULONG cFetched;
- while (pEnum->Next(1, &pMoniker, &cFetched) == S_OK)
- {
- IPropertyBag* pPropBag;
- hr = pMoniker->BindToStorage(0,0,IID_IPropertyBag,reinterpret_cast<void**>(&pPropBag));
- if (SUCCEEDED(hr))
- {
- //获取 vid 和 pid
- BSTR devicePath = NULL;
- hr = pMoniker->GetDisplayName(NULL, NULL, &devicePath);
- if (!SUCCEEDED(hr))
- {
- pMoniker->Release();
- continue;
- }
- wchar_t* lpszDevicePath = _bstr_t(devicePath);
- //获取设备名称
- VARIANT varName;
- varName.vt = VT_BSTR;
- VariantInit(&varName);
- hr = pPropBag->Read(L"FriendlyName", &varName, 0);
- if (SUCCEEDED(hr))
- {
- TCHAR str[2048];
- WideCharToMultiByte(CP_ACP,0,varName.bstrVal, -1, str, 2048, NULL, NULL);
- OutputDebugString(_T("新增设备:"));
- OutputDebugString(str);
- OutputDebugString(_T("\n"));
- vtDevices.push_back(str);
- SysFreeString(varName.bstrVal);
- }
- pPropBag->Release();
- }
- pMoniker->Release();
- }
- }
- }
- CoUninitialize();
- return 0;
- }
|