UNICODE与ASCII字符的转换

来源:互联网 发布:php中文手册 编辑:程序博客网 时间:2024/04/27 22:40

转自http://topic.csdn.net/t/20050517/09/4012450.html

/*------------------------------------------------------------------------------  
  把ASCII字符串转换成UNICODE字符串  
  [input]: source=源ASCII字符串  
  [output]: obj=目标UNICODE字符串  
  */  
  void   ConvertAnsiTounicode(char   *   source,TCHAR   *   obj)  
  {  
  int   nLength   =   0;  
   
  nLength   =   MultiByteToWideChar(CP_ACP,0,source,-1,NULL,0);  
  MultiByteToWideChar(CP_ACP,0,source,-1,obj,nLength);  
  }  
   
  /*------------------------------------------------------------------------------  
  把UNICODE字符串转换成ASCII字符串  
  [input]: source=源UNICODE字符串  
  [output]: obj=目标ASCII字符串  
  */  
  void   ConvertUnicodeToAnsi(TCHAR   *   source,char*   obj)//,int&   nLength)  
  {  
  int   nLength   =   0;  
   
  nLength   =   WideCharToMultiByte(CP_ACP,0,source,-1,NULL,0,NULL,NULL);  
  WideCharToMultiByte(CP_ACP,0,source,-1,obj,nLength,NULL,NULL);  
  } 

原创粉丝点击