| 26 | } |
| 27 | |
| 28 | std::vector<DeviceInfo> DeviceManager::EnumDevices() { |
| 29 | std::vector<DeviceInfo> devices; |
| 30 | SP_DEVINFO_DATA data = { sizeof(data) }; |
| 31 | wchar_t name[512]; |
| 32 | |
| 33 | for (DWORD i = 0;; i++) { |
| 34 | if (!::SetupDiEnumDeviceInfo(_hInfoSet.get(), i, &data)) |
| 35 | break; |
| 36 | |
| 37 | DeviceInfo di; |
| 38 | di.Data = data; |
| 39 | if (::SetupDiGetDeviceRegistryProperty(_hInfoSet.get(), &data, SPDRP_FRIENDLYNAME, nullptr, |
| 40 | (BYTE*)name, sizeof(name), nullptr)) { |
| 41 | di.Description = name; |
| 42 | } |
| 43 | if (di.Description.empty()) { |
| 44 | if (::SetupDiGetDeviceRegistryProperty(_hInfoSet.get(), &data, SPDRP_DEVICEDESC, nullptr, |
| 45 | (BYTE*)name, sizeof(name), nullptr)) { |
| 46 | di.Description = name; |
| 47 | } |
| 48 | } |
| 49 | devices.push_back(std::move(di)); // �����ַ��� |
| 50 | } |
| 51 | return devices; |
| 52 | } |
| 53 | |
| 54 | std::wstring WinSys::DeviceManager::GetDeviceClassDescription(const GUID* guid, const wchar_t* computerName /* = nullptr */) { |
| 55 | wchar_t desc[256]; |