_T() 有什么用?

解决方案 »

  1.   

    Using Generic-Text Mappings
    Microsoft Specific —>To simplify code development for various international ets, the Microsoft run-time library provides Microsoft-specific “generic-text” mappings for many data types, routines, and other objects. These mappings are defined in TCHAR.H. You can use these name mappings to write generic code that can be compiled for any of the three kinds of character sets: ASCII (SBCS), MBCS, or Unicode, depending on a manifest constant you define using a #define statement. Generic-text mappings are Microsoft extensions that are not ANSI compatible.Preprocessor Directives for Generic-Text Mappings#define Compiled Version Example  
    _UNICODE Unicode (wide-character) _tcsrev maps to _wcsrev 
    _MBCS Multibyte-character _tcsrev maps to _mbsrev 
    None (the default: neither _UNICODE nor _MBCS defined) SBCS (ASCII) _tcsrev maps to strrev 
    For example, the generic-text function _tcsrev, defined in TCHAR.H, maps to mbsrev if MBCS has been defined in your program, or to _wcsrev if _UNICODE has been defined. Otherwise _tcsrev maps to strrev. The generic-text data type _TCHAR, also defined in TCHAR.H, maps to type char if _MBCS is defined, to type wchar_t if _UNICODE is defined, and to type char if neither constant is defined. Other data type mappings are provided in TCHAR.H for programming convenience, but _TCHAR is the type that is most useful. Generic-Text Data Type MappingsGeneric-Text Data Type Name SBCS (_UNICODE, _MBCS Not Defined) 
    _MBCS Defined 
    _UNICODE Defined 
    _TCHAR char char wchar_t 
    _TINT int int wint_t 
    _TSCHAR signed char signed char wchar_t 
    _TUCHAR unsigned char unsigned char wchar_t 
    _TXCHAR char unsigned char wchar_t 
    _T or _TEXT No effect (removed by preprocessor) No effect (removed by preprocessor) L (converts following character or string to its Unicode counterpart) 
    For a complete list of generic-text mappings of routines, variables, and other objects, see Appendix B, Generic-Text Mappings.The following code fragments illustrate the use of _TCHAR and _tcsrev for mapping to the MBCS, Unicode, and SBCS models._TCHAR *RetVal, *szString;
    RetVal = _tcsrev(szString);If MBCS has been defined, the preprocessor maps the preceding fragment to the following code:char *RetVal, *szString;
    RetVal = _mbsrev(szString);If _UNICODE has been defined, the preprocessor maps the same fragment to the following code:wchar_t *RetVal, *szString;
    RetVal = _wcsrev(szString);If neither _MBCS nor _UNICODE has been defined, the preprocessor maps the fragment to single-byte ASCII code, as follows:char *RetVal, *szString;
    RetVal = strrev(szString);Thus you can write, maintain, and compile a single source code file to run with routines that are specific to any of the three kinds of character sets. See Also   Generic-text mappings, Data type mappings, Constants and global variable mappings, Routine mappings, A sample generic-text propgramEND Microsoft Specific
      

  2.   

    使用unicode时,不加_T根本就不对。
      

  3.   

    在通常情况下,一个英文字符占1个字节,一个汉字占2个字节。
    如果_T()的话,就转换成unicode,即无论是一个英文还是一个汉字都占两个字节!
      

  4.   

    vc编译时,可根据Define语句将_T()中的String 变为unicode,双字节
    或单字节。
      

  5.   

    楼上说的不太对
    _T()是定义于TCHAR.h中的一个宏如果你的工程定义了unicode那么它会装你的字串转成unicode否则就是ansi的具体请看windows核心编程下面是部分摘录...字符串(literal string)前面的大写字母L,用于告诉编译器该字符串应该作为U n i c o d e字符
    串来编译。当编译器将字符串置于程序的数据部分中时,它在每个字符之间分散插入零字节。
    这种变更带来的问题是,现在只有当定义了_ U N I C O D E时,程序才能成功地进行编译。我们需
    要另一个宏,以便有选择地在字符串的前面加上大写字母L。这项工作由_ T E X T宏来完成,
    _ T E X T宏也在T C h a r. h文件中做了定义。如果定义了_ U N I C O D E,那么_ T E X T定义为下面的形
    式:#define _TEXT(x) L ## x
    如果没有定义_ U N I C O D E,_ T E X T将定义为#define _TEXT(x) x
    使用该宏,可以改写上面这行代码,这样,无论是否定义了_ U N I C O D E宏,它都能够正确
    地进行编译。from windows核心编程
      

  6.   

    简单点讲
    就是根据你是否声明_UNICODE或_MBCS
    编译器分辨你的变量是什么类型