From f64c40346dab580220101b0aacb4a6ff5484d86a Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Sat, 30 Jan 2021 01:23:34 -0500 Subject: fix device id not working with g305 this uses w32 apis for enumerating dev info instead of ManagementObjectSearcher, which upper-cases dev ids, differing from kernel/cfgmgr32 this also breaks showing dev name alongside id, as the name seems inaccessible from cfgmgr32 given an interface supplied by rawinput not a big deal considering the names are too generic to be useful anyway --- wrapper/wrapper.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'wrapper') diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp index f5672a1..71a8cf6 100644 --- a/wrapper/wrapper.cpp +++ b/wrapper/wrapper.cpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -276,6 +277,30 @@ public: } }; +struct device_info { + std::wstring name; + std::wstring id; +}; + +std::vector get_unique_device_info() { + std::vector info; + + rawinput_foreach_with_interface([&](const auto& dev, const WCHAR* name) { + info.push_back({ + L"", // get_property_wstr(name, &DEVPKEY_Device_FriendlyName), /* doesn't work */ + dev_id_from_interface(name) + }); + }); + + std::sort(info.begin(), info.end(), + [](auto&& l, auto&& r) { return l.id < r.id; }); + auto last = std::unique(info.begin(), info.end(), + [](auto&& l, auto&& r) { return l.id == r.id; }); + info.erase(last, info.end()); + + return info; +} + public ref struct RawInputInterop { static void AddHandlesFromID(String^ deviceID, List^ rawInputHandles) @@ -292,6 +317,29 @@ public ref struct RawInputInterop throw gcnew System::Exception(gcnew String(e.what())); } } + + static List>^ GetDeviceIDs() + { + try + { + auto managed = gcnew List>(); + + for (auto&& [name, id] : get_unique_device_info()) + { + managed->Add( + ValueTuple( + msclr::interop::marshal_as(name), + msclr::interop::marshal_as(id))); + } + + return managed; + } + catch (const std::exception& e) + { + throw gcnew System::Exception(gcnew String(e.what())); + } + } + }; public ref struct DriverInterop -- cgit v1.2.3