From 68713e08b4b5009e76147e0109ffef3472477cfe Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sat, 19 Jul 2025 14:02:43 +0200 Subject: Common: Move GetDeviceProperty() into its own header Otherwise we include Windows headers in the entire codebase through CommonFuncs.h --- Source/Core/Common/WindowsDevice.cpp | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Source/Core/Common/WindowsDevice.cpp (limited to 'Source/Core/Common/WindowsDevice.cpp') diff --git a/Source/Core/Common/WindowsDevice.cpp b/Source/Core/Common/WindowsDevice.cpp new file mode 100644 index 0000000000..8ecc346187 --- /dev/null +++ b/Source/Core/Common/WindowsDevice.cpp @@ -0,0 +1,38 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#ifdef _WIN32 + +#include "Common/WindowsDevice.h" + +#include + +#include "Common/CommonFuncs.h" + +namespace Common +{ +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 unicode_buffer(required_size / sizeof(TCHAR)); + + result = SetupDiGetDeviceProperty( + device_info, device_data, requested_property, &device_property_type, + reinterpret_cast(unicode_buffer.data()), required_size, nullptr, 0); + if (!result) + return std::wstring(); + + return std::wstring(unicode_buffer.data()); +} +} // namespace Common + +#endif -- cgit v1.2.3