一、目的:
1、在MFC读取ini配置文件中GetPrivateProfileString获取的是LPWSTR,所以需要将其转换为string
二、操作:
1、MFC读取.ini文件字符串的方法
https://blog.youkuaiyun.com/qq_40544338/article/details/105991980
①总结:good:亲测
1、参考:LPCWSTR与string相互转换
https://blog.youkuaiyun.com/g9208/article/details/102633006
①、string char*转LPCWSTR
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;
}
①、LPCWSTR或LPWSTR转string
string WCharToMByte(LPCWSTR lpcwszStr)
{
string str;
DWORD dwMinSize = 0;
LPSTR lpszStr = NULL;
dwMinSize = WideCharToMultiByte(CP_OEMCP, NULL, lpcwszStr, -1, NULL, 0, NULL, FALSE);
if (0 == dwMinSize)
{
return FALSE;
}
lpszStr = new char[dwMinSize];
WideCharToMultiByte(CP_OEMCP, NULL, lpcwszStr, -1, lpszStr, dwMinSize, NULL, FALSE);
str = lpszStr;
delete[] lpszStr;
return str;
}