std::wstring, TCHAR, wchar_t and LPTSTR

S

sorty

Hi,

I have read in many places that TCHAR can be 'char' or 'wchar_t'
depending on ANSI or UNICODE.

I have also read that LPTSTR is a long pointer to a TCHAR.

I am confused about the following. Please answer with yes/no and then
elaborate as you please..

1. Where is TCHAR, LPTSTR defined

2. Is TCHAR for MFC apps only? Can I use it in a standard console app?

3. Is LPTSTR for MFC apps only? Can I use it in a standard console
app?

4. Is TCHAR and LPTSTR portable to other platforms such as UNIX?

5. Why would I use LPTSTR when I can just use a pointer to TCHAR eg
TCHAR *ch[]
 
R

Ron Natalie

sorty said:
I have read in many places that TCHAR can be 'char' or 'wchar_t'
depending on ANSI or UNICODE.

You need to discuss this on a group with microsoft in it's name, but the
above is correct.
I have also read that LPTSTR is a long pointer to a TCHAR.

It's not a long pointer to anything (damed MS stupidity). It's TCHAR*.
 
G

Gianni Mariani

Ron said:
You need to discuss this on a group with microsoft in it's name, but the
above is correct.




It's not a long pointer to anything (damed MS stupidity). It's TCHAR*.


I suspect you mean "damned". If it was truly damed I don't think we
would care so much :)
 
B

Bob Hairgrove

Hi,

I have read in many places that TCHAR can be 'char' or 'wchar_t'
depending on ANSI or UNICODE.

TCHAR is a Windows macro ... use std::_TCHAR instead which is defined
in said:
I have also read that LPTSTR is a long pointer to a TCHAR.
I am confused about the following. Please answer with yes/no and then
elaborate as you please..

1. Where is TCHAR, LPTSTR defined


LPTSTR and TCHAR are defined somewhere in the Windows header files.
2. Is TCHAR for MFC apps only? Can I use it in a standard console app?

You can use it anywhere as long as you include the header file(s)
where it is defined. It is not specific to MFC.
3. Is LPTSTR for MFC apps only? Can I use it in a standard console
app?

Same as above.
4. Is TCHAR and LPTSTR portable to other platforms such as UNIX?

No. Use _TCHAR and _TCHAR* instead.
5. Why would I use LPTSTR when I can just use a pointer to TCHAR eg
TCHAR *ch[]

All over the Windows API functions are declared this way. Who knows
whether someday they will be defined differently? Using the same
macros -- distasteful as they may be -- would keep your code from
breaking if they were ever redefined.
 
R

Rolf Magnus

Bob said:
TCHAR is a Windows macro ... use std::_TCHAR instead which is defined
in <tchar> or <tchar.h>.

Still Windows specific though. Btw, wtf does it do in the std namespace?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top