Reputation: 7
I am learning about win32 api .The TCHAR datatype is used in it for defining stings that are used for registering the class.Why is TCHAR used there?
Upvotes: 1
Views: 558
Reputation: 308206
TCHAR
was a crutch created by Microsoft when they were transitioning from code page based characters to Unicode. They wanted an easy way for people to transition their code, so they created a compiler flag that determined whether you were going to do things the old way or the new way. TCHAR
is a macro that expands to char
for the old way or wchar_t
for the new way. Each of the Windows API functions also gets a macro which appends A
for the old style functions or W
for the new functions.
If you're starting a new program, you should definitely use Unicode and forget about all that old baggage. Microsoft is forced to keep using it because they're the kings of backwards compatibility, and there are 20-year-old programs out there that will never be updated to Unicode. That doesn't mean you need to care.
Upvotes: 1
Reputation: 2609
TCHAR is a macro that either expands to char, when UNICOE is not defined, or wchar_t, when UNICODE is defined.
TCHAR is used because of every function there is a A- and W-function. There is also a define for each function, which consists of the function name without W or A. This macro is defined as the W-function, when UNICODE is defined or as the A-function, when UNICODE is not defined.
TCHAR can be used together with the define of each function, consisting only of the function name without A or W.
Upvotes: 0