build fixes for MSVC, start moving back to TCHAR usage so we can switch unicode on and off

This commit is contained in:
Brad Parker 2016-12-02 12:15:38 -05:00
parent 8e7d440ed5
commit 3846ce1837
11 changed files with 1797 additions and 868 deletions

View File

@ -19,6 +19,8 @@
#include <stddef.h>
#include <string.h>
#include <encodings/win32.h>
#ifndef _XBOX
#include <windows.h>
#include <mmreg.h>
@ -291,11 +293,15 @@ struct dsound_dev
LPGUID guid;
};
static BOOL CALLBACK enumerate_cb(LPGUID guid, LPCSTR desc, LPCSTR module, LPVOID context)
static BOOL CALLBACK enumerate_cb(LPGUID guid, LPCTSTR desc, LPCTSTR module, LPVOID context)
{
struct dsound_dev *dev = (struct dsound_dev*)context;
WCHAR_TO_CHAR_ALLOC(desc, desc_str)
RARCH_LOG("\t%u: %s\n", dev->total_count, desc);
RARCH_LOG("\t%u: %s\n", dev->total_count, desc_str);
if (desc_str)
free(desc_str);
if (dev->device == dev->total_count)
dev->guid = guid;

View File

@ -48,7 +48,7 @@
#include "../../configuration.h"
#include "../../verbosity.h"
#include "../tasks/tasks_internal.h"
#include "../../tasks/tasks_internal.h"
#include "../input_config.h"
#include "../input_joypad_driver.h"
#include "../input_keymaps.h"

View File

@ -17,6 +17,7 @@
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <encodings/win32.h>
#include <windowsx.h>
#include <dinput.h>
@ -207,6 +208,7 @@ static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p)
#endif
LPDIRECTINPUTDEVICE8 *pad = NULL;
settings_t *settings = config_get_ptr();
WCHAR_TO_CHAR_ALLOC(inst->tszInstanceName, name)
(void)p;
@ -224,8 +226,11 @@ static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p)
#endif
return DIENUM_CONTINUE;
g_pads[g_joypad_cnt].joy_name = strdup(inst->tszProductName);
g_pads[g_joypad_cnt].joy_friendly_name = strdup(inst->tszInstanceName);
g_pads[g_joypad_cnt].joy_name = strdup(name);
g_pads[g_joypad_cnt].joy_friendly_name = strdup(name);
if (name)
free(name);
/* there may be more useful info in the GUID so leave this here for a while */
#if 0

View File

