summaryrefslogtreecommitdiff
path: root/Source/Core/Common
diff options
context:
space:
mode:
authorJoshua Vandaƫle <joshua@vandaele.software>2025-06-13 14:21:39 +0200
committerJoshua Vandaƫle <joshua@vandaele.software>2025-06-13 17:46:53 +0200
commitd93245cc7a2aaa232a57161cdde426a540f0d810 (patch)
tree527727cfc8a8116854cca9821b1aafce237af456 /Source/Core/Common
parent944dd711b756702d48d7415866c4272d1a472e5f (diff)
Host: Implement a Windows-only implementation of `GetDeviceNameFromVIDPID`
Diffstat (limited to 'Source/Core/Common')
-rw-r--r--Source/Core/Common/CommonFuncs.cpp24
-rw-r--r--Source/Core/Common/CommonFuncs.h10
2 files changed, 34 insertions, 0 deletions
diff --git a/Source/Core/Common/CommonFuncs.cpp b/Source/Core/Common/CommonFuncs.cpp
index aff87a9258..f59939bf6b 100644
--- a/Source/Core/Common/CommonFuncs.cpp
+++ b/Source/Core/Common/CommonFuncs.cpp
@@ -10,6 +10,7 @@
#ifdef _WIN32
#include <windows.h>
+#include <SetupAPI.h>
#define strerror_r(err, buf, len) strerror_s(buf, len, err)
@@ -91,5 +92,28 @@ std::optional<std::wstring> GetModuleName(void* hInstance)
name.resize(size);
return name;
}
+
+std::wstring GetDeviceProperty(const HDEVINFO& device_info, const PSP_DEVINFO_DATA device_data,
+ const DEVPROPKEY* requested_property)
+{
+ DWORD required_size = 0;
+ DEVPROPTYPE device_property_type;
+ BOOL result;
+
+ result = SetupDiGetDeviceProperty(device_info, device_data, requested_property,
+ &device_property_type, nullptr, 0, &required_size, 0);
+ if (!result && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+ return std::wstring();
+
+ std::vector<TCHAR> unicode_buffer(required_size / sizeof(TCHAR));
+
+ result = SetupDiGetDeviceProperty(
+ device_info, device_data, requested_property, &device_property_type,
+ reinterpret_cast<PBYTE>(unicode_buffer.data()), required_size, nullptr, 0);
+ if (!result)
+ return std::wstring();
+
+ return std::wstring(unicode_buffer.data());
+}
#endif
} // namespace Common
diff --git a/Source/Core/Common/CommonFuncs.h b/Source/Core/Common/CommonFuncs.h
index c774cc64aa..8e09d0747b 100644
--- a/Source/Core/Common/CommonFuncs.h
+++ b/Source/Core/Common/CommonFuncs.h
@@ -5,6 +5,12 @@
#include <optional>
#include <string>
+#ifdef _WIN32
+#include <SetupAPI.h>
+#include <cfgmgr32.h>
+#include <devpropdef.h>
+#endif
+
#include "Common/CommonTypes.h"
#ifndef _WIN32
@@ -58,5 +64,9 @@ std::string GetWin32ErrorString(unsigned long error_code);
// Obtains a full path to the specified module.
std::optional<std::wstring> GetModuleName(void* hInstance);
+
+// Obtains a device property and returns it as a wide string.
+std::wstring GetDeviceProperty(const HANDLE& device_info, const PSP_DEVINFO_DATA device_data,
+ const DEVPROPKEY* requested_property);
#endif
} // namespace Common