By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,148 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,148 IT Pros & Developers. It's quick & easy.

std::wstring, TCHAR, wchar_t and LPTSTR

P: n/a
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[]
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"sorty" <so*****@hotmail.com> wrote in message news:bd**************************@posting.google.c om...
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*.
Jul 22 '05 #2

P: n/a
Ron Natalie wrote:
"sorty" <so*****@hotmail.com> wrote in message news:bd**************************@posting.google.c om...

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*.

I suspect you mean "damned". If it was truly damed I don't think we
would care so much :-)
Jul 22 '05 #3

P: n/a
On 24 Nov 2003 08:49:30 -0800, so*****@hotmail.com (sorty) wrote:
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 <tchar> or <tchar.h>.
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.

--
Bob Hairgrove
No**********@Home.com
Jul 22 '05 #4

P: n/a
Bob Hairgrove wrote:
On 24 Nov 2003 08:49:30 -0800, so*****@hotmail.com (sorty) wrote:
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 <tchar> or <tchar.h>.


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

Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.