/******************************************************************************************
Function: stringToLPCWSTR
Description: string转LPCWSTR
Input: orig:待转化的string类型字符串
Return: 转化后的LPCWSTR类型字符串
*******************************************************************************************/
LPCWSTR stringToLPCWSTR(std::string orig)
{
wchar_t *wcstring = 0;
try
{
size_t origsize = orig.length() + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
if (orig == "")
{
wcstring = (wchar_t *)malloc(0);
mbstowcs_s(&convertedChars, wcstring, origsize, orig.c_str(), _TRUNCATE);
}
else
{
wcstring = (wchar_t *)malloc(sizeof(wchar_t)*(orig.length() - 1));
mbstowcs_s(&convertedChars, wcstring, origsize, orig.c_str(), _TRUNCATE);
}
}
catch (std::exception e)
{
}
return wcstring;
}
网友评论