From 3aff764c2b5d613f766538d27e0b9f448e7ed5ca Mon Sep 17 00:00:00 2001 From: Gangzheng Tong Date: Mon, 8 Sep 2025 10:24:05 -0700 Subject: Use wide char version of Windows API (#8390) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR modernizes the Windows-specific code by replacing ANSI Windows API functions with their Unicode (wide character) counterparts. This change ensures proper handling of Unicode file paths and strings on Windows systems. ### File Operations (`source/core/slang-io.cpp`) - `DeleteFileA` → `DeleteFileW` - `GetTempPathA` → `GetTempPathW` - `GetTempFileNameA` → `GetTempFileNameW` - `RemoveDirectoryA` → `RemoveDirectoryW` - `SHFileOperationA` → `SHFileOperationW` - `GetModuleFileNameA` → `GetModuleFileNameW` with UTF-8 conversion ### Platform Operations (`source/core/slang-platform.cpp`) - `GetModuleHandleExA` → `GetModuleHandleExW` - `LoadLibraryExA` → `LoadLibraryExW` - `LoadLibraryA` → `LoadLibraryW` - `OutputDebugStringA` → `OutputDebugStringW` ### Runtime and Tools - `MessageBoxA` → `MessageBoxW` in slang-rt - `GetCurrentDirectoryA` → `GetCurrentDirectoryW` in slang-fiddle - String literal conversion to wide strings in vk-pipeline-create --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Gangzheng Tong Co-authored-by: slangbot Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/core/slang-platform.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'source/core/slang-platform.cpp') diff --git a/source/core/slang-platform.cpp b/source/core/slang-platform.cpp index 25e6bc6f0..75c1b96cd 100644 --- a/source/core/slang-platform.cpp +++ b/source/core/slang-platform.cpp @@ -122,7 +122,7 @@ SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY); handleOut = nullptr; if (!platformFileName || strlen(platformFileName) == 0) { - if (!GetModuleHandleExA(0, nullptr, (HMODULE*)&handleOut)) + if (!GetModuleHandleExW(0, nullptr, (HMODULE*)&handleOut)) return SLANG_FAIL; return SLANG_OK; } @@ -131,12 +131,14 @@ SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY); // First attempt tries on the directories explicitly specified with AddDllDirectory(), // If it failed to find one, we will search over all PATH. // Windows API made two approaches mutually exclusive and we need to try two times. - // https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexa - HMODULE h = LoadLibraryExA(platformFileName, nullptr, LOAD_LIBRARY_SEARCH_USER_DIRS); - // If LoadLibraryExA failed, try again with LoadLibraryA. - // https://docs.microsoft.com/en-us/windows/desktop/api/libloaderapi/nf-libloaderapi-loadlibrarya + // https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexw + String platformFileNameStr(platformFileName); + HMODULE h = + LoadLibraryExW(platformFileNameStr.toWString(), nullptr, LOAD_LIBRARY_SEARCH_USER_DIRS); + // If LoadLibraryExW failed, try again with LoadLibraryW. + // https://docs.microsoft.com/en-us/windows/desktop/api/libloaderapi/nf-libloaderapi-loadlibraryw if (!h) - h = LoadLibraryA(platformFileName); + h = LoadLibraryW(platformFileNameStr.toWString()); // If still not found, return an error. if (!h) { @@ -356,7 +358,8 @@ static const PlatformFlags s_familyFlags[int(PlatformFamily::CountOf)] = { /* static */ SlangResult PlatformUtil::outputDebugMessage([[maybe_unused]] const char* text) { #ifdef _WIN32 - OutputDebugStringA(text); + String textStr(text); + OutputDebugStringW(textStr.toWString()); return SLANG_OK; #else return SLANG_E_NOT_AVAILABLE; -- cgit v1.2.3