diff --git a/desmume/src/frontend/windows/winutil.cpp b/desmume/src/frontend/windows/winutil.cpp index 1bab5f8d4..07e8b4bad 100644 --- a/desmume/src/frontend/windows/winutil.cpp +++ b/desmume/src/frontend/windows/winutil.cpp @@ -87,7 +87,7 @@ void GetINIPath() } FCEUD_MakePathDirs(IniName); - wcscpy(IniNameW,mbstowcs(IniName).c_str()); //careful to use locale C-style mbstowcs to get IniName (which is with locale encoding) to unicode + wcscpy(IniNameW,mbstowcs_locale(IniName).c_str()); //write BOM to get unicode FILE* test = fopen(IniName,"rb"); diff --git a/desmume/src/path.cpp b/desmume/src/path.cpp index c2c2b883d..d71b07ecf 100644 --- a/desmume/src/path.cpp +++ b/desmume/src/path.cpp @@ -170,7 +170,7 @@ void createDirectoryRecursively(std::wstring path) void FCEUD_MakePathDirs(const char *fname) { - createDirectoryRecursively(mbstowcs(fname)); + createDirectoryRecursively(mbstowcs_locale(fname)); } #endif //------------------------------ diff --git a/desmume/src/utils/xstring.cpp b/desmume/src/utils/xstring.cpp index d491b180b..6b92f5f30 100644 --- a/desmume/src/utils/xstring.cpp +++ b/desmume/src/utils/xstring.cpp @@ -284,6 +284,19 @@ std::string mass_replace(const std::string &source, const std::string &victim, c return answer; } +std::wstring mbstowcs_locale(std::string str) +{ + #ifdef HOST_WINDOWS + int plenty = str.size()*4+1; + wchar_t *wgarbage = new wchar_t[plenty]; + MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str.data(), -1, wgarbage, plenty); + std::wstring ret = wgarbage; + delete[] wgarbage; + return ret; + #endif + return mbstowcs(str); +} + //convert a std::string to std::wstring std::wstring mbstowcs(std::string str) { diff --git a/desmume/src/utils/xstring.h b/desmume/src/utils/xstring.h index 92a881ceb..5741d998f 100644 --- a/desmume/src/utils/xstring.h +++ b/desmume/src/utils/xstring.h @@ -107,5 +107,7 @@ std::string mass_replace(const std::string &source, const std::string &victim, c std::wstring mbstowcs(std::string str); std::string wcstombs(std::wstring str); +std::wstring mbstowcs_locale(std::string str); + #endif