Fix deprecation warning

This commit is contained in:
badaix 2021-06-27 20:55:05 +02:00
parent 2cc9567847
commit 74b3e7d9a4

View file

@ -107,9 +107,18 @@ inline PcmDevice convertToDevice(int idx, IMMDevicePtr& device)
desc.idx = idx; desc.idx = idx;
using converter = wstring_convert<codecvt_utf8_utf16<wchar_t>, wchar_t>; // Convert a wide Unicode string to an UTF8 string
desc.name = converter{}.to_bytes(id); auto utf8_encode = [](const std::wstring& wstr) {
desc.description = converter{}.to_bytes(deviceName.pwszVal); if (wstr.empty())
return std::string();
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
std::string strTo(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
return strTo;
};
desc.name = utf8_encode(id);
desc.description = utf8_encode(deviceName.pwszVal);
CoTaskMemFree(id); CoTaskMemFree(id);