std::string ConvertLPCTSTRToString(LPCTSTR lpctstr) {
int length = lstrlen(lpctstr);
int size = WideCharToMultiByte(CP_UTF8, 0, lpctstr, length, nullptr, 0, nullptr, nullptr);
if (size == 0) {
// 转换失败处理
return "";
}
std::string str(size, '\0');
WideCharToMultiByte(CP_UTF8, 0, lpctstr, length + 1, &str[0], size, nullptr, nullptr);
return str;
}
LPWSTR ConvertToLPWSTR(const std::string& s)
{
LPWSTR ws = new wchar_t[s.size() + 1]; // +1 for zero at the end
copy(s.begin(), s.end(), ws);
ws[s.size()] = 0; // zero at the end
return ws;
}
std::string与LPCTSTR/LPWSTR互转
于 2023-11-15 15:50:20 首次发布