MultiByteToWideChar和WideCharToMultiByte的用法

来源:互联网 发布:交大网络教育学院登录 编辑:程序博客网 时间:2024/05/21 17:57
  多字节转换为宽字符:  
  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;


原创粉丝点击