win32: revert wchar_t changes

Revert "win32: more wchar_t -> WCHAR replacements"
Revert "win32: replace wchar_t with WCHAR"

Doing a "partial" port of this makes no sense anymore from my
perspective. Revert the changes, as they're confusing without
context, maintenance, and progress. These changes were a bit
premature anyway, and might actually cause other issues
(locale neutrality etc. as it was pointed out).
This commit is contained in:
wm4 2015-08-01 20:51:52 +02:00
parent fefac2c941
commit 41101c2996
13 changed files with 48 additions and 50 deletions

View File

@ -174,7 +174,7 @@ static BOOL CALLBACK DirectSoundEnum(LPGUID guid, LPCSTR desc, LPCSTR module,
}
char *guidstr = talloc_strdup(NULL, "");
if (guid) {
WCHAR guidwstr[80] = {0};
wchar_t guidwstr[80] = {0};
StringFromGUID2(guid, guidwstr, MP_ARRAY_SIZE(guidwstr));
char *nstr = mp_to_utf8(NULL, guidwstr);
if (nstr) {
@ -227,7 +227,7 @@ static int LoadDirectSound(struct ao *ao)
struct priv *p = ao->priv;
// initialize directsound
p->hdsound_dll = LoadLibraryW(u"DSOUND.DLL");
p->hdsound_dll = LoadLibrary(L"DSOUND.DLL");
if (p->hdsound_dll == NULL) {
MP_ERR(ao, "cannot load DSOUND.DLL\n");
return 0;

View File

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

View File

@ -67,7 +67,7 @@ static HRESULT STDMETHODCALLTYPE sIMMNotificationClient_OnDeviceStateChanged(
if (change->is_hotplug) {
MP_VERBOSE(ao, "OnDeviceStateChanged triggered: sending hotplug event\n");
ao_hotplug_event(ao);
} else if (pwstrDeviceId && !lstrcmpW(pwstrDeviceId, change->monitored)) {
} else if (pwstrDeviceId && !wcscmp(pwstrDeviceId, change->monitored)) {
switch (dwNewState) {
case DEVICE_STATE_DISABLED:
case DEVICE_STATE_NOTPRESENT:
@ -110,7 +110,7 @@ static HRESULT STDMETHODCALLTYPE sIMMNotificationClient_OnDeviceRemoved(
if (change->is_hotplug) {
MP_VERBOSE(ao, "OnDeviceRemoved triggered: sending hotplug event\n");
ao_hotplug_event(ao);
} else if (pwstrDeviceId && !lstrcmpW(pwstrDeviceId, change->monitored)) {
} else if (pwstrDeviceId && !wcscmp(pwstrDeviceId, change->monitored)) {
MP_VERBOSE(ao, "OnDeviceRemoved triggered for device %S: "
"requesting ao reload\n", pwstrDeviceId);
ao_request_reload(ao);
@ -144,7 +144,7 @@ static HRESULT STDMETHODCALLTYPE sIMMNotificationClient_OnDefaultDeviceChanged(
}
/* don't reload if already on the new default */
if (pwstrDeviceId && !lstrcmpW(pwstrDeviceId, change->monitored)) {
if (pwstrDeviceId && !wcscmp(pwstrDeviceId, change->monitored)) {
MP_VERBOSE(ao, "OnDefaultDeviceChanged triggered: "
"already using default device, no reload required\n");
return S_OK;
@ -167,7 +167,7 @@ static HRESULT STDMETHODCALLTYPE sIMMNotificationClient_OnPropertyValueChanged(
struct ao *ao = change->ao;
if (!change->is_hotplug && pwstrDeviceId &&
!lstrcmpW(pwstrDeviceId, change->monitored))
!wcscmp(pwstrDeviceId, change->monitored))
{
MP_VERBOSE(ao, "OnPropertyValueChanged triggered on device %S\n",
pwstrDeviceId);

View File

@ -34,7 +34,7 @@
#include "osdep/io.h"
#include "osdep/timer.h"
#define MIXER_DEFAULT_LABEL u"mpv - video player"
#define MIXER_DEFAULT_LABEL L"mpv - video player"
DEFINE_PROPERTYKEY(mp_PKEY_Device_FriendlyName,
0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20,
@ -190,7 +190,7 @@ bool wasapi_fill_VistaBlob(wasapi_state *state)
{
if (!state)
goto exit_label;
state->VistaBlob.hAvrt = LoadLibraryW(u"avrt.dll");
state->VistaBlob.hAvrt = LoadLibraryW(L"avrt.dll");
if (!state->VistaBlob.hAvrt)
goto exit_label;
@ -612,7 +612,7 @@ exit_label:
}
static HRESULT init_session_display(struct wasapi_state *state) {
WCHAR path[MAX_PATH+12] = {0};
wchar_t path[MAX_PATH+12] = {0};
HRESULT hr = IAudioClient_GetService(state->pAudioClient,
&IID_IAudioSessionControl,
@ -620,7 +620,7 @@ static HRESULT init_session_display(struct wasapi_state *state) {
EXIT_ON_ERROR(hr);
GetModuleFileNameW(NULL, path, MAX_PATH);
lstrcatW(path, u",-IDI_ICON1");
lstrcatW(path, L",-IDI_ICON1");
hr = IAudioSessionControl_SetDisplayName(state->pSessionControl, MIXER_DEFAULT_LABEL, NULL);
EXIT_ON_ERROR(hr);
@ -725,7 +725,7 @@ reinit:
if (state->VistaBlob.hAvrt) {
state->hTask =
state->VistaBlob.pAvSetMmThreadCharacteristicsW(u"Pro Audio", &state->taskIndex);
state->VistaBlob.pAvSetMmThreadCharacteristicsW(L"Pro Audio", &state->taskIndex);
}
MP_VERBOSE(state, "Format fixed. Using %lld byte buffer block size\n",

View File

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

View File

@ -31,7 +31,7 @@ static char *portable_path;
static char *mp_get_win_exe_dir(void *talloc_ctx)
{
WCHAR w_exedir[MAX_PATH + 1] = {0};
wchar_t w_exedir[MAX_PATH + 1] = {0};
int len = (int)GetModuleFileNameW(NULL, w_exedir, MAX_PATH);
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)
{
WCHAR w_appdir[MAX_PATH + 1] = {0};
wchar_t w_appdir[MAX_PATH + 1] = {0};
if (SHGetFolderPathW(NULL, folder|CSIDL_FLAG_CREATE, NULL,
SHGFP_TYPE_CURRENT, w_appdir) != S_OK)

View File

@ -112,7 +112,7 @@ static int create_overlapped_pipe(HANDLE *read, HANDLE *write)
unsigned long id = atomic_fetch_add(&counter, 1);
unsigned pid = GetCurrentProcessId();
wchar_t buf[36];
swprintf(buf, sizeof(buf), u"\\\\.\\pipe\\mpv-anon-%08x-%08lx", pid, id);
swprintf(buf, sizeof(buf), L"\\\\.\\pipe\\mpv-anon-%08x-%08lx", pid, id);
// The function for creating anonymous pipes (CreatePipe) can't create
// overlapped pipes, so instead, use a named pipe with a unique name

View File

@ -198,7 +198,7 @@ static bool check_stream_network(int fd)
// NtQueryVolumeInformationFile is an internal Windows function. It has
// been present since Windows XP, however this code should fail gracefully
// if it's removed from a future version of Windows.
HMODULE ntdll = GetModuleHandleW(u"ntdll.dll");
HMODULE ntdll = GetModuleHandleW(L"ntdll.dll");
pNtQueryVolumeInformationFile = (NTSTATUS (NTAPI*)(HANDLE,
PIO_STATUS_BLOCK, PVOID, ULONG, FS_INFORMATION_CLASS))
GetProcAddress(ntdll, "NtQueryVolumeInformationFile");

View File

@ -355,7 +355,7 @@ static int create_device(struct lavc_ctx *s)
}
}
ctx->d3dlib = LoadLibraryW(u"d3d9.dll");
ctx->d3dlib = LoadLibrary(L"d3d9.dll");
if (!ctx->d3dlib) {
MP_ERR(ctx, "Failed to load D3D9 library\n");
goto fail;
@ -423,7 +423,7 @@ static int dxva2_init(struct lavc_ctx *s)
ctx->deviceHandle = INVALID_HANDLE_VALUE;
ctx->dxva2lib = LoadLibraryW(u"dxva2.dll");
ctx->dxva2lib = LoadLibrary(L"dxva2.dll");
if (!ctx->dxva2lib) {
MP_ERR(ctx, "Failed to load DXVA2 library\n");
goto fail;

View File

@ -84,7 +84,7 @@ static void *w32gpa(const GLubyte *procName)
void *res = wglGetProcAddress(procName);
if (res)
return res;
oglmod = GetModuleHandleW(u"opengl32.dll");
oglmod = GetModuleHandle(L"opengl32.dll");
return GetProcAddress(oglmod, procName);
}
@ -208,7 +208,7 @@ static void create_ctx(void *ptr)
if (!w32_ctx->context)
create_context_w32_old(ctx);
w32_ctx->dwmapi_dll = LoadLibraryW(u"Dwmapi.dll");
w32_ctx->dwmapi_dll = LoadLibrary(L"Dwmapi.dll");
if (w32_ctx->dwmapi_dll)
w32_ctx->dwmflush = (DwmFlush_t)GetProcAddress(w32_ctx->dwmapi_dll, "DwmFlush");

View File

@ -42,7 +42,7 @@
#include "misc/rendezvous.h"
#include "talloc.h"
static const WCHAR classname[] = u"mpv";
static const wchar_t classname[] = L"mpv";
static __thread struct vo_w32_state *w32_thread_context;
@ -237,7 +237,7 @@ static HRESULT STDMETHODCALLTYPE DropTarget_Drop(IDropTarget* This,
UINT nrecvd_files = 0;
for (UINT i = 0; i < numFiles; i++) {
UINT len = DragQueryFileW(hDrop, i, NULL, 0);
WCHAR* buf = talloc_array(NULL, WCHAR, len + 1);
wchar_t* buf = talloc_array(NULL, wchar_t, len + 1);
if (DragQueryFileW(hDrop, i, buf, len + 1) == len) {
char* fname = mp_to_utf8(files, buf);
@ -400,12 +400,12 @@ static int mod_state(struct vo_w32_state *w32)
return res;
}
static int decode_surrogate_pair(WCHAR lead, WCHAR trail)
static int decode_surrogate_pair(wchar_t lead, wchar_t trail)
{
return 0x10000 + (((lead & 0x3ff) << 10) | (trail & 0x3ff));
}
static int decode_utf16(struct vo_w32_state *w32, WCHAR c)
static int decode_utf16(struct vo_w32_state *w32, wchar_t c)
{
// Decode UTF-16, keeping state in w32->high_surrogate
if (IS_HIGH_SURROGATE(c)) {
@ -435,7 +435,7 @@ static void clear_keyboard_buffer(void)
static const UINT vkey = VK_DECIMAL;
static const BYTE keys[256] = { 0 };
UINT scancode = MapVirtualKey(vkey, MAPVK_VK_TO_VSC);
WCHAR buf[10];
wchar_t buf[10];
int ret = 0;
// 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:
// https://web.archive.org/web/20101013215215/http://blogs.msdn.com/b/michkap/archive/2006/03/24/559169.aspx
WCHAR buf[10] = { 0 };
wchar_t buf[10] = { 0 };
// Dead keys aren't useful for key shortcuts, so clear the keyboard state
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 wc)
static bool handle_char(struct vo_w32_state *w32, wchar_t wc)
{
int c = decode_utf16(w32, wc);
@ -1129,7 +1129,7 @@ static void *gui_thread(void *ptr)
.style = CS_HREDRAW | CS_VREDRAW,
.lpfnWndProc = WndProc,
.hInstance = hInstance,
.hIcon = LoadIconW(hInstance, u"IDI_ICON1"),
.hIcon = LoadIconW(hInstance, L"IDI_ICON1"),
.hCursor = LoadCursor(NULL, IDC_ARROW),
.lpszClassName = classname,
};
@ -1325,7 +1325,7 @@ static int gui_thread_control(struct vo_w32_state *w32, int request, void *arg)
SetThreadExecutionState(ES_CONTINUOUS);
return VO_TRUE;
case VOCTRL_UPDATE_WINDOW_TITLE: {
WCHAR *title = mp_from_utf8(NULL, (char *)arg);
wchar_t *title = mp_from_utf8(NULL, (char *)arg);
SetWindowTextW(w32->window, title);
talloc_free(title);
return VO_TRUE;

View File

@ -51,7 +51,6 @@ def __add_clang_flags__(ctx):
def __add_mswin_flags__(ctx):
ctx.env.CFLAGS += ['-D_WIN32_WINNT=0x600', '-DUNICODE', '-DCOBJMACROS',
'-U__STRICT_ANSI__']
ctx.env.CFLAGS += ['-std=c11']
def __add_mingw_flags__(ctx):
__add_mswin_flags__(ctx)