win32: replace wchar_t with WCHAR

WCHAR is more portable. While at least MinGW, Cygwin, and MSVC actually
use 16 bit wchar_t, Midipix will have 32 bit wchar_t. In that context,
using WCHAR instead is more portable.

This affects only non-MinGW parts, so not all uses of wchar_t need to
be changed. For example, terminal-win.c won't be used on Midipix at
all. (Most of io.c won't either, so the search & replace here is more
than necessary, but also not harmful.)

(Midipix is not useable yet, so this is just preparation.)
This commit is contained in:
wm4 2015-07-28 23:59:17 +02:00
parent 7d889fbdd0
commit 0b52ac8a78
7 changed files with 33 additions and 32 deletions

View File

@ -174,7 +174,7 @@ static BOOL CALLBACK DirectSoundEnum(LPGUID guid, LPCSTR desc, LPCSTR module,
} }
char *guidstr = talloc_strdup(NULL, ""); char *guidstr = talloc_strdup(NULL, "");
if (guid) { if (guid) {
wchar_t guidwstr[80] = {0}; WCHAR guidwstr[80] = {0};
StringFromGUID2(guid, guidwstr, MP_ARRAY_SIZE(guidwstr)); StringFromGUID2(guid, guidwstr, MP_ARRAY_SIZE(guidwstr));
char *nstr = mp_to_utf8(NULL, guidwstr); char *nstr = mp_to_utf8(NULL, guidwstr);
if (nstr) { if (nstr) {

View File

@ -25,6 +25,7 @@
#include <endpointvolume.h> #include <endpointvolume.h>
#include <mmdeviceapi.h> #include <mmdeviceapi.h>
#include <avrt.h> #include <avrt.h>
#include <windows.h>
#include "audio/out/ao_wasapi.h" #include "audio/out/ao_wasapi.h"
#include "audio/out/ao_wasapi_utils.h" #include "audio/out/ao_wasapi_utils.h"
@ -344,9 +345,9 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
return CONTROL_TRUE; return CONTROL_TRUE;
case AOCONTROL_UPDATE_STREAM_TITLE: { case AOCONTROL_UPDATE_STREAM_TITLE: {
MP_VERBOSE(state, "Updating stream title to \"%s\"\n", (char*)arg); MP_VERBOSE(state, "Updating stream title to \"%s\"\n", (char*)arg);
wchar_t *title = mp_from_utf8(NULL, (char*)arg); WCHAR *title = mp_from_utf8(NULL, (char*)arg);
wchar_t *tmp = NULL; WCHAR *tmp = NULL;
/* There is a weird race condition in the IAudioSessionControl itself -- /* There is a weird race condition in the IAudioSessionControl itself --
it seems that *sometimes* the SetDisplayName does not take effect and it still shows it seems that *sometimes* the SetDisplayName does not take effect and it still shows

View File

@ -612,7 +612,7 @@ exit_label:
} }
static HRESULT init_session_display(struct wasapi_state *state) { static HRESULT init_session_display(struct wasapi_state *state) {
wchar_t path[MAX_PATH+12] = {0}; WCHAR path[MAX_PATH+12] = {0};
HRESULT hr = IAudioClient_GetService(state->pAudioClient, HRESULT hr = IAudioClient_GetService(state->pAudioClient,
&IID_IAudioSessionControl, &IID_IAudioSessionControl,

View File

@ -95,17 +95,17 @@ int mp_make_wakeup_pipe(int pipes[2])
//copied and modified from libav //copied and modified from libav
//http://git.libav.org/?p=libav.git;a=blob;f=libavformat/os_support.c;h=a0fcd6c9ba2be4b0dbcc476f6c53587345cc1152;hb=HEADl30 //http://git.libav.org/?p=libav.git;a=blob;f=libavformat/os_support.c;h=a0fcd6c9ba2be4b0dbcc476f6c53587345cc1152;hb=HEADl30
wchar_t *mp_from_utf8(void *talloc_ctx, const char *s) WCHAR *mp_from_utf8(void *talloc_ctx, const char *s)
{ {
int count = MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0); int count = MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0);
if (count <= 0) if (count <= 0)
abort(); abort();
wchar_t *ret = talloc_array(talloc_ctx, wchar_t, count); WCHAR *ret = talloc_array(talloc_ctx, WCHAR, count);
MultiByteToWideChar(CP_UTF8, 0, s, -1, ret, count); MultiByteToWideChar(CP_UTF8, 0, s, -1, ret, count);
return ret; return ret;
} }
char *mp_to_utf8(void *talloc_ctx, const wchar_t *s) char *mp_to_utf8(void *talloc_ctx, const WCHAR *s)
{ {
int count = WideCharToMultiByte(CP_UTF8, 0, s, -1, NULL, 0, NULL, NULL); int count = WideCharToMultiByte(CP_UTF8, 0, s, -1, NULL, 0, NULL, NULL);
if (count <= 0) if (count <= 0)
@ -141,7 +141,7 @@ static void copy_stat(struct mp_stat *dst, struct _stat64 *src)
int mp_stat(const char *path, struct mp_stat *buf) int mp_stat(const char *path, struct mp_stat *buf)
{ {
struct _stat64 buf_; struct _stat64 buf_;
wchar_t *wpath = mp_from_utf8(NULL, path); WCHAR *wpath = mp_from_utf8(NULL, path);
int res = _wstat64(wpath, &buf_); int res = _wstat64(wpath, &buf_);
talloc_free(wpath); talloc_free(wpath);
copy_stat(buf, &buf_); copy_stat(buf, &buf_);
@ -237,7 +237,7 @@ int mp_open(const char *filename, int oflag, ...)
mode = va_arg(va, int); mode = va_arg(va, int);
va_end(va); va_end(va);
} }
wchar_t *wpath = mp_from_utf8(NULL, filename); WCHAR *wpath = mp_from_utf8(NULL, filename);
int res = _wopen(wpath, oflag, mode); int res = _wopen(wpath, oflag, mode);
talloc_free(wpath); talloc_free(wpath);
return res; return res;
@ -250,16 +250,16 @@ int mp_creat(const char *filename, int mode)
FILE *mp_fopen(const char *filename, const char *mode) FILE *mp_fopen(const char *filename, const char *mode)
{ {
wchar_t *wpath = mp_from_utf8(NULL, filename); WCHAR *wpath = mp_from_utf8(NULL, filename);
wchar_t *wmode = mp_from_utf8(wpath, mode); WCHAR *wmode = mp_from_utf8(wpath, mode);
FILE *res = _wfopen(wpath, wmode); FILE *res = _wfopen(wpath, wmode);
talloc_free(wpath); talloc_free(wpath);
return res; return res;
} }
// Windows' MAX_PATH/PATH_MAX/FILENAME_MAX is fixed to 260, but this limit // Windows' MAX_PATH/PATH_MAX/FILENAME_MAX is fixed to 260, but this limit
// applies to unicode paths encoded with wchar_t (2 bytes on Windows). The UTF-8 // applies to unicode paths encoded with WCHAR (2 bytes). The UTF-8
// version could end up bigger in memory. In the worst case each wchar_t is // version could end up bigger in memory. In the worst case each WCHAR is
// encoded to 3 bytes in UTF-8, so in the worst case we have: // encoded to 3 bytes in UTF-8, so in the worst case we have:
// wcslen(wpath) * 3 <= strlen(utf8path) // wcslen(wpath) * 3 <= strlen(utf8path)
// Thus we need MP_PATH_MAX as the UTF-8/char version of PATH_MAX. // Thus we need MP_PATH_MAX as the UTF-8/char version of PATH_MAX.
@ -273,7 +273,7 @@ struct mp_dir {
union { union {
struct dirent dirent; struct dirent dirent;
// dirent has space only for FILENAME_MAX bytes. _wdirent has space for // dirent has space only for FILENAME_MAX bytes. _wdirent has space for
// FILENAME_MAX wchar_t, which might end up bigger as UTF-8 in some // FILENAME_MAX WCHAR, which might end up bigger as UTF-8 in some
// cases. Guarantee we can always hold _wdirent.d_name converted to // cases. Guarantee we can always hold _wdirent.d_name converted to
// UTF-8 (see MP_PATH_MAX). // UTF-8 (see MP_PATH_MAX).
// This works because dirent.d_name is the last member of dirent. // This works because dirent.d_name is the last member of dirent.
@ -283,7 +283,7 @@ struct mp_dir {
DIR* mp_opendir(const char *path) DIR* mp_opendir(const char *path)
{ {
wchar_t *wpath = mp_from_utf8(NULL, path); WCHAR *wpath = mp_from_utf8(NULL, path);
_WDIR *wdir = _wopendir(wpath); _WDIR *wdir = _wopendir(wpath);
talloc_free(wpath); talloc_free(wpath);
if (!wdir) if (!wdir)
@ -321,7 +321,7 @@ int mp_closedir(DIR *dir)
int mp_mkdir(const char *path, int mode) int mp_mkdir(const char *path, int mode)
{ {
wchar_t *wpath = mp_from_utf8(NULL, path); WCHAR *wpath = mp_from_utf8(NULL, path);
int res = _wmkdir(wpath); int res = _wmkdir(wpath);
talloc_free(wpath); talloc_free(wpath);
return res; return res;
@ -330,10 +330,10 @@ int mp_mkdir(const char *path, int mode)
FILE *mp_tmpfile(void) FILE *mp_tmpfile(void)
{ {
// Reserve a file name in the format %TMP%\mpvXXXX.TMP // Reserve a file name in the format %TMP%\mpvXXXX.TMP
wchar_t tmp_path[MAX_PATH + 1]; WCHAR tmp_path[MAX_PATH + 1];
if (!GetTempPathW(MAX_PATH + 1, tmp_path)) if (!GetTempPathW(MAX_PATH + 1, tmp_path))
return NULL; return NULL;
wchar_t tmp_name[MAX_PATH + 1]; WCHAR tmp_name[MAX_PATH + 1];
if (!GetTempFileNameW(tmp_path, L"mpv", 0, tmp_name)) if (!GetTempFileNameW(tmp_path, L"mpv", 0, tmp_name))
return NULL; return NULL;
@ -379,7 +379,7 @@ static void init_getenv(void)
{ {
if (utf8_environ_ctx) if (utf8_environ_ctx)
return; return;
wchar_t *wenv = GetEnvironmentStringsW(); WCHAR *wenv = GetEnvironmentStringsW();
if (!wenv) if (!wenv)
return; return;
utf8_environ_ctx = talloc_new(NULL); utf8_environ_ctx = talloc_new(NULL);

View File

@ -49,9 +49,9 @@ int mp_make_cloexec_pipe(int pipes[2]);
int mp_make_wakeup_pipe(int pipes[2]); int mp_make_wakeup_pipe(int pipes[2]);
#ifdef _WIN32 #ifdef _WIN32
#include <wchar.h> #include <windows.h>
wchar_t *mp_from_utf8(void *talloc_ctx, const char *s); WCHAR *mp_from_utf8(void *talloc_ctx, const char *s);
char *mp_to_utf8(void *talloc_ctx, const wchar_t *s); char *mp_to_utf8(void *talloc_ctx, const WCHAR *s);
#endif #endif
#ifdef __CYGWIN__ #ifdef __CYGWIN__

View File

@ -31,7 +31,7 @@ static char *portable_path;
static char *mp_get_win_exe_dir(void *talloc_ctx) static char *mp_get_win_exe_dir(void *talloc_ctx)
{ {
wchar_t w_exedir[MAX_PATH + 1] = {0}; WCHAR w_exedir[MAX_PATH + 1] = {0};
int len = (int)GetModuleFileNameW(NULL, w_exedir, MAX_PATH); int len = (int)GetModuleFileNameW(NULL, w_exedir, MAX_PATH);
int imax = 0; int imax = 0;
@ -54,7 +54,7 @@ static char *mp_get_win_exe_subdir(void *ta_ctx, const char *name)
static char *mp_get_win_shell_dir(void *talloc_ctx, int folder) static char *mp_get_win_shell_dir(void *talloc_ctx, int folder)
{ {
wchar_t w_appdir[MAX_PATH + 1] = {0}; WCHAR w_appdir[MAX_PATH + 1] = {0};
if (SHGetFolderPathW(NULL, folder|CSIDL_FLAG_CREATE, NULL, if (SHGetFolderPathW(NULL, folder|CSIDL_FLAG_CREATE, NULL,
SHGFP_TYPE_CURRENT, w_appdir) != S_OK) SHGFP_TYPE_CURRENT, w_appdir) != S_OK)

View File

@ -42,7 +42,7 @@
#include "misc/rendezvous.h" #include "misc/rendezvous.h"
#include "talloc.h" #include "talloc.h"
static const wchar_t classname[] = L"mpv"; static const WCHAR classname[] = L"mpv";
static __thread struct vo_w32_state *w32_thread_context; static __thread struct vo_w32_state *w32_thread_context;
@ -237,7 +237,7 @@ static HRESULT STDMETHODCALLTYPE DropTarget_Drop(IDropTarget* This,
UINT nrecvd_files = 0; UINT nrecvd_files = 0;
for (UINT i = 0; i < numFiles; i++) { for (UINT i = 0; i < numFiles; i++) {
UINT len = DragQueryFileW(hDrop, i, NULL, 0); UINT len = DragQueryFileW(hDrop, i, NULL, 0);
wchar_t* buf = talloc_array(NULL, wchar_t, len + 1); WCHAR* buf = talloc_array(NULL, WCHAR, len + 1);
if (DragQueryFileW(hDrop, i, buf, len + 1) == len) { if (DragQueryFileW(hDrop, i, buf, len + 1) == len) {
char* fname = mp_to_utf8(files, buf); char* fname = mp_to_utf8(files, buf);
@ -400,12 +400,12 @@ static int mod_state(struct vo_w32_state *w32)
return res; return res;
} }
static int decode_surrogate_pair(wchar_t lead, wchar_t trail) static int decode_surrogate_pair(WCHAR lead, WCHAR trail)
{ {
return 0x10000 + (((lead & 0x3ff) << 10) | (trail & 0x3ff)); return 0x10000 + (((lead & 0x3ff) << 10) | (trail & 0x3ff));
} }
static int decode_utf16(struct vo_w32_state *w32, wchar_t c) static int decode_utf16(struct vo_w32_state *w32, WCHAR c)
{ {
// Decode UTF-16, keeping state in w32->high_surrogate // Decode UTF-16, keeping state in w32->high_surrogate
if (IS_HIGH_SURROGATE(c)) { if (IS_HIGH_SURROGATE(c)) {
@ -435,7 +435,7 @@ static void clear_keyboard_buffer(void)
static const UINT vkey = VK_DECIMAL; static const UINT vkey = VK_DECIMAL;
static const BYTE keys[256] = { 0 }; static const BYTE keys[256] = { 0 };
UINT scancode = MapVirtualKey(vkey, MAPVK_VK_TO_VSC); UINT scancode = MapVirtualKey(vkey, MAPVK_VK_TO_VSC);
wchar_t buf[10]; WCHAR buf[10];
int ret = 0; int ret = 0;
// Use the method suggested by Michael Kaplan to clear any pending dead // Use the method suggested by Michael Kaplan to clear any pending dead
@ -453,7 +453,7 @@ static int to_unicode(UINT vkey, UINT scancode, const BYTE keys[256])
// Make the buffer 10 code units long to be safe, same as here: // Make the buffer 10 code units long to be safe, same as here:
// https://web.archive.org/web/20101013215215/http://blogs.msdn.com/b/michkap/archive/2006/03/24/559169.aspx // https://web.archive.org/web/20101013215215/http://blogs.msdn.com/b/michkap/archive/2006/03/24/559169.aspx
wchar_t buf[10] = { 0 }; WCHAR buf[10] = { 0 };
// Dead keys aren't useful for key shortcuts, so clear the keyboard state // Dead keys aren't useful for key shortcuts, so clear the keyboard state
clear_keyboard_buffer(); clear_keyboard_buffer();
@ -541,7 +541,7 @@ static void handle_key_up(struct vo_w32_state *w32, UINT vkey, UINT scancode)
} }
} }
static bool handle_char(struct vo_w32_state *w32, wchar_t wc) static bool handle_char(struct vo_w32_state *w32, WCHAR wc)
{ {
int c = decode_utf16(w32, wc); int c = decode_utf16(w32, wc);
@ -1325,7 +1325,7 @@ static int gui_thread_control(struct vo_w32_state *w32, int request, void *arg)
SetThreadExecutionState(ES_CONTINUOUS); SetThreadExecutionState(ES_CONTINUOUS);
return VO_TRUE; return VO_TRUE;
case VOCTRL_UPDATE_WINDOW_TITLE: { case VOCTRL_UPDATE_WINDOW_TITLE: {
wchar_t *title = mp_from_utf8(NULL, (char *)arg); WCHAR *title = mp_from_utf8(NULL, (char *)arg);
SetWindowTextW(w32->window, title); SetWindowTextW(w32->window, title);
talloc_free(title); talloc_free(title);
return VO_TRUE; return VO_TRUE;