Reputation: 11098
I've opened winnt.h header file and found there this two lines:
typedef wchar_t WCHAR;
and
typedef WCHAR TCHAR, *PTCHAR;
but there was comment in one of my posts that there is some difference between them. Then what is the difference?
Upvotes: 16
Views: 28684
Reputation: 6563
TCHAR
is portable type which is char
for ANSI type projects and WCHAR
(16-bit Unicode char) for UNICODE projects. Using TCHAR
and TCHAR *
/LPSTR
you can create portable project which can easily be recompiled for ANSI and UNICODE version. But after Windows 98/ME become obsolete and rarely used, there is no need to create non-Unicode executables.
Upvotes: 0
Reputation: 2361
Technically speaking there is no difference because you cannot typedef two different entities to a single one. Let us See An Example...
typedef char a;
typedef char b;
typedef a b, c;
This Definition Works But If a Change The Above Definition To This
typedef char a;
typedef char * b;
typedef a b, c;
Error 1 error C2040: 'b' : 'a' differs in levels of indirection from 'char *'
Another One
typedef char a;
typedef int b;
typedef a b, c;
Error 1 error C2371: 'b' : redefinition; different basic types
So By Analyzing These Things Only Same Type Can Defined Together.
Upvotes: 0
Reputation: 9893
TCHAR
can be either char
or WCHAR
based on the platform. WCHAR
is always a 16-bit Unicode character, wchar_t
.
Upvotes: 12
Reputation: 9503
http://msdn.microsoft.com/en-us/library/aa383751%28VS.85%29.aspx
TCHAR:
A WCHAR if UNICODE is defined, a CHAR otherwise.
WCHAR:
A 16-bit Unicode character. For more information, see Character Sets Used By Fonts.
Upvotes: 7
Reputation: 100050
If you read the entire header, you will find:
#ifdef _UNICODE
typedef WCHAR TCHAR;
#else
typedef char TCHAR;
#endif
or words to that effect.
Perhaps MS has removed the narrow option of late.
Upvotes: 20