LPCWSTR stringToLPCWSTR(std::string orig)
{
size_t origsize = orig.length() + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
wchar_t* wcstring = (wchar_t*)malloc(sizeof(wchar_t)* (orig.length() - 1));
mbstowcs_s(&convertedChars, wcstring, origsize, orig.c_str(), _TRUNCATE);
return wcstring;
}
LPCTSTR stringToLPCSTR(std::string orig)
{
size_t origsize = orig.length() + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
wchar_t* wcstring = (wchar_t*)malloc(sizeof(wchar_t)* (orig.length() - 1));
mbstowcs_s(&convertedChars, wcstring, origsize, orig.c_str(), _TRUNCATE);
// 将 std::string 转换为 std::wstring
std::wstring wideString(orig.begin(), orig.end());
// 获取 LPCTSTR 指针
#ifdef UNICODE
LPCTSTR lpctstr = wideString.c_str();
#else
// 将 wideString 转换为 const char* 如果不是 Unicode 环境
const char* narrowCString = orig.c_str();
LPCTSTR lpctstr = narrowCString;
#endif
return lpctstr;
}
string转LPCWSTR和LPCTSTR
最新推荐文章于 2024-05-24 15:31:50 发布