use unicode versions of windows functions

This commit is contained in:
Brad Parker 2016-11-29 02:04:13 -05:00
parent 53549646af
commit cd9d09d1f3
10 changed files with 63 additions and 12 deletions

View File

@ -208,6 +208,8 @@ void fill_pathname_application_path(char *s, size_t len)
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
DWORD ret; DWORD ret;
wchar_t ws[len];
size_t ws_size = 0;
#endif #endif
#ifdef __HAIKU__ #ifdef __HAIKU__
image_info info; image_info info;
@ -219,7 +221,9 @@ void fill_pathname_application_path(char *s, size_t len)
return; return;
#ifdef _WIN32 #ifdef _WIN32
ret = GetModuleFileName(GetModuleHandle(NULL), s, len - 1); mbstowcs_s(&ws_size, ws, len, s, len - 1);
ret = GetModuleFileName(GetModuleHandle(NULL), ws, len - 1);
s[ret] = '\0'; s[ret] = '\0';
#elif defined(__APPLE__) #elif defined(__APPLE__)
if (bundle) if (bundle)

View File

@ -260,6 +260,7 @@ void win32_monitor_info(void *data, void *hm_data, unsigned *mon_id)
static int win32_drag_query_file(HWND hwnd, WPARAM wparam) static int win32_drag_query_file(HWND hwnd, WPARAM wparam)
{ {
char szFilename[1024] = {0}; char szFilename[1024] = {0};
wchar_t wszFilename[1024] = {0};
if (DragQueryFile((HDROP)wparam, 0xFFFFFFFF, NULL, 0)) if (DragQueryFile((HDROP)wparam, 0xFFFFFFFF, NULL, 0))
{ {
@ -268,8 +269,11 @@ static int win32_drag_query_file(HWND hwnd, WPARAM wparam)
content_ctx_info_t content_info = {0}; content_ctx_info_t content_info = {0};
core_info_list_t *core_info_list = NULL; core_info_list_t *core_info_list = NULL;
const core_info_t *core_info = NULL; const core_info_t *core_info = NULL;
size_t file_len = 0;
DragQueryFile((HDROP)wparam, 0, szFilename, 1024); DragQueryFile((HDROP)wparam, 0, wszFilename, 1024);
wcstombs_s(&file_len, szFilename, sizeof(szFilename), wszFilename, sizeof(szFilename) - 1);
core_info_get_list(&core_info_list); core_info_get_list(&core_info_list);
@ -510,7 +514,7 @@ bool win32_window_create(void *data, unsigned style,
unsigned height, bool fullscreen) unsigned height, bool fullscreen)
{ {
#ifndef _XBOX #ifndef _XBOX
main_window.hwnd = CreateWindowEx(0, "RetroArch", "RetroArch", main_window.hwnd = CreateWindowEx(0, L"RetroArch", L"RetroArch",
style, style,
fullscreen ? mon_rect->left : g_pos_x, fullscreen ? mon_rect->left : g_pos_x,
fullscreen ? mon_rect->top : g_pos_y, fullscreen ? mon_rect->top : g_pos_y,
@ -578,6 +582,9 @@ static bool win32_monitor_set_fullscreen(unsigned width, unsigned height,
{ {
#ifndef _XBOX #ifndef _XBOX
DEVMODE devmode; DEVMODE devmode;
wchar_t dev_name_wide[1024];
size_t dev_name_size = strlen(dev_name) + 1;
size_t dev_name_wide_size = 0;
memset(&devmode, 0, sizeof(devmode)); memset(&devmode, 0, sizeof(devmode));
devmode.dmSize = sizeof(DEVMODE); devmode.dmSize = sizeof(DEVMODE);
@ -588,7 +595,10 @@ static bool win32_monitor_set_fullscreen(unsigned width, unsigned height,
RARCH_LOG("Setting fullscreen to %ux%u @ %uHz on device %s.\n", RARCH_LOG("Setting fullscreen to %ux%u @ %uHz on device %s.\n",
width, height, refresh, dev_name); width, height, refresh, dev_name);
return ChangeDisplaySettingsEx(dev_name, &devmode,
mbstowcs_s(&dev_name_wide_size, dev_name_wide, dev_name_size, dev_name, dev_name_size - 1);
return ChangeDisplaySettingsEx(dev_name_wide, &devmode,
NULL, CDS_FULLSCREEN, NULL) == DISP_CHANGE_SUCCESSFUL; NULL, CDS_FULLSCREEN, NULL) == DISP_CHANGE_SUCCESSFUL;
#endif #endif
} }
@ -679,7 +689,8 @@ bool win32_suppress_screensaver(void *data, bool enable)
#endif #endif
} }
void win32_set_style(MONITORINFOEX *current_mon, HMONITOR *hm_to_use, /* FIXME: It should not be necessary to add the W after MONITORINFOEX, but linking fails without it. */
void win32_set_style(MONITORINFOEXW *current_mon, HMONITOR *hm_to_use,
unsigned *width, unsigned *height, bool fullscreen, bool windowed_full, unsigned *width, unsigned *height, bool fullscreen, bool windowed_full,
RECT *rect, RECT *mon_rect, DWORD *style) RECT *rect, RECT *mon_rect, DWORD *style)
{ {
@ -704,10 +715,14 @@ void win32_set_style(MONITORINFOEX *current_mon, HMONITOR *hm_to_use,
} }
else else
{ {
char dev_name[CCHDEVICENAME] = {0};
size_t name_len = 0;
*style = WS_POPUP | WS_VISIBLE; *style = WS_POPUP | WS_VISIBLE;
wcstombs_s(&name_len, dev_name, sizeof(dev_name), current_mon->szDevice, sizeof(dev_name) - 1);
if (!win32_monitor_set_fullscreen(*width, *height, if (!win32_monitor_set_fullscreen(*width, *height,
refresh, current_mon->szDevice)) refresh, dev_name))
{} {}
/* Display settings might have changed, get new coordinates. */ /* Display settings might have changed, get new coordinates. */
@ -853,7 +868,7 @@ void win32_window_reset(void)
void win32_destroy_window(void) void win32_destroy_window(void)
{ {
#ifndef _XBOX #ifndef _XBOX
UnregisterClass("RetroArch", GetModuleHandle(NULL)); UnregisterClass(L"RetroArch", GetModuleHandle(NULL));
#endif #endif
main_window.hwnd = NULL; main_window.hwnd = NULL;
} }

View File

@ -21,6 +21,9 @@
#ifndef _XBOX #ifndef _XBOX
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define UNICODE
#include <tchar.h>
#include <wchar.h>
#include <windows.h> #include <windows.h>
#endif #endif
@ -94,7 +97,8 @@ void win32_check_window(bool *quit,
void win32_set_window(unsigned *width, unsigned *height, void win32_set_window(unsigned *width, unsigned *height,
bool fullscreen, bool windowed_full, void *rect_data); bool fullscreen, bool windowed_full, void *rect_data);
void win32_set_style(MONITORINFOEX *current_mon, HMONITOR *hm_to_use, /* FIXME: It should not be necessary to add the W after MONITORINFOEX, but linking fails without it. */
void win32_set_style(MONITORINFOEXW *current_mon, HMONITOR *hm_to_use,
unsigned *width, unsigned *height, bool fullscreen, bool windowed_full, unsigned *width, unsigned *height, bool fullscreen, bool windowed_full,
RECT *rect, RECT *mon_rect, DWORD *style); RECT *rect, RECT *mon_rect, DWORD *style);

View File

@ -18,6 +18,10 @@
#ifdef _XBOX #ifdef _XBOX
#include <xtl.h> #include <xtl.h>
#include <xgraphics.h> #include <xgraphics.h>
#else
#define UNICODE
#include <tchar.h>
#include <wchar.h>
#endif #endif
#include <formats/image.h> #include <formats/image.h>

View File

@ -45,7 +45,7 @@ static void *d3dfonts_w32_init_font(void *video_data,
OUT_TT_PRECIS, OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_PITCH, DEFAULT_PITCH,
"Verdana" /* Hardcode FTL */ L"Verdana" /* Hardcode FTL */
}; };
d3dfonts = (d3dfonts_t*)calloc(1, sizeof(*d3dfonts)); d3dfonts = (d3dfonts_t*)calloc(1, sizeof(*d3dfonts));

View File

@ -28,11 +28,15 @@
#include <boolean.h> #include <boolean.h>
#include <retro_stat.h> #include <retro_stat.h>
#include <retro_dirent.h> #include <retro_dirent.h>
#include <encodings/utf.h>
struct RDIR *retro_opendir(const char *name) struct RDIR *retro_opendir(const char *name)
{ {
#if defined(_WIN32) #if defined(_WIN32)
char path_buf[1024]; char path_buf[1024];
wchar_t pathW[1024];
size_t path_size = 0;
size_t out_size = 0;
#endif #endif
struct RDIR *rdir = (struct RDIR*)calloc(1, sizeof(*rdir)); struct RDIR *rdir = (struct RDIR*)calloc(1, sizeof(*rdir));
@ -41,7 +45,9 @@ struct RDIR *retro_opendir(const char *name)
#if defined(_WIN32) #if defined(_WIN32)
snprintf(path_buf, sizeof(path_buf), "%s\\*", name); snprintf(path_buf, sizeof(path_buf), "%s\\*", name);
rdir->directory = FindFirstFile(path_buf, &rdir->entry); path_size = strlen(path_buf) + 1;
mbstowcs_s(&out_size, pathW, path_size, path_buf, path_size - 1);
rdir->directory = FindFirstFile(pathW, &rdir->entry);
#elif defined(VITA) || defined(PSP) #elif defined(VITA) || defined(PSP)
rdir->directory = sceIoDopen(name); rdir->directory = sceIoDopen(name);
#elif defined(_3DS) #elif defined(_3DS)
@ -93,7 +99,8 @@ int retro_readdir(struct RDIR *rdir)
const char *retro_dirent_get_name(struct RDIR *rdir) const char *retro_dirent_get_name(struct RDIR *rdir)
{ {
#if defined(_WIN32) #if defined(_WIN32)
return rdir->entry.cFileName; utf16_to_char_string(rdir->entry.cFileName, rdir->path, sizeof(rdir->path));
return rdir->path;
#elif defined(VITA) || defined(PSP) || defined(__CELLOS_LV2__) #elif defined(VITA) || defined(PSP) || defined(__CELLOS_LV2__)
return rdir->entry.d_name; return rdir->entry.d_name;
#else #else

View File

@ -33,6 +33,9 @@
#include <xtl.h> #include <xtl.h>
#define INVALID_FILE_ATTRIBUTES -1 #define INVALID_FILE_ATTRIBUTES -1
#else #else
#define UNICODE
#include <tchar.h>
#include <wchar.h>
#include <io.h> #include <io.h>
#include <fcntl.h> #include <fcntl.h>
#include <direct.h> #include <direct.h>
@ -102,7 +105,13 @@ static bool path_stat(const char *path, enum stat_mode mode, int32_t *size)
#elif defined(_WIN32) #elif defined(_WIN32)
WIN32_FILE_ATTRIBUTE_DATA file_info; WIN32_FILE_ATTRIBUTE_DATA file_info;
GET_FILEEX_INFO_LEVELS fInfoLevelId = GetFileExInfoStandard; GET_FILEEX_INFO_LEVELS fInfoLevelId = GetFileExInfoStandard;
DWORD ret = GetFileAttributesEx(path, fInfoLevelId, &file_info); size_t path_len = strlen(path);
wchar_t path_wide[path_len + 1];
size_t path_wide_size = 0;
mbstowcs_s(&path_wide_size, path_wide, path_len + 1, path, path_len);
DWORD ret = GetFileAttributesEx(path_wide, fInfoLevelId, &file_info);
if (ret == 0) if (ret == 0)
return false; return false;
#else #else

View File

@ -24,6 +24,7 @@
#define __RETRO_DIRENT_H #define __RETRO_DIRENT_H
#include <retro_common_api.h> #include <retro_common_api.h>
#include <retro_miscellaneous.h>
#include <boolean.h> #include <boolean.h>
@ -65,6 +66,7 @@ struct RDIR
WIN32_FIND_DATA entry; WIN32_FIND_DATA entry;
HANDLE directory; HANDLE directory;
bool next; bool next;
char path[PATH_MAX_LENGTH];
#elif defined(VITA) || defined(PSP) #elif defined(VITA) || defined(PSP)
SceUID directory; SceUID directory;
SceIoDirent entry; SceIoDirent entry;

View File

@ -47,6 +47,9 @@
#if defined(_WIN32) && !defined(_XBOX) #if defined(_WIN32) && !defined(_XBOX)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define UNICODE
#include <tchar.h>
#include <wchar.h>
#include <windows.h> #include <windows.h>
#elif defined(_WIN32) && defined(_XBOX) #elif defined(_WIN32) && defined(_XBOX)
#include <Xtl.h> #include <Xtl.h>

View File

@ -26,6 +26,9 @@
#include <errno.h> #include <errno.h>
#if defined(_WIN32) #if defined(_WIN32)
# define UNICODE
# include <tchar.h>
# include <wchar.h>
# ifdef _MSC_VER # ifdef _MSC_VER
# define setmode _setmode # define setmode _setmode
# endif # endif