cdvdgigaherz: Replace use of deprecated wstring_convert

wstring_convert is deprecated in C++17. Use MultiByteToWideChar() and
WideCharToMultiByte() instead.
This commit is contained in:
Jonathan Li 2018-06-02 10:02:30 +01:00
parent 4ab97be693
commit 6778fa2b71
2 changed files with 15 additions and 8 deletions

View File

@ -16,7 +16,9 @@
#include "Settings.h"
#if defined(_WIN32)
#include <codecvt>
#define NOMINMAX
#include <windows.h>
#include <vector>
#endif
#include <fstream>
#include <locale>
@ -96,8 +98,10 @@ bool Settings::Get(const std::string &key, std::string &data) const
#if defined(_WIN32)
void Settings::Set(std::string key, std::wstring value)
{
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
m_data[key] = converter.to_bytes(value);
int size = WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, nullptr, 0, nullptr, nullptr);
std::vector<char> converted_string(size);
WideCharToMultiByte(CP_UTF8, 0, value.c_str(), -1, converted_string.data(), converted_string.size(), nullptr, nullptr);
m_data[key] = converted_string.data();
}
bool Settings::Get(const std::string &key, std::wstring &data) const
@ -106,8 +110,10 @@ bool Settings::Get(const std::string &key, std::wstring &data) const
if (it == m_data.end())
return false;
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
data = converter.from_bytes(it->second);
int size = MultiByteToWideChar(CP_UTF8, 0, it->second.c_str(), -1, nullptr, 0);
std::vector<wchar_t> converted_string(size);
MultiByteToWideChar(CP_UTF8, 0, it->second.c_str(), -1, converted_string.data(), converted_string.size());
data = converted_string.data();
return true;
}
#endif

View File

@ -19,7 +19,6 @@
#include "../CDVD.h"
#include <Windows.h>
#include <commctrl.h>
#include <codecvt>
#include "resource.h"
static HINSTANCE s_hinstance;
@ -107,8 +106,10 @@ std::wstring GetValidDrive()
drive = drives.front();
}
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
printf(" * CDVD: Opening drive '%s'...\n", converter.to_bytes(drive).c_str());
int size = WideCharToMultiByte(CP_UTF8, 0, drive.c_str(), -1, nullptr, 0, nullptr, nullptr);
std::vector<char> converted_string(size);
WideCharToMultiByte(CP_UTF8, 0, drive.c_str(), -1, converted_string.data(), converted_string.size(), nullptr, nullptr);
printf(" * CDVD: Opening drive '%s'...\n", converted_string.data());
// The drive string has the form "X:\", but to open the drive, the string
// has to be in the form "\\.\X:"