Go Up to Unicode for C++ Index
The _TCHAR data type is declared conditionally in the tchar.h header file. _TCHAR is defined as a typedef (alias) that maps either to
char or to
wchar_t. When you want to write portable code, you should use _TCHAR instead of hard coding
wchar_t data types.
IDE Option "_TCHAR maps to"
The IDE option _TCHAR maps to controls the floating definition of
"_TCHAR maps to" Values:
To set the _TCHAR maps to option, go to the Project > Options > Directories and Conditionals dialog box.
Use "_TCHAR maps to" with
wchar_t for VCL
The VCL is implemented in Unicode and always expects Unicode. To use the VCL, you should set _TCHAR maps to to
wchar_t. For example, the following code does not compile unless you have set _TCHAR maps to to
TResourceStream* res = new TResourceStream(HInstance, ResourceId, RT_RCDATA);
_TCHAR is char,
RT_RCDATA maps to a
char*, but VCL expects
Code Changes Required for Using "_TCHAR maps to" with
Before you can set the _TCHAR maps to option to
wchar_t, your project must have an entry point called either
_tWinMain. New projects created with C++Builder have these entry points by default, but for imported projects you might need to add these entry points by hand. You must also include the tchar.h header file, which contains the floating definitions and the entry points that you need. For a list of the floating functions contained in tchar.h, see Floating Functions.
Use _TEXT Macro before Text Literals
To ensure that character and string literals float properly to ANSI or Unicode, use either the
_T macros. For example:
::MessageBox(0, _TEXT("The message"), _TEXT("The caption"), MB_OK);
With _UNICODE defined, the
_T) macro translates a literal string (character) to the L-prefixed form; otherwise,
_TEXT translates the literal without the
L prefix. For example, if you define _UNICODE, then
translates to the L-prefixed form:
Otherwise, this macro translates without the