std::wstring, TCHAR, wchar_t and LPTSTR

Discussion in 'C++' started by sorty, Nov 24, 2003.

  1. sorty

    sorty Guest

    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[]
     
    sorty, Nov 24, 2003
    #1
    1. Advertising

  2. sorty

    Ron Natalie Guest

    "sorty" <> wrote in message news:...

    > 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*.
     
    Ron Natalie, Nov 24, 2003
    #2
    1. Advertising

  3. Ron Natalie wrote:
    > "sorty" <> wrote in message news:...
    >
    >
    >>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 :)
     
    Gianni Mariani, Nov 24, 2003
    #3
  4. On 24 Nov 2003 08:49:30 -0800, (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
     
    Bob Hairgrove, Nov 24, 2003
    #4
  5. sorty

    Rolf Magnus Guest

    Bob Hairgrove wrote:

    > On 24 Nov 2003 08:49:30 -0800, (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?
     
    Rolf Magnus, Nov 25, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Adrian Cornish
    Replies:
    2
    Views:
    8,243
    Adrian Cornish
    Jul 12, 2003
  2. He Shiming
    Replies:
    8
    Views:
    4,934
    Stephen Howe
    Jan 3, 2005
  3. Vinu
    Replies:
    1
    Views:
    1,453
    msalters
    Aug 4, 2005
  4. Replies:
    14
    Views:
    4,444
    Phlip
    Aug 3, 2006
  5. Jeffrey Walton
    Replies:
    10
    Views:
    964
    Mathias Gaunard
    Nov 26, 2006
Loading...

Share This Page