@ -23,6 +23,7 @@
#include <string.h>
#include <stdio.h>
#include <dynamic/dylib.h>
#include <encodings/win32.h>
#ifdef NEED_DYNAMIC
@ -34,7 +35,7 @@
#endif
#ifdef _WIN32
static char last_dyn_error[512];
static TCHAR last_dyn_error[512];
static void set_dl_error(void)
{
@ -45,11 +46,16 @@ static void set_dl_error(void)
NULL,
err,
MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),
last_dyn_error,
(LPTSTR)last_dyn_error,
sizeof(last_dyn_error) - 1,
NULL) == 0)
snprintf(last_dyn_error, sizeof(last_dyn_error) - 1,
{
WCHAR_TO_CHAR_ALLOC(last_dyn_error, last_dyn_error_str)
snprintf(last_dyn_error_str, sizeof(last_dyn_error) - 1,
"unknown error %lu", err);
if (last_dyn_error_str)
free(last_dyn_error_str);
}
}
#endif
@ -65,8 +71,12 @@ dylib_t dylib_load(const char *path)
{
#ifdef _WIN32
int prevmode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
dylib_t lib = LoadLibrary(path);
dylib_t lib = NULL;
CHAR_TO_WCHAR_ALLOC(path, path_wide)
lib = LoadLibrary(path_wide);
free(path_wide);
SetErrorMode(prevmode);
if (!lib)

View File

@ -24,6 +24,7 @@
#include <stdio.h>
#include <retro_common.h>
#include <encodings/win32.h>
#include <boolean.h>
#include <retro_stat.h>
@ -97,7 +98,9 @@ const char *retro_dirent_get_name(struct RDIR *rdir)
{
#if defined(_WIN32)
memset(rdir->path, 0, sizeof(rdir->path));
utf16_to_char_string(rdir->entry.cFileName, rdir->path, sizeof(rdir->path));
#ifdef UNICODE
utf16_to_char_string((const uint16_t*)rdir->entry.cFileName, rdir->path, sizeof(rdir->path));
#endif
return rdir->path;
#elif defined(VITA) || defined(PSP) || defined(__CELLOS_LV2__)
return rdir->entry.d_name;

View File

@ -0,0 +1,53 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (utf.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _LIBRETRO_ENCODINGS_WIN32_H
#define _LIBRETRO_ENCODINGS_WIN32_H
#ifndef _XBOX
#ifdef _WIN32
#define UNICODE
#include <tchar.h>
#include <wchar.h>
#include <encodings/utf.h>
#endif
#endif
#ifdef UNICODE
#define CHAR_TO_WCHAR_ALLOC(s, ws) \
size_t ws##_size = (s[0] ? strlen(s) : 0) + 1; \
wchar_t *ws = (wchar_t*)calloc(ws##_size, 2); \
if (s[0]) \
MultiByteToWideChar(CP_UTF8, 0, s, -1, ws, ws##_size / sizeof(wchar_t));
#define WCHAR_TO_CHAR_ALLOC(ws, s) \
size_t s##_size = ((ws[0] ? wcslen((const wchar_t*)ws) : 0) / 2) + 1; \
char *s = (char*)calloc(s##_size, 1); \
if (ws[0]) \
utf16_to_char_string((const uint16_t*)ws, s, s##_size);
#else
#define CHAR_TO_WCHAR_ALLOC(s, ws) char *ws = strdup(s);
#define WCHAR_TO_CHAR_ALLOC(ws, s) char *s = strdup(ws);
#endif
#endif

View File

@ -200,14 +200,12 @@ unsigned menu_event(uint64_t input, uint64_t trigger_input)
size_t new_scroll_accel = 0;
menu_input_t *menu_input = NULL;
settings_t *settings = config_get_ptr();
static bool ok_old = false;
static char ok_old = 0;
unsigned menu_ok_btn = settings->input.menu_swap_ok_cancel_buttons ?
RETRO_DEVICE_ID_JOYPAD_B : RETRO_DEVICE_ID_JOYPAD_A;
unsigned menu_cancel_btn = settings->input.menu_swap_ok_cancel_buttons ?
RETRO_DEVICE_ID_JOYPAD_A : RETRO_DEVICE_ID_JOYPAD_B;
bool ok_current = input & UINT64_C(1) << menu_ok_btn;
/* TODO/FIXME - unsafe use of type 'bool' in operation */
char ok_current = input & UINT64_C(1) << menu_ok_btn;
bool ok_trigger = ok_current & ~ok_old;
ok_old = ok_current;

File diff suppressed because it is too large Load Diff

View File

@ -19,6 +19,7 @@
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <encodings/win32.h>
#ifdef _MSC_VER
#pragma comment( lib, "comctl32" )
@ -233,13 +234,8 @@ void shader_dlg_params_reload(void)
for (i = 0; i < (int)shader_info.data->num_parameters; i++)
{
shader_param_ctrl_t*control = &g_shader_dlg.controls[i];
size_t param_desc_wide_size = sizeof(shader_info.data->parameters[i].desc) * 2;
wchar_t param_desc_wide[param_desc_wide_size];
memset(param_desc_wide, 0, sizeof(param_desc_wide));
MultiByteToWideChar(CP_UTF8, 0, shader_info.data->parameters[i].desc, -1, param_desc_wide, sizeof(param_desc_wide) / sizeof(param_desc_wide[0]));
shader_param_ctrl_t *control = &g_shader_dlg.controls[i];
CHAR_TO_WCHAR_ALLOC(shader_info.data->parameters[i].desc, param_desc_wide)
if ((shader_info.data->parameters[i].minimum == 0.0)
&& (shader_info.data->parameters[i].maximum
@ -300,6 +296,8 @@ void shader_dlg_params_reload(void)
}
if (param_desc_wide)
free(param_desc_wide);
}
if (window && g_shader_dlg.separator.hwnd)
@ -534,13 +532,16 @@ static bool win32_browser(
browser_state.title = strdup(title);
browser_state.startdir = strdup(initial_dir);
browser_state.path = strdup(filename);
browser_state.window = owner;
result = browser->open(&browser_state);
if (browser_state.filters)
free(browser_state.filters);
if (browser_state.title)
free(browser_state.title);
if (browser_state.startdir)
free(browser_state.startdir);
if (browser_state.path)
free(browser_state.path);
}

View File

@ -18,6 +18,7 @@
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <encodings/win32.h>
#include <windows.h>
@ -26,23 +27,60 @@
static bool ui_browser_window_win32_core(ui_browser_window_state_t *state, bool save)
{
OPENFILENAME ofn = {};
bool success = true;
#ifdef UNICODE
size_t filters_size = (state->filters ? strlen(state->filters) : 0) + 1;
size_t path_size = strlen(state->path) + 1;
size_t title_size = strlen(state->title) + 1;
size_t startdir_size = strlen(state->startdir) + 1;
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = (HWND)state->window;
wchar_t *filters_wide = (wchar_t*)calloc(filters_size, 2);
wchar_t *path_wide = (wchar_t*)calloc(path_size, 2);
wchar_t *title_wide = (wchar_t*)calloc(title_size, 2);
wchar_t *startdir_wide = (wchar_t*)calloc(startdir_size, 2);
if (state->filters)
MultiByteToWideChar(CP_UTF8, 0, state->filters, -1, filters_wide, filters_size);
if (state->title)
MultiByteToWideChar(CP_UTF8, 0, state->title, -1, title_wide, title_size);
if (state->path)
MultiByteToWideChar(CP_UTF8, 0, state->path, -1, path_wide, path_size);
if (state->startdir)
MultiByteToWideChar(CP_UTF8, 0, state->startdir, -1, startdir_wide, startdir_size);
ofn.lpstrFilter = filters_wide;
ofn.lpstrFile = path_wide;
ofn.lpstrTitle = title_wide;
ofn.lpstrInitialDir = startdir_wide;
#else
ofn.lpstrFilter = state->filters;
ofn.lpstrFile = state->path;
ofn.lpstrTitle = state->title;
ofn.lpstrInitialDir = state->startdir;
ofn.lpstrDefExt = "";
#endif
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = (HWND)state->window;
ofn.lpstrDefExt = TEXT("");
ofn.nMaxFile = PATH_MAX;
ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR;
if ( save && !GetOpenFileName(&ofn))
return false;
success = false;
if (!save && !GetSaveFileName(&ofn))
return false;
success = false;
return true;
#ifdef UNICODE
if (filters_wide)
free(filters_wide);
if (title_wide)
free(title_wide);
if (path_wide)
free(path_wide);
if (startdir_wide)
free(startdir_wide);
#endif
return success;
}
static bool ui_browser_window_win32_open(ui_browser_window_state_t *state)

View File

@ -20,6 +20,8 @@
#include <stdlib.h>
#include <string.h>
#include <encodings/win32.h>
#include <windows.h>
#ifdef _MSC_VER
@ -72,7 +74,10 @@ static void ui_window_win32_set_visible(void *data,
static void ui_window_win32_set_title(void *data, char *buf)
{
ui_window_win32_t *window = (ui_window_win32_t*)data;
SetWindowText(window->hwnd, buf);
CHAR_TO_WCHAR_ALLOC(buf, buf_wide)
SetWindowText(window->hwnd, buf_wide);
if (buf_wide)
free(buf_wide);
}
void ui_window_win32_set_droppable(void *data, bool droppable)