diff --git a/RtAudio.cpp b/RtAudio.cpp index bc61c545..2d8f5779 100644 --- a/RtAudio.cpp +++ b/RtAudio.cpp @@ -74,7 +74,22 @@ std::string convertCharPointerToStdString(const char *text) template<> inline std::string convertCharPointerToStdString(const wchar_t *text) { +#if defined(_MSC_VER) + if (!text) + return std::string(); + const int wchars = (int) wcslen(text); + // how many characters are required after conversion? + const int nchars = WideCharToMultiByte(CP_UTF8, 0, text, wchars, 0, 0, 0, 0); + if (!nchars) + return std::string(); + // create buffer + std::string nret(nchars, 0); + // do the conversion + WideCharToMultiByte(CP_UTF8, 0, text, wchars, &nret[0], nchars, 0, 0); + return nret; +#else return std::wstring_convert>{}.to_bytes(text); +#endif } #if defined(_MSC_VER)