Click to See Complete Forum and Search --> : Why TCHAR?
Stern_Pea
May 1st, 2003, 02:51 AM
hi everybody:
I'm reading Programming Windows
Always see this : static TCHAR szAppName[]=TEXT("KeyView");
I'm puzzled why "TCHAR" and Why "TEXT" and why not use standard c/c++ ?
in MSDN it says " The TCHAR data type is a Win32 character string that can be used to describe ANSI, DBCS, or Unicode strings. For ANSI and DBCS platforms, TCHAR is defined as follows:
typedef char TCHAR;
For Unicode platforms, TCHAR is defined as synonymous with the WCHAR type.
"
can anyone tell me the function of "TEXT" and "TCHAR"?
The most important ..Are you use that in your progamme?
Thank you a lot:D
Sean O'Connor
May 1st, 2003, 03:07 AM
can anyone tell me the function of "TEXT" and "TCHAR"?
The most important ..Are you use that in your progamme?
TCHAR's are used because not all non-english characters can be found in the standard 8 bit, 256 character set which is what a CHAR is. A TCHAR is 16 bits so it's possible to encode a vast number of non-english characters.
I use them in my Pocket PC apps only because you have no choice but to. I don't use them at all in my Windows apps because they take up double the space and I've never seen a need for them. I've got "Programming Windows" too but I just ignore all the TCHAR stuff myself.
Sean.
rxbagain
May 1st, 2003, 03:19 AM
TCHAR is used to simplify the porting of program from UNICODE and ANSI and vice versa.
for example you, you have a code like this.
char s1[100];
char s2[100];
char s2[100];
If you port this to UNICODE (eg. CE App) you have to change it to this
WCHAR s1[100];
WCHAR s2[100];
WCHAR s2[100];
To simplify it, you define it using TCHAR, for ANSI, just make this
TCHAR s1[100];
TCHAR s2[100];
TCHAR s2[100];
to make it a UNICODE program, add this to your code
#define UNICODE
and the compiler will do the conversion from char[100] to WCHAR[100]
That's how it works. The TEXT works the same
Hope this will help you
Stern_Pea
May 1st, 2003, 07:37 AM
Thank all of you very much ...
helps me a lot
I'm a newbie .. Known little about windows programming ...:D
Freeman Yan
May 1st, 2003, 10:55 PM
rxbagain, your post is really good!
But I still have some questions:
When shall I use the unicode?
What's the default for Windows english version, ASCII or unicode?
Any difference between Windows 9X, 2000 and XP?
Thanks!
rxbagain
May 1st, 2003, 11:09 PM
Win9X by uses the MutiByte character code (ASCII).
NT platforms (NT, 2000, XP) uses UNICODE by default, but u can as well use the Multibyte characters in your program
CE uses only UNICODE.
Unicode programming is used if you want to make a program that will run on UNICODE systems (NT, 200, XP, CE). This will limit your system targets but it will make faster for your program to manipulate strings because it there is no need for the system to translate from ASCII to UNICODE and vice versa.
Hope this will clarify your concern.
Freeman Yan
May 1st, 2003, 11:30 PM
Thanks!
hankdane
May 5th, 2003, 12:08 PM
Originally posted by Sean O'Connor
I don't use them at all in my Windows apps because they take up double the space and I've never seen a need for them.
This is not true. (Well, you may not see a need for TCHARs, but the first part...)
In an ANSI build, a TCHAR is just like a char, and does not take up extra space. In a UNICODE build, true, then the TCHARs are converted to wide chars, and take up the extra space. But presumably, you would only build your project in UNICODE if you needed to support unicode. Sure, wide chars take up extra space, but they are worth it if you want to support any language.
Personally, I only use TCHARs and WCHARs, I never use straight char's anymore.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.