Explicitly use wide version of win API

This commit is contained in:
Exzap 2025-11-21 22:18:14 +01:00
parent c7c7e5c29d
commit 518eca80c3
6 changed files with 22 additions and 42 deletions

View file

@ -590,16 +590,16 @@ void CemuUpdateWindow::OnClose(wxCloseEvent& event)
if (m_restartRequired && !m_restartFile.empty() && fs::exists(m_restartFile)) if (m_restartRequired && !m_restartFile.empty() && fs::exists(m_restartFile))
{ {
PROCESS_INFORMATION pi{}; PROCESS_INFORMATION pi{};
STARTUPINFO si{}; STARTUPINFOW si{};
si.cb = sizeof(si); si.cb = sizeof(si);
std::wstring cmdline = GetCommandLineW(); std::wstring cmdline = GetCommandLineW();
const auto index = cmdline.find('"', 1); const auto index = cmdline.find('"', 1);
cemu_assert_debug(index != std::wstring::npos); 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"); HANDLE lock = CreateMutexW(nullptr, TRUE, L"Global\\cemu_update_lock");
CreateProcess(nullptr, (wchar_t*)cmdline.c_str(), nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi); CreateProcessW(nullptr, (wchar_t*)cmdline.c_str(), nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi);
exit(0); exit(0);
} }

View file

