From 3aa792eb7799befb40a0bc1c6ee6e580097061a5 Mon Sep 17 00:00:00 2001 From: Michael Dewberry Date: Sun, 17 Sep 2023 11:24:37 -0400 Subject: [PATCH] Load firmware from UTF-8 paths correctly, fixing #172 --- src/common/core/FirmwareManager.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/common/core/FirmwareManager.cpp b/src/common/core/FirmwareManager.cpp index 7918ffc..51729fa 100644 --- a/src/common/core/FirmwareManager.cpp +++ b/src/common/core/FirmwareManager.cpp @@ -192,12 +192,19 @@ struct FirmwareManagerImpl #if ARCH_WIN - wchar_t* libName = new wchar_t[4096]; - MultiByteToWideChar(CP_ACP, 0, libraryToLoad.c_str(), -1, libName, 4096); + int wideLength = MultiByteToWideChar(CP_UTF8, 0, libraryToLoad.c_str(), -1, nullptr, 0); + if (wideLength > 0) + { + std::vector wideLibName(wideLength); + wideLength = MultiByteToWideChar(CP_UTF8, 0, libraryToLoad.c_str(), -1, wideLibName.data(), wideLength); + if (wideLength > 0) + { + SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); + handle = LoadLibraryW(wideLibName.data()); + SetErrorMode(0); + } + } - SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); - handle = LoadLibrary(libName); - SetErrorMode(0); if (!handle) { int error = GetLastError();