From 50578dabaad6981ac2fb854bca77ed8527071c94 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 28 Mar 2025 14:15:41 +0100 Subject: [PATCH] unicode: Remove deprecated MB_PRECOMPOSED Online documentation suggests it should be used as default (for the most of code pages), SDK source code says it's deprecated. Let's remove it and see how things work. Reference: https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar Signed-off-by: Simon Rozman --- include/stdex/unicode.hpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/include/stdex/unicode.hpp b/include/stdex/unicode.hpp index 95413579c..1fb4f5fbb 100644 --- a/include/stdex/unicode.hpp +++ b/include/stdex/unicode.hpp @@ -197,10 +197,9 @@ namespace stdex stdex_assert(count_src < INT_MAX || count_src == SIZE_MAX); // Try to convert to stack buffer first. - DWORD dwFlagsMBWC = static_cast(m_from_wincp) < CP_UTF7 ? MB_PRECOMPOSED : 0; WCHAR szStackBuffer[1024 / sizeof(WCHAR)]; #pragma warning(suppress: 6387) // Testing indicates src may be NULL when count_src is also 0. Is SAL of the lpMultiByteStr parameter wrong? - int cch = MultiByteToWideChar(static_cast(m_from_wincp), dwFlagsMBWC, reinterpret_cast(src), static_cast(count_src), szStackBuffer, _countof(szStackBuffer)); + int cch = MultiByteToWideChar(static_cast(m_from_wincp), 0, reinterpret_cast(src), static_cast(count_src), szStackBuffer, _countof(szStackBuffer)); if (cch) { // Append from stack. dst.append(reinterpret_cast(szStackBuffer), count_src != SIZE_MAX ? wcsnlen(szStackBuffer, cch) : static_cast(cch) - 1); @@ -209,10 +208,10 @@ namespace stdex DWORD dwResult = GetLastError(); if (dwResult == ERROR_INSUFFICIENT_BUFFER) { // Query the required output size. Allocate buffer. Then convert again. - cch = MultiByteToWideChar(static_cast(m_from_wincp), dwFlagsMBWC, reinterpret_cast(src), static_cast(count_src), NULL, 0); + cch = MultiByteToWideChar(static_cast(m_from_wincp), 0, reinterpret_cast(src), static_cast(count_src), NULL, 0); size_t offset = dst.size(); dst.resize(offset + static_cast(cch)); - cch = MultiByteToWideChar(static_cast(m_from_wincp), dwFlagsMBWC, reinterpret_cast(src), static_cast(count_src), &dst[offset], cch); + cch = MultiByteToWideChar(static_cast(m_from_wincp), 0, reinterpret_cast(src), static_cast(count_src), &dst[offset], cch); dst.resize(offset + (count_src != SIZE_MAX ? wcsnlen(&dst[offset], cch) : static_cast(cch) - 1)); return; } @@ -250,10 +249,10 @@ namespace stdex stdex_assert(count_src < INT_MAX || count_src == SIZE_MAX); // Try to convert to stack buffer first. - DWORD dwFlagsMBWC = static_cast(m_from_wincp) < CP_UTF7 ? MB_PRECOMPOSED : 0, dwResult; + DWORD dwResult; WCHAR szStackBufferMBWC[512 / sizeof(WCHAR)]; #pragma warning(suppress: 6387) // Testing indicates src may be NULL when count_src is also 0. Is SAL of the lpMultiByteStr parameter wrong? - int cch = MultiByteToWideChar(static_cast(m_from_wincp), dwFlagsMBWC, reinterpret_cast(src), static_cast(count_src), szStackBufferMBWC, _countof(szStackBufferMBWC)); + int cch = MultiByteToWideChar(static_cast(m_from_wincp), 0, reinterpret_cast(src), static_cast(count_src), szStackBufferMBWC, _countof(szStackBufferMBWC)); if (cch) { // Append from stack. size_t count_inter = count_src != SIZE_MAX ? wcsnlen(szStackBufferMBWC, cch) : static_cast(cch) - 1; @@ -283,9 +282,9 @@ namespace stdex dwResult = GetLastError(); if (dwResult == ERROR_INSUFFICIENT_BUFFER) { // Query the required output size. Allocate buffer. Then convert again. - cch = MultiByteToWideChar(static_cast(m_from_wincp), dwFlagsMBWC, reinterpret_cast(src), static_cast(count_src), NULL, 0); + cch = MultiByteToWideChar(static_cast(m_from_wincp), 0, reinterpret_cast(src), static_cast(count_src), NULL, 0); std::unique_ptr szBufferMBWC(new WCHAR[cch]); - cch = MultiByteToWideChar(static_cast(m_from_wincp), dwFlagsMBWC, reinterpret_cast(src), static_cast(count_src), szBufferMBWC.get(), cch); + cch = MultiByteToWideChar(static_cast(m_from_wincp), 0, reinterpret_cast(src), static_cast(count_src), szBufferMBWC.get(), cch); size_t count_inter = count_src != SIZE_MAX ? wcsnlen(szBufferMBWC.get(), cch) : static_cast(cch) - 1; // Query the required output size. Allocate buffer. Then convert again.