Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

should I eliminate TCHAR from Windows code?

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?

like image 307
vy32 Avatar asked Jun 11 '11 11:06

vy32


People also ask

What is Tchar?

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).

What does Tchar H do?

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.

What is Tchar h in C++?

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.

What is _t in MFC?

_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.


1 Answers

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.

like image 156
David Heffernan Avatar answered Sep 23 '22 20:09

David Heffernan