Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows deprecation warnings using WideCharToMultiByte() #426

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions RtAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::codecvt_utf8_utf16<wchar_t>>{}.to_bytes(text);
#endif
}

#if defined(_MSC_VER)
Expand Down
Loading