From ec9aab2c467b0556f2ef679ef912055c6a77c2fc Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Fri, 3 Mar 2023 05:09:20 +0100 Subject: [PATCH] mmdevapi: Use UTF-16 for client name in "test_connect_params" and "create_stream_params" structs. The conversion to another encoding is now up to the unixlib. --- dlls/mmdevapi/unixlib.h | 4 ++-- dlls/winepulse.drv/mmdevdrv.c | 23 ++++++----------------- dlls/winepulse.drv/pulse.c | 21 +++++++++++++++++++-- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/dlls/mmdevapi/unixlib.h b/dlls/mmdevapi/unixlib.h index ea0d2f9c4b9..37b4c53cb35 100644 --- a/dlls/mmdevapi/unixlib.h +++ b/dlls/mmdevapi/unixlib.h @@ -53,7 +53,7 @@ struct get_endpoint_ids_params struct create_stream_params { - const char *name; + const WCHAR *name; const char *device; EDataFlow flow; AUDCLNT_SHAREMODE share; @@ -219,7 +219,7 @@ struct set_event_handle_params struct test_connect_params { - const char *name; + const WCHAR *name; enum driver_priority priority; }; diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c index 99dbe24c82f..9a6939e959c 100644 --- a/dlls/winepulse.drv/mmdevdrv.c +++ b/dlls/winepulse.drv/mmdevdrv.c @@ -23,6 +23,7 @@ #include #include +#include #include "windef.h" #include "winbase.h" @@ -247,11 +248,9 @@ static BOOL query_productname(void *data, LANGANDCODEPAGE *lang, LPVOID *buffer, return VerQueryValueW(data, pn, buffer, len) && *len; } -static char *get_application_name(BOOL query_app_name) +static WCHAR *get_application_name(BOOL query_app_name) { WCHAR path[MAX_PATH], *name; - char *str = NULL; - size_t len; GetModuleFileNameW(NULL, path, ARRAY_SIZE(path)); @@ -327,15 +326,9 @@ static char *get_application_name(BOOL query_app_name) } } - if (found) { - len = WideCharToMultiByte(CP_UTF8, 0, productname, -1, NULL, 0, NULL, NULL); - str = malloc(len); - if (str) WideCharToMultiByte(CP_UTF8, 0, productname, -1, str, len, NULL, NULL); - } - skip: free(data); - if (str) return str; + if (found) return wcsdup(productname); } name = wcsrchr(path, '\\'); @@ -343,11 +336,7 @@ static char *get_application_name(BOOL query_app_name) name = path; else name++; - len = WideCharToMultiByte(CP_UTF8, 0, name, -1, NULL, 0, NULL, NULL); - if (!(str = malloc(len))) - return NULL; - WideCharToMultiByte(CP_UNIXCP, 0, name, -1, str, len, NULL, NULL); - return str; + return wcsdup(name); } static DWORD WINAPI pulse_timer_cb(void *user) @@ -481,7 +470,7 @@ end: int WINAPI AUDDRV_GetPriority(void) { struct test_connect_params params; - char *name; + WCHAR *name; params.name = name = get_application_name(FALSE); pulse_call(test_connect, ¶ms); @@ -817,7 +806,7 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, struct create_stream_params params; unsigned int i, channel_count; stream_handle stream; - char *name; + WCHAR *name; HRESULT hr; TRACE("(%p)->(%x, %lx, %s, %s, %p, %s)\n", This, mode, flags, diff --git a/dlls/winepulse.drv/pulse.c b/dlls/winepulse.drv/pulse.c index 900b77415a8..28afb5b788d 100644 --- a/dlls/winepulse.drv/pulse.c +++ b/dlls/winepulse.drv/pulse.c @@ -196,6 +196,14 @@ static int muldiv(int a, int b, int c) return ret; } +static char *wstr_to_str(const WCHAR *wstr) +{ + const int len = wcslen(wstr); + char *str = malloc(len * 3 + 1); + ntdll_wcstoumbs(wstr, len + 1, str, len * 3 + 1, FALSE); + return str; +} + /* Following pulseaudio design here, mainloop has the lock taken whenever * it is handling something for pulse, and the lock is required whenever * doing any pa_* call that can affect the state in any way @@ -765,13 +773,17 @@ static NTSTATUS pulse_test_connect(void *args) PhysDevice *dev; pa_operation *o; int ret; + char *name = wstr_to_str(params->name); pulse_lock(); pulse_ml = pa_mainloop_new(); pa_mainloop_set_poll_func(pulse_ml, pulse_poll_func, NULL); - pulse_ctx = pa_context_new(pa_mainloop_get_api(pulse_ml), params->name); + pulse_ctx = pa_context_new(pa_mainloop_get_api(pulse_ml), name); + + free(name); + if (!pulse_ctx) { ERR("Failed to create context\n"); pa_mainloop_free(pulse_ml); @@ -1104,10 +1116,15 @@ static NTSTATUS pulse_create_stream(void *args) struct pulse_stream *stream; unsigned int i, bufsize_bytes; HRESULT hr; + char *name = wstr_to_str(params->name); pulse_lock(); - if (FAILED(params->result = pulse_connect(params->name))) + params->result = pulse_connect(name); + + free(name); + + if (FAILED(params->result)) { pulse_unlock(); return STATUS_SUCCESS; -- 2.11.4.GIT