Generic Text Mappings (Windows CE 5.0)
Developing an Application > Microsoft C Run-time Library for Windows CE
To simplify transporting code for international use, the Microsoft run-time library provides Microsoft-specific generic-text mappings for many data types, routines, and other objects.
You can use these mappings, defined in TCHAR.H, to write generic code that can be compiled for single byte or Unicode applications, depending on a manifest constant you define using a #define statement.
Generic-text mappings are Microsoft extensions that are not ANSI compatible.
Using the header file TCHAR.H, you can build single-byte and Unicode applications from the same sources. TCHAR.H defines macros prefixed with _tcs that, with the correct preprocessor definitions, map to str or wcs functions as appropriate.
To build Unicode, define the symbol _UNICODE. Because a single-byte application is the default, no symbol definition is required.
The _TCHAR data type is defined conditionally in TCHAR.H. If the symbol _UNICODE is defined for your build, _TCHAR is defined as wchar_t; otherwise, for single-byte builds, it is defined as char. The basic Unicode wide character data type is wchar_t, which is the 16-bit counterpart to an 8-bit signed char.
For international applications, use the _tcs family of functions, which operate in _TCHAR units, not bytes. For example, _tcsncpy copies n _TCHARs, not n bytes.
Preprocessor Directives for Generic-Text Mappings
The following are preprocessor directives for generic-text mappings:
# define | Compiled Version | Example |
---|---|---|
_UNICODE | Unicode (wide-character) | _tcsrev maps to _wcsrev |
None | SBCS (ASCII) | _tcsrev maps to strrev |
For example, the generic-text function _tcsrev, defined in TCHAR.H, maps to _wcsrev if you defined _UNICODE. Otherwise _tcsrev maps to strrev.
Other data type mappings are provided in TCHAR.H for programming convenience, but _TCHAR is the most useful.
The following code examples illustrate the use of _TCHAR and _tcsrev for mapping to the Unicode and single byte character models.
_TCHAR *RetVal, *szString;
RetVal = _tcsrev(szString);
If _UNICODE is defined, the preprocessor maps this fragment to the code:
wchar_t *RetVal, *szString;
RetVal = _wcsrev(szString);
If _UNICODE is not defined, the preprocessor maps the fragment to single-byte ASCII code:
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 either single byte or Unicode character sets.
See Also
Data Type Mappings | Constant and Global Variable Mappings | Routine Mappings
Send Feedback on this topic to the authors