What are the various differences between the two symbols TCHAR
and _TCHAR
type defined in the Windows header tchar.h? Explain with examples. Briefly describe scenarios where you would use TCHAR as opposed to _TCHAR in your code. (10 marks)
For ANSI and DBCS platforms, TCHAR is defined as follows: For Unicode platforms, TCHAR is defined as synonymous with the WCHAR type. MAPI clients can use the TCHAR data type to represent a string of either the WCHAR or char type. Be sure to define the symbolic constant UNICODE and limit the platform when it is required.
Use TCHAR instead of char and use TCHAR* instead of char*. TCHAR* can be written LPTSTR. For const TCHAR*, you may write LPCTSTR which is required when a string is passed as an argument to a function where modification should be restricted.
TCHAR can be either char or WCHAR based on the platform. WCHAR is always a 16-bit Unicode character, wchar_t. Show activity on this post. A WCHAR if UNICODE is defined, a CHAR otherwise.
MAPI clients can use the TCHAR data type to represent a string of either the WCHAR or char type. Be sure to define the symbolic constant UNICODE and limit the platform when it is required. MAPI will interpret the platform information and internally translate TCHAR to the appropriate string.
In addition to what @RussC said, TCHAR
is used by the Win32 API and is based on the UNICODE
define, whereas _TCHAR
is used by the C runtime and is based on the _UNICODE
define instead. UNICODE
and _UNICODE
are usually defined/omitted together, making TCHAR
and _TCHAR
interchangable, but that is not a requirement. They are semantically separated for use by different frameworks.
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