Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differentiate between TCHAR and _TCHAR

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)

like image 688
Agnel Kurian Avatar asked Jun 01 '10 10:06

Agnel Kurian


People also ask

What is a Tchar data type?

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.

Can I use Tchar instead of char in C++?

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.

What is the difference between a char and a wchar?

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.

How do I use Tchar data type in MAPI?

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.


1 Answers

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.

like image 163
Remy Lebeau Avatar answered Sep 28 '22 18:09

Remy Lebeau