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.

See also

WinAPI data types and constants
The GCC option -municode.
Unicode
wchar_t

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Windows/...', 1740454273, '3.18.110.214', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Windows/development/WinAPI/data-types/Definition-of-TCHAR-and-TEXT-depending-on-UNICODE(102): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78