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> --- tools/slang-fiddle/slang-fiddle-main.cpp | 9 ++++++--- tools/vk-pipeline-create/main.cpp | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/slang-fiddle/slang-fiddle-main.cpp b/tools/slang-fiddle/slang-fiddle-main.cpp index cf8407995..fea16dafe 100644 --- a/tools/slang-fiddle/slang-fiddle-main.cpp +++ b/tools/slang-fiddle/slang-fiddle-main.cpp @@ -425,9 +425,12 @@ int main(int argc, char const* const* argv) } fprintf(stderr, "\n"); - char buffer[1024]; - GetCurrentDirectoryA(sizeof(buffer), buffer); - fprintf(stderr, "cwd: %s\n", buffer); + wchar_t wideBuffer[1024]; + GetCurrentDirectoryW(sizeof(wideBuffer) / sizeof(wideBuffer[0]), wideBuffer); + + // Convert to UTF-8 using String::fromWString + String currentDir = String::fromWString(wideBuffer); + fprintf(stderr, "cwd: %s\n", currentDir.getBuffer()); return 1; #endif diff --git a/tools/vk-pipeline-create/main.cpp b/tools/vk-pipeline-create/main.cpp index 91abb90bc..5685affb4 100644 --- a/tools/vk-pipeline-create/main.cpp +++ b/tools/vk-pipeline-create/main.cpp @@ -278,8 +278,8 @@ void PipelineCreationReplay::initVulkanAPI(IDevice* device) vkAPI.device = (VkDevice)(handle.handles[2].value); vkAPI.instance = (VkInstance)(handle.handles[0].value); #if SLANG_WINDOWS_FAMILY - auto dynamicLibraryName = "vulkan-1.dll"; - HMODULE module = ::LoadLibraryA(dynamicLibraryName); + auto dynamicLibraryName = L"vulkan-1.dll"; + HMODULE module = ::LoadLibraryW(dynamicLibraryName); vkAPI.vulkanLibraryHandle = (void*)module; #define VK_API_GET_GLOBAL_PROC(x) vkAPI.x = (PFN_##x)GetProcAddress(module, #x); #else -- cgit v1.2.3