From 0cca0d98315e7fca0cb255f796ddd11af618140a Mon Sep 17 00:00:00 2001 From: GH Cao Date: Fri, 2 Sep 2022 16:53:53 +0800 Subject: [PATCH] win_joystick_rawinput: Fix wchar/char mismatch --- src/include/86box/win.h | 2 ++ src/qt/win_joystick_rawinput.c | 10 +++++----- src/win/win_joystick_rawinput.c | 10 +++++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/include/86box/win.h b/src/include/86box/win.h index ccd6e0f19..4122bb684 100644 --- a/src/include/86box/win.h +++ b/src/include/86box/win.h @@ -23,7 +23,9 @@ #ifndef PLAT_WIN_H #define PLAT_WIN_H +#ifndef UNICODE #define UNICODE +#endif #define BITMAP WINDOWS_BITMAP #if 0 # ifdef _WIN32_WINNT diff --git a/src/qt/win_joystick_rawinput.c b/src/qt/win_joystick_rawinput.c index d1fca0491..dd95f40c9 100644 --- a/src/qt/win_joystick_rawinput.c +++ b/src/qt/win_joystick_rawinput.c @@ -205,15 +205,15 @@ void joystick_get_capabilities(raw_joystick_t* rawjoy, plat_joystick_t* joy) { void joystick_get_device_name(raw_joystick_t* rawjoy, plat_joystick_t* joy, PRID_DEVICE_INFO info) { UINT size = 0; - char *device_name = NULL; + WCHAR *device_name = NULL; WCHAR device_desc_wide[200] = {0}; - GetRawInputDeviceInfoA(rawjoy->hdevice, RIDI_DEVICENAME, device_name, &size); - device_name = calloc(size, sizeof(char)); - if (GetRawInputDeviceInfoA(rawjoy->hdevice, RIDI_DEVICENAME, device_name, &size) <= 0) + GetRawInputDeviceInfoW(rawjoy->hdevice, RIDI_DEVICENAME, device_name, &size); + device_name = calloc(size, sizeof(WCHAR)); + if (GetRawInputDeviceInfoW(rawjoy->hdevice, RIDI_DEVICENAME, device_name, &size) <= 0) fatal("joystick_get_capabilities: Failed to get device name.\n"); - HANDLE hDevObj = CreateFile(device_name, GENERIC_READ | GENERIC_WRITE, + HANDLE hDevObj = CreateFileW(device_name, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (hDevObj) { HidD_GetProductString(hDevObj, device_desc_wide, sizeof(WCHAR) * 200); diff --git a/src/win/win_joystick_rawinput.c b/src/win/win_joystick_rawinput.c index 47441f8cf..86c4bfa87 100644 --- a/src/win/win_joystick_rawinput.c +++ b/src/win/win_joystick_rawinput.c @@ -220,15 +220,15 @@ void joystick_get_device_name(raw_joystick_t *rawjoy, plat_joystick_t *joy, PRID_DEVICE_INFO info) { UINT size = 0; - char *device_name = NULL; + WCHAR *device_name = NULL; WCHAR device_desc_wide[200] = { 0 }; - GetRawInputDeviceInfoA(rawjoy->hdevice, RIDI_DEVICENAME, device_name, &size); - device_name = calloc(size, sizeof(char)); - if (GetRawInputDeviceInfoA(rawjoy->hdevice, RIDI_DEVICENAME, device_name, &size) <= 0) + GetRawInputDeviceInfoW(rawjoy->hdevice, RIDI_DEVICENAME, device_name, &size); + device_name = calloc(size, sizeof(WCHAR)); + if (GetRawInputDeviceInfoW(rawjoy->hdevice, RIDI_DEVICENAME, device_name, &size) <= 0) fatal("joystick_get_capabilities: Failed to get device name.\n"); - HANDLE hDevObj = CreateFile(device_name, GENERIC_READ | GENERIC_WRITE, + HANDLE hDevObj = CreateFileW(device_name, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (hDevObj) { HidD_GetProductString(hDevObj, device_desc_wide, sizeof(WCHAR) * 200);