diff options
| author | a1xd <[email protected]> | 2021-04-25 22:19:27 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-04-25 22:19:27 -0400 |
| commit | 5c63222dce051bd4a2e79e736887d15ef9d3d377 (patch) | |
| tree | 56c416fc4ca6bb6b7a482fbe179e5865d6e8aeb2 | |
| parent | bugfix - rawinput (diff) | |
| download | rawaccel-5c63222dce051bd4a2e79e736887d15ef9d3d377.tar.xz rawaccel-5c63222dce051bd4a2e79e736887d15ef9d3d377.zip | |
ignore GetRawInputDeviceInfo errors
| -rw-r--r-- | common/utility-rawinput.hpp | 17 |
1 files changed, 12 insertions, 5 deletions
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]); } } |