1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| //String conversion functions
string GetStringA(string s) { return s; }
string GetStringA(wstring s, int codePage=CP_ACP)
{
int cbBufSize = WideCharToMultiByte(codePage, 0, s.c_str(), -1, NULL, 0, NULL, NULL);
vector<char> buf(cbBufSize);
WideCharToMultiByte(codePage, 0, s.c_str(), -1, &buf[0], cbBufSize, NULL, NULL);
string ret(&buf[0]);
return ret;
}
wstring GetStringW(string s, int codePage=CP_ACP)
{
int cchBufSize = MultiByteToWideChar(codePage, 0, s.c_str(), -1, NULL, 0);
vector<wchar_t> buf(cchBufSize);
MultiByteToWideChar(codePage, 0, s.c_str(), -1, &buf[0], cchBufSize);
wstring ret(&buf[0]);
return ret;
}
wstring GetStringW(wstring s) { return s; }
//String conversion functions with a code page ID
string GetStringA(string s, int codePage) { return GetStringA(GetStringW(s), codePage); }
wstring GetStringW(wstring s, int codePage) { (void)codePage; return s; } |
Partager