I have to agree with Sascha. The underlying premise of TCHAR
/ _T()
/ etc. is that you can write an "ANSI"-based application and then magically give it Unicode support by defining a macro. But this is based on several bad assumptions:
That you actively build both MBCS and Unicode versions of your software
Otherwise, you will slip up and use ordinary char*
strings in many places.
That you don't use non-ASCII backslash escapes in _T("...") literals
Unless your "ANSI" encoding happens to be ISO-8859-1, the resulting char*
and wchar_t*
literals won't represent the same characters.
That UTF-16 strings are used just like "ANSI" strings
They're not. Unicode introduces several concepts that don't exist in most legacy character encodings. Surrogates. Combining characters. Normalization. Conditional and language-sensitive casing rules.
And perhaps most importantly, the fact that UTF-16 is rarely saved on disk or sent over the Internet: UTF-8 tends to be preferred for external representation.
That your application doesn't use the Internet
(Now, this may be a valid assumption for your software, but...)
The web runs on UTF-8 and a plethora of rarer encodings. The TCHAR
concept only recognizes two: "ANSI" (which can't be UTF-8) and "Unicode" (UTF-16). It may be useful for making your Windows API calls Unicode-aware, but it's damned useless for making your web and e-mail apps Unicode-aware.
That you use no non-Microsoft libraries
Nobody else uses TCHAR
. Poco uses std::string
and UTF-8. SQLite has UTF-8 and UTF-16 versions of its API, but no TCHAR
. TCHAR
isn't even in the standard library, so no std::tcout
unless you want to define it yourself.
What I recommend instead of TCHAR
Forget that "ANSI" encodings exist, except for when you need to read a file that isn't valid UTF-8. Forget about TCHAR
too. Always call the "W" version of Windows API functions. #define _UNICODE
just to make sure you don't accidentally call an "A" function.
Always use UTF encodings for strings: UTF-8 for char
strings and UTF-16 (on Windows) or UTF-32 (on Unix-like systems) for wchar_t
strings. typedef
UTF16
and UTF32
character types to avoid platform differences.