TCHAR

来源:互联网 发布:java命令行输入参数 编辑:程序博客网 时间:2024/04/30 06:55

The TCHAR data type is a Win32 character string that can be used to describe ANSI, DBCS, or Unicode strings. For ANSI and DBCS platforms, TCHAR is defined as follows:
typedef char          TCHAR; 
For Unicode platforms, TCHAR is defined as synonymous with the WCHAR type.
即,
TCHAR 在ANSI,DBCS 中是 char
TCHAR 在Unicode 中是 unsigned short
这在预编译中的UNICODE宏确定
#ifdefine UNICODE
define TCHAR WCHAR
#else
define TCHAR char

#char 转换成TCHAR?
    使用预编译符
 char szText[50]="程序员";
 #ifdef _UNICODE
 //此时TCHAR表示wchar,做相应转换即可
 int i=0;
 TCHAR szWideChar[50];
 szWideChar[0]=0;
 i=MultiByteToWideChar(CP_ACP,0,szText,-1,szWideChar,0);
 i=MultiByteToWideChar(CP_ACP,0,szText,-1,szWideChar,i);

 #else
 //此时TCHAR表示char,不必做任何转换
 #endif

原创粉丝点击