Skip to content

Commit

Permalink
Load firmware from UTF-8 paths correctly, fixing #172
Browse files Browse the repository at this point in the history
  • Loading branch information
Dewb committed Sep 17, 2023
1 parent 93c8ab8 commit 3aa792e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/common/core/FirmwareManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<wchar_t> 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();
Expand Down

0 comments on commit 3aa792e

Please sign in to comment.