Iceberg tip
LPCTSTRit can be either a single-byte or a multi-byte string (depending on the constant UNICODEdetermined at compile time or not), while std::stringusers (including your function) usually use it to store a single-byte string.
You will need two conversions: one for LPCSTR(not UNICODEbuild) and one for LPCWSTR( UNICODEbuild). The first is simple:
std::string convert(LPCSTR str) {
return std::string(str);
}
, WideCharToMultiByte. , char; CodePage. , CP_ACP.
: WideCharToMultiByte example
, , , . , , , 100% , .
std::string MBFromW(LPCWSTR pwsz, UINT cp) {
int cch = WideCharToMultiByte(cp, 0, pwsz, -1, 0, 0, NULL, NULL);
char* psz = new char[cch];
WideCharToMultiByte(cp, 0, pwsz, -1, psz, cch, NULL, NULL);
std::string st(psz);
delete[] psz;
return st;
}
Caveat emptor: - , , . , . . .
, std::string (, UTF8) - char, - .
, STL, std::string, , , , .
, , , , std::string - , UTF-8. " ", , .