MultiByteToWideChar和WideCharToMultiByte的用法

  多字节转换为宽字符:  
  char sText[20] = {"多字节字符串!OK!"};
  DWORD dwNum = MultiByteToWideChar (CP_ACP, 0, sText, -1, NULL, 0);
  wchar_t *pwText;
  pwText = new wchar_t[dwNum];
  if(!pwText)
  {
   delete []pwText;
  }
  MultiByteToWideChar (CP_ACP, 0, psText, -1, sText, dwSize);
  delete []psText;
  
 
  同理,宽字符转为多字节字符的代码如下:  
	wchar_t wText[20] = {L"宽字符转换实例!OK!"};
	DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,wText,-1,NULL,0,NULL,FALSE);
	char *psText;
	psText = new char[dwNum];
	if(!psText)
	{
		delete []psText;
	}
	WideCharToMultiByte (CP_OEMCP,NULL,wText,-1,psText,dwNum,NULL,FALSE);
	delete []psText;


©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页