Skip to content

Commit

Permalink
inline Utf8ToUtf16 function
Browse files Browse the repository at this point in the history
  • Loading branch information
fredemmott committed Feb 13, 2021
1 parent acd499e commit 7f8903a
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Sources/PlayWavFileWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,31 @@
*/
#include "PlayWavFile.h"

#include "StringEncoding.h"

#include "Windows.h"

#include <string>

namespace FredEmmott::Audio {

namespace {

std::wstring Utf8ToUtf16(const std::string& utf8) {
if (utf8.empty()) {
return std::wstring();
}
int wchar_len
= MultiByteToWideChar(CP_UTF8, 0, utf8.data(), utf8.size(), 0, 0);
std::wstring buf(wchar_len, 0);
MultiByteToWideChar(
CP_UTF8, 0, utf8.data(), utf8.size(), buf.data(), wchar_len);
return buf;
}

} // namespace

void PlayWavFile(const std::string& path) {
const auto utf16 = FredEmmott::Encoding::Utf8ToUtf16(path);
const auto utf16 = Utf8ToUtf16(path);
PlaySound(utf16.c_str(), NULL, SND_ASYNC| SND_NODEFAULT);
}

}
} // namespace FredEmmott::Audio

0 comments on commit 7f8903a

Please sign in to comment.