多字符串转换宽字符串

Home / Article MrLee 2014-8-29 2620

char* WCharToChar(const wchar_t *wstr)
{
	//第四个参数-1表示求长度
	int _length = WideCharToMultiByte(CP_OEMCP, 0, wstr, -1, NULL, 0, NULL, FALSE);
	char *pstr = new char[_length+1];
	_length = WideCharToMultiByte(CP_OEMCP, 0, wstr, -1, pstr, _length, NULL, FALSE);
	pstr[_length] = 0;
	return pstr;
}
wchar_t* CharToWChar(const char *str)
{
	//第四个参数-1表示求长度
	int _length = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
	wchar_t *pwText = new wchar_t[_length+1];
	_length = MultiByteToWideChar(CP_ACP,0,str,-1,pwText,_length);
	pwText[_length] = 0;
	return pwText;
}

本文链接:https://www.it72.com/193.htm

推荐阅读
最新回复 (0)
返回