From d9d866e5c5a83510bc72afcee7918fd121cde00e Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Thu, 9 Nov 2023 20:36:28 -0800 Subject: [PATCH] patch unsupported modes of WideCharToMultiByte --- wrappers/kernel32.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/wrappers/kernel32.c b/wrappers/kernel32.c index e832121..a4e179f 100644 --- a/wrappers/kernel32.c +++ b/wrappers/kernel32.c @@ -351,7 +351,18 @@ BOOL WINAPI CORKEL32_FreeEnvironmentStringsW(LPWSTR param_0) INT WINAPI CORKEL32_WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, INT cchWideChar, LPSTR lpMultiByteStr, INT cbMultiByte, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar) { INT r; - dwFlags = 0; + + // Windows 95 doesn't support these flags and will throw an error if they're specified + const unsigned short WC_ERR_INVALID_CHARS = 0x80; + const unsigned short WC_NO_BEST_FIT_CHARS = 0x400; + dwFlags &= ~WC_NO_BEST_FIT_CHARS; + dwFlags &= ~WC_ERR_INVALID_CHARS; + + // Windows 95 doesn't appear to support UTF-8 conversion, so we fallback to the default multibyte codepage + if (CodePage == CP_UTF8) { + CodePage = CP_ACP; + } + r = WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, lpMultiByteStr, cbMultiByte, lpDefaultChar, lpUsedDefaultChar); Trace(TRACE_PASSTHROUGH, "WideCharToMultiByte, r = %i, CodePage = %u, dwFlags = %u", r, CodePage, dwFlags); return r;