[Redirector] Update ws2s and s2ws

This commit is contained in:
Connection Refused
2021-10-14 18:08:51 +08:00
parent 110013b2ae
commit 945ea9a20d

View File

@@ -2,10 +2,10 @@
string ws2s(const wstring str)
{
auto length = WideCharToMultiByte(CP_ACP, 0, str.c_str(), (int)str.length(), NULL, 0, NULL, NULL);
auto buffer = new char[length]();
auto length = WideCharToMultiByte(CP_ACP, 0, str.c_str(), static_cast<int>(str.length()), NULL, 0, NULL, NULL);
auto buffer = new char[length + 1]();
WideCharToMultiByte(CP_ACP, 0, str.c_str(), (int)str.length(), buffer, length, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, str.c_str(), static_cast<int>(str.length()), buffer, length, NULL, NULL);
auto data = string(buffer);
delete[] buffer;
@@ -15,10 +15,10 @@ string ws2s(const wstring str)
wstring s2ws(const string str)
{
auto length = MultiByteToWideChar(CP_ACP, 0, str.c_str(), (int)str.length(), NULL, 0);
auto buffer = new wchar_t[length]();
auto length = MultiByteToWideChar(CP_ACP, 0, str.c_str(), static_cast<int>(str.length()), NULL, 0);
auto buffer = new wchar_t[length + 1]();
MultiByteToWideChar(CP_ACP, 0, str.c_str(), (int)str.length(), buffer, length);
MultiByteToWideChar(CP_ACP, 0, str.c_str(), static_cast<int>(str.length()), buffer, length);
auto data = wstring(buffer);
delete[] buffer;