From 518eca80c3b693fb2461268b18d338704617464e Mon Sep 17 00:00:00 2001 From: Exzap <13877693+Exzap@users.noreply.github.com> Date: Fri, 21 Nov 2025 22:18:14 +0100 Subject: [PATCH] Explicitly use wide version of win API --- src/gui/wxgui/CemuUpdateWindow.cpp | 8 +++--- .../api/DirectInput/DirectInputController.cpp | 17 +++++++------ .../api/DirectInput/DirectInputController.h | 2 +- .../DirectInputControllerProvider.cpp | 25 ++----------------- .../DirectInputControllerProvider.h | 4 +-- src/main.cpp | 8 +++--- 6 files changed, 22 insertions(+), 42 deletions(-) diff --git a/src/gui/wxgui/CemuUpdateWindow.cpp b/src/gui/wxgui/CemuUpdateWindow.cpp index 542ae588..fd51467d 100644 --- a/src/gui/wxgui/CemuUpdateWindow.cpp +++ b/src/gui/wxgui/CemuUpdateWindow.cpp @@ -590,16 +590,16 @@ void CemuUpdateWindow::OnClose(wxCloseEvent& event) if (m_restartRequired && !m_restartFile.empty() && fs::exists(m_restartFile)) { PROCESS_INFORMATION pi{}; - STARTUPINFO si{}; + STARTUPINFOW si{}; si.cb = sizeof(si); std::wstring cmdline = GetCommandLineW(); const auto index = cmdline.find('"', 1); cemu_assert_debug(index != std::wstring::npos); - cmdline = L"\"" + m_restartFile.wstring() + L"\"" + cmdline.substr(index + 1); + cmdline = L"\"" + boost::nowide::widen(_pathToUtf8(m_restartFile)) + L"\"" + cmdline.substr(index + 1); - HANDLE lock = CreateMutex(nullptr, TRUE, L"Global\\cemu_update_lock"); - CreateProcess(nullptr, (wchar_t*)cmdline.c_str(), nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi); + HANDLE lock = CreateMutexW(nullptr, TRUE, L"Global\\cemu_update_lock"); + CreateProcessW(nullptr, (wchar_t*)cmdline.c_str(), nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi); exit(0); } diff --git a/src/input/api/DirectInput/DirectInputController.cpp b/src/input/api/DirectInput/DirectInputController.cpp index 0792aac7..f0f33701 100644 --- a/src/input/api/DirectInput/DirectInputController.cpp +++ b/src/input/api/DirectInput/DirectInputController.cpp @@ -22,9 +22,10 @@ DirectInputController::~DirectInputController() // TODO: test if really needed // workaround for gamecube controllers crash on release? bool should_release_device = true; - if (m_product_guid == GUID{}) { - DIDEVICEINSTANCE info{}; - info.dwSize = sizeof(DIDEVICEINSTANCE); + if (m_product_guid == GUID{}) + { + DIDEVICEINSTANCEW info{}; + info.dwSize = sizeof(DIDEVICEINSTANCEW); if (SUCCEEDED(m_device->GetDeviceInfo(&info))) { m_product_guid = info.guidProduct; @@ -90,8 +91,8 @@ bool DirectInputController::connect() if (FAILED(hr) || m_device == nullptr) return false; - DIDEVICEINSTANCE idi{}; - idi.dwSize = sizeof(DIDEVICEINSTANCE); + DIDEVICEINSTANCEW idi{}; + idi.dwSize = sizeof(DIDEVICEINSTANCEW); if (SUCCEEDED(m_device->GetDeviceInfo(&idi))) { // overwrite guid name with "real" display name @@ -147,8 +148,8 @@ bool DirectInputController::connect() } } - DIDEVICEINSTANCE info{}; - info.dwSize = sizeof(DIDEVICEINSTANCE); + DIDEVICEINSTANCEW info{}; + info.dwSize = sizeof(DIDEVICEINSTANCEW); if (SUCCEEDED(m_device->GetDeviceInfo(&info))) { m_product_guid = info.guidProduct; @@ -157,7 +158,7 @@ bool DirectInputController::connect() std::fill(m_min_axis.begin(), m_min_axis.end(), 0); std::fill(m_max_axis.begin(), m_max_axis.end(), std::numeric_limits::max()); m_device->EnumObjects( - [](LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) -> BOOL + [](LPCDIDEVICEOBJECTINSTANCEW lpddoi, LPVOID pvRef) -> BOOL { auto* thisptr = (DirectInputController*)pvRef; diff --git a/src/input/api/DirectInput/DirectInputController.h b/src/input/api/DirectInput/DirectInputController.h index d2c3dba2..ac617356 100644 --- a/src/input/api/DirectInput/DirectInputController.h +++ b/src/input/api/DirectInput/DirectInputController.h @@ -42,7 +42,7 @@ private: GUID m_product_guid{}; std::shared_mutex m_mutex; - Microsoft::WRL::ComPtr m_device; + Microsoft::WRL::ComPtr m_device; Microsoft::WRL::ComPtr m_effect; std::array m_min_axis{}; diff --git a/src/input/api/DirectInput/DirectInputControllerProvider.cpp b/src/input/api/DirectInput/DirectInputControllerProvider.cpp index 79f31354..4c7192f6 100644 --- a/src/input/api/DirectInput/DirectInputControllerProvider.cpp +++ b/src/input/api/DirectInput/DirectInputControllerProvider.cpp @@ -4,34 +4,16 @@ DirectInputControllerProvider::DirectInputControllerProvider() { - /*m_module = LoadLibraryA("dinput8.dll"); - if (!m_module) - throw std::runtime_error("can't load any xinput dll"); - - m_DirectInput8Create = (decltype(&DirectInput8Create))GetProcAddress(m_module, "DirectInput8Create"); - m_GetdfDIJoystick = (decltype(&GetdfDIJoystick))GetProcAddress(m_module, "GetdfDIJoystick"); - - if (!m_DirectInput8Create) - { - FreeLibrary(m_module); - throw std::runtime_error("can't find the DirectInput8Create export"); - }*/ - - - const auto r = DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_dinput8, nullptr); + const auto r = DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8W, (void**)&m_dinput8, nullptr); if (FAILED(r)) { const auto error = GetLastError(); - //FreeLibrary(m_module); throw std::runtime_error(fmt::format("can't create direct input object (error: {:#x})", error)); } } DirectInputControllerProvider::~DirectInputControllerProvider() { - /*if (m_module) - FreeLibrary(m_module); - */ } std::vector> DirectInputControllerProvider::get_controllers() @@ -39,7 +21,7 @@ std::vector> DirectInputControllerProvider::get_ std::vector> result; m_dinput8->EnumDevices(DI8DEVCLASS_GAMECTRL, - [](LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) -> BOOL + [](LPCDIDEVICEINSTANCEW lpddi, LPVOID pvRef) -> BOOL { auto* controllers = (decltype(&result))pvRef; @@ -55,8 +37,5 @@ std::vector> DirectInputControllerProvider::get_ LPCDIDATAFORMAT DirectInputControllerProvider::get_data_format() const { - /*if (m_GetdfDIJoystick) - return m_GetdfDIJoystick();*/ - return GetdfDIJoystick(); } diff --git a/src/input/api/DirectInput/DirectInputControllerProvider.h b/src/input/api/DirectInput/DirectInputControllerProvider.h index de8c3216..aa601e84 100644 --- a/src/input/api/DirectInput/DirectInputControllerProvider.h +++ b/src/input/api/DirectInput/DirectInputControllerProvider.h @@ -23,7 +23,7 @@ public: std::vector> get_controllers() override; - IDirectInput8* get_dinput() const { return m_dinput8.Get(); } + IDirectInput8W* get_dinput() const { return m_dinput8.Get(); } LPCDIDATAFORMAT get_data_format() const; private: @@ -32,7 +32,7 @@ private: decltype(&DirectInput8Create) m_DirectInput8Create; decltype(&GetdfDIJoystick) m_GetdfDIJoystick = nullptr; - Microsoft::WRL::ComPtr m_dinput8; + Microsoft::WRL::ComPtr m_dinput8; }; #endif diff --git a/src/main.cpp b/src/main.cpp index ed48252c..9355465e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -96,12 +96,12 @@ void WindowsInitCwd() { #if BOOST_OS_WINDOWS executablePath.resize(4096); - int i = GetModuleFileName(NULL, executablePath.data(), executablePath.size()); + int i = GetModuleFileNameW(NULL, executablePath.data(), executablePath.size()); if(i >= 0) executablePath.resize(i); else executablePath.clear(); - SetCurrentDirectory(executablePath.c_str()); + SetCurrentDirectoryW(executablePath.c_str()); // set high priority SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS); #endif @@ -192,7 +192,7 @@ void HandlePostUpdate() HANDLE lock; do { - lock = CreateMutex(nullptr, TRUE, L"Global\\cemu_update_lock"); + lock = CreateMutexW(nullptr, TRUE, L"Global\\cemu_update_lock"); std::this_thread::sleep_for(std::chrono::milliseconds(1)); } while (lock == nullptr); const DWORD wait_result = WaitForSingleObject(lock, 2000); @@ -220,7 +220,7 @@ void ToolShaderCacheMerger(); #if BOOST_OS_WINDOWS // entrypoint for release builds -int wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nShowCmd) +int wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) { if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE))) cemuLog_log(LogType::Force, "CoInitializeEx() failed");