1. 本文转自他出,链接为:http://blog.csdn.net/js_gary/article/details/7527232,转载请说明出处!!!
  2. wchar_t * ANSIToUnicode( const char* str )
  3. {
  4.       int    textlen ;
  5.       wchar_t * result;
  6.       textlen = MultiByteToWideChar( CP_ACP, 0, str,-1,    NULL,0 );  
  7.       result = (wchar_t *)malloc((textlen+1)*sizeof(wchar_t));  
  8.       memset(result,0,(textlen+1)*sizeof(wchar_t));  
  9.       MultiByteToWideChar(CP_ACP, 0,str,-1,(LPWSTR)result,textlen );  
  10.       return    result;  
  11. }
  12. char * UnicodeToANSI( const wchar_t *str )
  13. {
  14.       char * result;
  15.       int textlen;
  16.       // wide char to multi char
  17.       textlen = WideCharToMultiByte( CP_ACP,    0,    str,    -1,    NULL, 0, NULL, NULL );
  18.       result =(char *)malloc((textlen+1)*sizeof(char));
  19.       memset( result, 0, sizeof(char) * ( textlen + 1 ) );
  20.       WideCharToMultiByte( CP_ACP, 0, str, -1, result, textlen, NULL, NULL );
  21.       return result;
  22. }
  23. wchar_t * UTF8ToUnicode( const char* str )
  24. {
  25.       int    textlen ;
  26.       wchar_t * result;
  27.       textlen = MultiByteToWideChar( CP_UTF8, 0, str,-1,    NULL,0 );  
  28.       result = (wchar_t *)malloc((textlen+1)*sizeof(wchar_t));  
  29.       memset(result,0,(textlen+1)*sizeof(wchar_t));  
  30.       MultiByteToWideChar(CP_UTF8, 0,str,-1,(LPWSTR)result,textlen );  
  31.       return    result;  
  32. }
  33. char * UnicodeToUTF8( const wchar_t *str )
  34. {
  35.       char * result;
  36.       int textlen;
  37.       // wide char to multi char
  38.       textlen = WideCharToMultiByte( CP_UTF8,    0,    str,    -1,    NULL, 0, NULL, NULL );
  39.       result =(char *)malloc((textlen+1)*sizeof(char));
  40.       memset(result, 0, sizeof(char) * ( textlen + 1 ) );
  41.       WideCharToMultiByte( CP_UTF8, 0, str, -1, result, textlen, NULL, NULL );
  42.       return result;
  43. }