From f014691592e4452a8f04437456c027cd27948413 Mon Sep 17 00:00:00 2001 From: zilmar Date: Thu, 26 Dec 2024 15:05:19 +1030 Subject: [PATCH] Common: Fix CPath::SelectFile --- Source/Common/path.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Source/Common/path.cpp b/Source/Common/path.cpp index 364f7d931..eb04e923e 100644 --- a/Source/Common/path.cpp +++ b/Source/Common/path.cpp @@ -1001,7 +1001,16 @@ bool CPath::Exists() const bool CPath::SelectFile(void * hwndOwner, const char * InitialDir, const char * FileFilter, bool FileMustExist) { CPath CurrentDir(CURRENT_DIRECTORY); - std::wstring FileFilterW = stdstr(FileFilter).ToUTF16(); + + size_t FilterLen = 0; + while (FileFilter[FilterLen] != '\0' || FileFilter[FilterLen + 1] != '\0') + { + FilterLen++; + } + FilterLen += 2; + + std::vector FileFilterW(FilterLen); + MultiByteToWideChar(CP_UTF8, 0, FileFilter, (int)FilterLen, FileFilterW.data(), static_cast(FilterLen)); std::wstring InitialDirW = stdstr(InitialDir).ToUTF16(); OPENFILENAME openfilename; @@ -1011,7 +1020,7 @@ bool CPath::SelectFile(void * hwndOwner, const char * InitialDir, const char * F openfilename.lStructSize = sizeof(openfilename); openfilename.hwndOwner = (HWND)hwndOwner; - openfilename.lpstrFilter = FileFilterW.c_str(); + openfilename.lpstrFilter = FileFilterW.data(); openfilename.lpstrFile = FileName; openfilename.lpstrInitialDir = InitialDirW.c_str(); openfilename.nMaxFile = MAX_PATH;