Search notes:
WinAPI: Definition of TCHAR, TEXT etc. depending on UNICODE
When including
<windows.h>
(or more accurately, when including
<winnt.h>
), the
preprocessor defines the
macros TCHAR
and
TEXT
depending on the defined value of
UNICODE
(manually edited for simplicity and clarity):
// From WinDef.h
#define CONST const
// UNICODE (Wide Character) types -- 340
typedef wchar_t WCHAR;
// typedef CONST WCHAR *LPCWCH, *PCWCH; -- 351
typedef CONST WCHAR *LPCWSTR, *PCWSTR; -- 357
// ANSI (Multi-bypte Character) types -- 416
typedef CONST CHAR *LPCSTR, *PCSTR; -- 424
#ifdef UNICODE
typedef WCHAR TCHAR , *PTCHAR;
typedef LPCWSTR PCTSTR, LPCTSTR;
#define __TEXT(quote) L##quote
#else
typedef char TCHAR, *PTCHAR;
typedef LPCSTR PCTSTR, LPCTSTR
#define __TEXT(quote) quote
#endif
#define TEXT(quote) __TEXT(quote)
This makes it possible to use the same source code when compiling for ansi or wide character targets (See
WinAPI: A
and W
functions .)
Generic Unicode Ansi (Multibyte)
TCHAR
WCHAR
char
PCTSTR
/ LPCTSTR
LPCWSTR
PCTSTR
_UNICODE
While
UNICODE
is used to direct
WinAPI functions, the macro
_UNICODE
is used for a similar purpose for standard C functions (such as
printf
or
fopen
).
TODO
Similarly to
TCHAR
that is dependent on the defition of
UNICODE
there is also a
CRT _TCHAR
that is dependent on the definition of
_UNICODE
.