char 与 wchar之间的转换

来源:互联网 发布:js创建json 取值 编辑:程序博客网 时间:2024/05/19 21:42

1.头文件中要定义宏;  
      #define   UNICODE  
      #define   _UNICODE  
   
  2.char转换成wchar  
      const   char   *pFilePathName   =   "c://aa.dll";  
      int   nLen   =   strlen(pFilePathName)   +   1;  
      int   nwLen   =   MultiByteToWideChar(CP_ACP,   0,   pFilePathName,   nLen,   NULL,   0);  
   
      TCHAR   lpszFile[256];  
      MultiByteToWideChar(CP_ACP,   0,   pFilePathName,   nLen,   lpszFile,   nwLen);  
   
  3.wchar转换成char  
        char   *pFilePathName;  
        TCHAR   lpszFile[256];  
      _tcscpy(lpszFile,   _T("c://aa.dll"));  
   
      int   nLen   =   wcslen(wstr)+1;    
      WideCharToMultiByte(CP_ACP,   0,   lpszFile,   nLen,   pFilePathName,   2*nLen,   NULL,   NULL);