现在的位置: 首页 > 综合 > 正文

char 与 wchar之间的转换

2012年09月03日 ⁄ 综合 ⁄ 共 561字 ⁄ 字号 评论关闭

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);    

抱歉!评论已关闭.