Home

TCHAR

TCHAR is a typedef defined in the Windows header tchar.h that provides a generic character type intended to simplify writing code that can be compiled for either ANSI or Unicode character sets. When UNICODE (and often _UNICODE) is defined, TCHAR resolves to wchar_t; otherwise it resolves to char. This enables code to handle text with a single type regardless of build configuration.

The tchar.h header also defines related generic string and pointer types, such as LPTSTR (pointer to TCHAR)

The generic entry points and utilities mirror this mapping: _tmain maps to main or wmain, and _tWinMain

Usage notes: TCHAR originated to ease porting between ANSI and Unicode Windows APIs and to support older

and
LPCTSTR
(pointer
to
const
TCHAR),
as
well
as
a
family
of
character
and
string
function
macros
that
map
to
the
narrow
or
wide
versions,
including
_tcslen,
_tcscpy,
and
_tprintf.
String
literals
can
be
written
with
the
TEXT
or
_T
macro,
which
expands
to
L"..."
in
Unicode
builds
and
"..."
in
ANSI
builds.
maps
to
WinMain
or
wWinMain,
depending
on
the
build.
Code
written
with
TCHAR
and
the
_t*
functions
is
portable
between
Unicode
and
non-Unicode
configurations.
codebases.
In
modern
Windows
development,
using
wchar_t
with
the
wide-character
APIs,
or
explicit
UTF-8
workflows
with
appropriate
conversions,
is
often
preferred.
TCHAR
remains
available
for
maintaining
legacy
code
and
for
projects
that
rely
on
the
Windows
SDK’s
traditional
text
abstractions.
See
tchar.h
for
the
full
set
of
types
and
macros,
and
for
how
UNICODE
and
_UNICODE
influence
mappings.