Share via


TCHAR vs _TCHAR

Question

Friday, July 21, 2006 10:44 PM | 1 vote

For the life of me, I can't figure out how to deal with strings in Visual C++.

What is the difference between TCHAR and _TCHAR?

The built-in help is very confusing.  Thank you.

All replies (5)

Friday, July 21, 2006 11:39 PM ✅Answered | 3 votes

TCHAR and _TCHAR are identical, although since TCHAR doesn't have a leading underscore, Microsoft aren't allowed to reserved it as a keyword (imagine if you had a variable called TCHAR. Think what would happen). Hence TCHAR will not be #defined when Language Extensions are disabled (/Za).

TCHAR is defined in winnt.h (which you'll get when you #include <windows.h>), and also tchar.h under /Ze.
_TCHAR is available only in tchar.h (which also #defines _TSCHAR and _TUCHAR). Those are unsigned/signed variants of the normal TCHAR data type.

You've probably already read it, but just in case, the strings section of Codeproject has useful info.


Saturday, July 22, 2006 3:17 AM ✅Answered | 2 votes

TCHAR is defined as wchar_t in a Unicode build, but as char in a non Unicode build.  So if you're not using Unicode (i.e. don't have _UNICODE defined in the project's preprocessor settings), then you can simply pass in the TCHAR str[256] to a function that expects a char * , otherwise you will have to convert the string from Unicode to non-Unicode using wcstombs function.


Friday, July 21, 2006 11:56 PM

OShah, thanks for your reply.

By the way, I have some existing C code that I know works:

void myfunction(char *string) { ... }

If I have a string, say: TCHAR str[256], how do I pass it to myfunction()
which expects a char *?

Thank you.


Monday, April 30, 2007 9:47 PM

 

 

Hi, Friends.

 

I have programed in Autolisp for some years, and now I am learning C++ an Object ARX.

 

 

I have bougth a book : Programing Autocad 2000 in Objecto ARX and I am facing this new challenge,

 

I need some help , if you please. From you or some tutorial you could point to me.

 

I am using Autocad 2007 and Visual Studio 2005

 

I have these lines of code, and error messages, about string types char , tchar and achar

 

Variable declaration:

TCHAR kw[20];

 

Code line:

rc = acedGetKword(L"\nLinetype - [Name/List/Continuous]<Continuous>: ", kw);

 

 

Error message:

 

Error 3 error C2664: 'acedGetKword' : cannot convert parameter 2 from 'TCHAR [20]' to 'ACHAR *' 

 

 

 

Thanks for your help.

 


Tuesday, May 1, 2007 12:03 AM

What is ACHAR defined as, that is the important thing here. If TCHAR and ACHAR are not the same types then you need to convert kw to be the same type as ACHAR.
Could you find out what ACHAR is, that way we could give more help.