diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index 6d1b6908f3..ee738ba4e3 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -309,6 +309,8 @@ if(WIN32) CompatPatches.cpp GL/GLInterface/WGL.cpp GL/GLInterface/WGL.h + WindowsDevice.cpp + WindowsDevice.h WindowsRegistry.cpp ) elseif(APPLE) diff --git a/Source/Core/Common/CommonFuncs.cpp b/Source/Core/Common/CommonFuncs.cpp index f59939bf6b..91eed700ab 100644 --- a/Source/Core/Common/CommonFuncs.cpp +++ b/Source/Core/Common/CommonFuncs.cpp @@ -92,28 +92,5 @@ std::optional 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 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()); -} #endif } // namespace Common diff --git a/Source/Core/Common/CommonFuncs.h b/Source/Core/Common/CommonFuncs.h index 8e09d0747b..94b97ba469 100644 --- a/Source/Core/Common/CommonFuncs.h +++ b/Source/Core/Common/CommonFuncs.h @@ -5,11 +5,6 @@ #include #include -#ifdef _WIN32 -#include -#include -#include -#endif #include "Common/CommonTypes.h" @@ -64,9 +59,5 @@ std::string GetWin32ErrorString(unsigned long error_code); // Obtains a full path to the specified module. std::optional 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 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 diff --git a/Source/Core/Common/WindowsDevice.h b/Source/Core/Common/WindowsDevice.h new file mode 100644 index 0000000000..c79e9b0d7a --- /dev/null +++ b/Source/Core/Common/WindowsDevice.h @@ -0,0 +1,29 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#ifdef _WIN32 + +#include + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include + +#include +#include +#include + +namespace Common +{ +// 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); +} // namespace Common + +#endif diff --git a/Source/Core/Core/HW/WiimoteReal/IOWin.cpp b/Source/Core/Core/HW/WiimoteReal/IOWin.cpp index da4926524f..924213e1c8 100644 --- a/Source/Core/Core/HW/WiimoteReal/IOWin.cpp +++ b/Source/Core/Core/HW/WiimoteReal/IOWin.cpp @@ -30,6 +30,7 @@ #include "Common/Logging/Log.h" #include "Common/ScopeGuard.h" #include "Common/Thread.h" +#include "Common/WindowsDevice.h" #include "Core/HW/WiimoteCommon/DataReport.h" #include "Core/HW/WiimoteCommon/WiimoteConstants.h" #include "Core/HW/WiimoteCommon/WiimoteReport.h" diff --git a/Source/Core/Core/IOS/USB/Host.cpp b/Source/Core/Core/IOS/USB/Host.cpp index d14a76b0cc..f8263d7afd 100644 --- a/Source/Core/Core/IOS/USB/Host.cpp +++ b/Source/Core/Core/IOS/USB/Host.cpp @@ -19,12 +19,11 @@ #ifdef __LIBUSB__ #include #endif + #ifdef _WIN32 #include #include #include - -#include "Common/CommonFuncs.h" #endif #include "Common/ChunkFile.h" @@ -35,6 +34,10 @@ #include "Core/IOS/USB/USBScanner.h" #include "Core/System.h" +#ifdef _WIN32 +#include "Common/WindowsDevice.h" +#endif + namespace IOS::HLE { USBHost::USBHost(EmulationKernel& ios, const std::string& device_name) diff --git a/Source/Core/DolphinLib.props b/Source/Core/DolphinLib.props index efcd9f5a92..5803fb0437 100644 --- a/Source/Core/DolphinLib.props +++ b/Source/Core/DolphinLib.props @@ -178,6 +178,7 @@ + @@ -861,6 +862,7 @@ +