TCHAR与char的转换[转载]

首先是把TCHAR转为char

//将TCHAR转为char  
//*tchar是TCHAR类型指针,*_char是char类型指针  
TcharToChar (const TCHAR * tchar, char * _char)  
{  
    int iLength;  
  //获取字节长度  
  iLength = WideCharToMultiByte(CP_ACP, 0, tchar, -1, NULL, 0, NULL, NULL);  
  //将tchar值赋给_char   
  WideCharToMultiByte(CP_ACP, 0, tchar, -1, _char, iLength, NULL, NULL);   
}  

然后是把char转为TCHAR

//同上 
CharToTchar (const char * _char, TCHAR * tchar)  
{  
    int iLength;
    iLength = MultiByteToWideChar (CP_ACP, 0, _char, strlen (_char) + 1, NULL, 0) ;  
    MultiByteToWideChar (CP_ACP, 0, _char, strlen (_char) + 1, tchar, iLength) ;  
}

参考:

http://blog.csdn.net/q408384053/article/details/7522155#

 
 
posted on 2013-12-18 09:35  大宴天下  阅读(512)  评论(0编辑  收藏  举报