@ -22,9 +22,10 @@ DirectInputController::~DirectInputController()
// TODO: test if really needed // TODO: test if really needed
// workaround for gamecube controllers crash on release? // workaround for gamecube controllers crash on release?
bool should_release_device = true; bool should_release_device = true;
if (m_product_guid == GUID{}) { if (m_product_guid == GUID{})
DIDEVICEINSTANCE info{}; {
info.dwSize = sizeof(DIDEVICEINSTANCE); DIDEVICEINSTANCEW info{};
info.dwSize = sizeof(DIDEVICEINSTANCEW);
if (SUCCEEDED(m_device->GetDeviceInfo(&info))) if (SUCCEEDED(m_device->GetDeviceInfo(&info)))
{ {
m_product_guid = info.guidProduct; m_product_guid = info.guidProduct;
@ -90,8 +91,8 @@ bool DirectInputController::connect()
if (FAILED(hr) || m_device == nullptr) if (FAILED(hr) || m_device == nullptr)
return false; return false;
DIDEVICEINSTANCE idi{}; DIDEVICEINSTANCEW idi{};
idi.dwSize = sizeof(DIDEVICEINSTANCE); idi.dwSize = sizeof(DIDEVICEINSTANCEW);
if (SUCCEEDED(m_device->GetDeviceInfo(&idi))) if (SUCCEEDED(m_device->GetDeviceInfo(&idi)))
{ {
// overwrite guid name with "real" display name // overwrite guid name with "real" display name
@ -147,8 +148,8 @@ bool DirectInputController::connect()
} }
} }
DIDEVICEINSTANCE info{}; DIDEVICEINSTANCEW info{};
info.dwSize = sizeof(DIDEVICEINSTANCE); info.dwSize = sizeof(DIDEVICEINSTANCEW);
if (SUCCEEDED(m_device->GetDeviceInfo(&info))) if (SUCCEEDED(m_device->GetDeviceInfo(&info)))
{ {
m_product_guid = info.guidProduct; 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_min_axis.begin(), m_min_axis.end(), 0);
std::fill(m_max_axis.begin(), m_max_axis.end(), std::numeric_limits<uint16>::max()); std::fill(m_max_axis.begin(), m_max_axis.end(), std::numeric_limits<uint16>::max());
m_device->EnumObjects( m_device->EnumObjects(
[](LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) -> BOOL [](LPCDIDEVICEOBJECTINSTANCEW lpddoi, LPVOID pvRef) -> BOOL
{ {
auto* thisptr = (DirectInputController*)pvRef; auto* thisptr = (DirectInputController*)pvRef;

View file

@ -42,7 +42,7 @@ private:
GUID m_product_guid{}; GUID m_product_guid{};
std::shared_mutex m_mutex; std::shared_mutex m_mutex;
Microsoft::WRL::ComPtr<IDirectInputDevice8> m_device; Microsoft::WRL::ComPtr<IDirectInputDevice8W> m_device;
Microsoft::WRL::ComPtr<IDirectInputEffect> m_effect; Microsoft::WRL::ComPtr<IDirectInputEffect> m_effect;
std::array<LONG, 6> m_min_axis{}; std::array<LONG, 6> m_min_axis{};

View file

@ -4,34 +4,16 @@
DirectInputControllerProvider::DirectInputControllerProvider() DirectInputControllerProvider::DirectInputControllerProvider()
{ {
/*m_module = LoadLibraryA("dinput8.dll"); const auto r = DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8W, (void**)&m_dinput8, nullptr);
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);
if (FAILED(r)) if (FAILED(r))
{ {
const auto error = GetLastError(); const auto error = GetLastError();
//FreeLibrary(m_module);
throw std::runtime_error(fmt::format("can't create direct input object (error: {:#x})", error)); throw std::runtime_error(fmt::format("can't create direct input object (error: {:#x})", error));
} }
} }
DirectInputControllerProvider::~DirectInputControllerProvider() DirectInputControllerProvider::~DirectInputControllerProvider()
{ {
/*if (m_module)
FreeLibrary(m_module);
*/
} }
std::vector<std::shared_ptr<ControllerBase>> DirectInputControllerProvider::get_controllers() std::vector<std::shared_ptr<ControllerBase>> DirectInputControllerProvider::get_controllers()
@ -39,7 +21,7 @@ std::vector<std::shared_ptr<ControllerBase>> DirectInputControllerProvider::get_
std::vector<std::shared_ptr<ControllerBase>> result; std::vector<std::shared_ptr<ControllerBase>> result;
m_dinput8->EnumDevices(DI8DEVCLASS_GAMECTRL, m_dinput8->EnumDevices(DI8DEVCLASS_GAMECTRL,
[](LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) -> BOOL [](LPCDIDEVICEINSTANCEW lpddi, LPVOID pvRef) -> BOOL
{ {
auto* controllers = (decltype(&result))pvRef; auto* controllers = (decltype(&result))pvRef;
@ -55,8 +37,5 @@ std::vector<std::shared_ptr<ControllerBase>> DirectInputControllerProvider::get_
LPCDIDATAFORMAT DirectInputControllerProvider::get_data_format() const LPCDIDATAFORMAT DirectInputControllerProvider::get_data_format() const
{ {
/*if (m_GetdfDIJoystick)
return m_GetdfDIJoystick();*/
return GetdfDIJoystick(); return GetdfDIJoystick();
} }

View file

@ -23,7 +23,7 @@ public:
std::vector<std::shared_ptr<ControllerBase>> get_controllers() override; std::vector<std::shared_ptr<ControllerBase>> get_controllers() override;
IDirectInput8* get_dinput() const { return m_dinput8.Get(); } IDirectInput8W* get_dinput() const { return m_dinput8.Get(); }
LPCDIDATAFORMAT get_data_format() const; LPCDIDATAFORMAT get_data_format() const;
private: private:
@ -32,7 +32,7 @@ private:
decltype(&DirectInput8Create) m_DirectInput8Create; decltype(&DirectInput8Create) m_DirectInput8Create;
decltype(&GetdfDIJoystick) m_GetdfDIJoystick = nullptr; decltype(&GetdfDIJoystick) m_GetdfDIJoystick = nullptr;
Microsoft::WRL::ComPtr<IDirectInput8> m_dinput8; Microsoft::WRL::ComPtr<IDirectInput8W> m_dinput8;
}; };
#endif #endif

View file

@ -96,12 +96,12 @@ void WindowsInitCwd()
{ {
#if BOOST_OS_WINDOWS #if BOOST_OS_WINDOWS
executablePath.resize(4096); executablePath.resize(4096);
int i = GetModuleFileName(NULL, executablePath.data(), executablePath.size()); int i = GetModuleFileNameW(NULL, executablePath.data(), executablePath.size());
if(i >= 0) if(i >= 0)
executablePath.resize(i); executablePath.resize(i);
else else
executablePath.clear(); executablePath.clear();
SetCurrentDirectory(executablePath.c_str()); SetCurrentDirectoryW(executablePath.c_str());
// set high priority // set high priority
SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS); SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
#endif #endif
@ -192,7 +192,7 @@ void HandlePostUpdate()
HANDLE lock; HANDLE lock;
do 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)); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} while (lock == nullptr); } while (lock == nullptr);
const DWORD wait_result = WaitForSingleObject(lock, 2000); const DWORD wait_result = WaitForSingleObject(lock, 2000);
@ -220,7 +220,7 @@ void ToolShaderCacheMerger();
#if BOOST_OS_WINDOWS #if BOOST_OS_WINDOWS
// entrypoint for release builds // 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))) if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE)))
cemuLog_log(LogType::Force, "CoInitializeEx() failed"); cemuLog_log(LogType::Force, "CoInitializeEx() failed");