From 5c63222dce051bd4a2e79e736887d15ef9d3d377 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Sun, 25 Apr 2021 22:19:27 -0400 Subject: ignore GetRawInputDeviceInfo errors --- common/utility-rawinput.hpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'common/utility-rawinput.hpp') diff --git a/common/utility-rawinput.hpp b/common/utility-rawinput.hpp index 26e558f..1167891 100644 --- a/common/utility-rawinput.hpp +++ b/common/utility-rawinput.hpp @@ -57,17 +57,24 @@ void rawinput_foreach_with_interface(Func fn, DWORD input_type = RIM_TYPEMOUSE) throw std::system_error(GetLastError(), std::system_category(), "GetRawInputDeviceList failed"); } + std::wstring name; + UINT len; + for (auto&& dev : devs) { if (dev.dwType != input_type) continue; - WCHAR name[256] = {}; - UINT len = 256; + // get required length + if (GetRawInputDeviceInfoW(dev.hDevice, RIDI_DEVICENAME, NULL, &len) == RI_ERROR) { + continue; + } + + name.resize(len); - if (GetRawInputDeviceInfoW(dev.hDevice, RIDI_DEVICENAME, name, &len) == RI_ERROR) { - throw std::system_error(GetLastError(), std::system_category(), "GetRawInputDeviceInfoW failed"); + if (GetRawInputDeviceInfoW(dev.hDevice, RIDI_DEVICENAME, &name[0], &len) == RI_ERROR) { + continue; } - fn(dev, name); + fn(dev, &name[0]); } } -- cgit v1.2.3