Skip to content

Commit

Permalink
Fix Windows deprecation warnings for std::codecvt using WideCharToMul…
Browse files Browse the repository at this point in the history
…tiByte
  • Loading branch information
g40 committed Apr 6, 2024
1 parent cb03db3 commit 0b687c3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions RtAudio.cpp
Expand Up @@ -74,7 +74,22 @@ std::string convertCharPointerToStdString(const char *text)
template<> inline
std::string convertCharPointerToStdString(const wchar_t *text)
{
#if 1
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<std::codecvt_utf8_utf16<wchar_t>>{}.to_bytes(text);
#endif
}

#if defined(_MSC_VER)
Expand Down

0 comments on commit 0b687c3

Please sign in to comment.