I am revising some very old (10 years) C code. The code compiles on Unix/Mac with GCC and cross-compiles for Windows with MinGW. Currently there are TCHAR strings throughout. I'd like to get rid of the TCHAR and use a C++ string instead. Is it still necessary to use the Windows wide functions, or can I do everything now with Unicode and UTF-8?
TCHAR is simply a macro that expands to char in ANSI builds (i.e. _UNICODE is not defined) and wchar_t in Unicode builds ( _UNICODE is defined). There are various string types based on the TCHAR macro, such as LPCTSTR (long pointer to a constant TCHAR string).
By using the tchar. h, you can build single-byte, Multibyte Character Set (MBCS), and Unicode applications from the same sources. tchar. h defines macros (which have the prefix _tcs ) that, with the correct preprocessor definitions, map to str , _mbs , or wcs functions, as appropriate.
For multibyte character set : TCHAR stands for char (simple character of 1 byte) For Unicode character set: TCHAR stands for wchar (Wide character of 2 byte) For example : If your Visual Studio project setting have character set = Multi byte character set.
_T stands for “text”. It will turn your literal into a Unicode wide character literal if and only if you are compiling your sources with Unicode support.
Windows uses UTF16 still and most likely always will. You need to use wstring
rather than string
therefore. Windows APIs don't offer support for UTF8 directly largely because Windows supported Unicode before UTF8 was invented.
It is thus rather painful to write Unicode code that will compile on both Windows and Unix platforms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With