summaryrefslogtreecommitdiffstats
path: root/source/core/slang-platform.cpp
diff options
context:
space:
mode:
authorGangzheng Tong <tonggangzheng@gmail.com>2025-09-08 10:24:05 -0700
committerGitHub <noreply@github.com>2025-09-08 17:24:05 +0000
commit3aff764c2b5d613f766538d27e0b9f448e7ed5ca (patch)
tree0d21cd8486bb8914a933cd58841e4c9bb246df70 /source/core/slang-platform.cpp
parent8b512c49d163af1df33e940acc3c4a230f0d00b7 (diff)
Use wide char version of Windows API (#8390)
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 <gtong-nv@users.noreply.github.com> Co-authored-by: slangbot <ellieh+slangbot@nvidia.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source/core/slang-platform.cpp')
-rw-r--r--source/core/slang-platform.cpp17
1 files changed, 10 insertions, 7 deletions
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;