Confused about strings - Programmer

This is a discussion on Confused about strings - Programmer ; Hello there. I have been using C and C++ in DOS for a number of years, but I am now taking my first steps into Windows programming, with Windows XP and Visual C++ Express. I understand how strings work in ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Confused about strings

  1. Confused about strings

    Hello there. I have been using C and C++ in DOS for a number of years,
    but I am now taking my first steps into Windows programming, with
    Windows XP and Visual C++ Express. I understand how strings work in C,
    but this set-up uses something slightly different, and I am getting
    confused. Could someone talk me through it?

    As I understand it, the functions use TCHARs instead of chars. These
    seem to be "wide characters" on my system, but as I understand it the
    point is that I don't worry about what TCHARs are, I let the program
    sort all that out for me.

    This means that I have to use slightly different functions, but I'm not
    entirely sure which. So far I have been replacing strlen, strcpy,
    strcat and sprintf with lstrlen, _tcscpy, _tcscat and _stprintf, but I
    can't help feeling that I'm guessing. In particular, the fact that one
    has an l where the others have a t suggests I'm doing something wrong.

    And what's the difference between a TCHAR * and a LPCTSTR?

    I'd be grateful if anyone could explain this to me.

    If this is not the best newsgroup for this sort of question, I'd also
    be grateful if someone could point me to a better one.

    Thanks very much.
    Paul.


  2. Re: Confused about strings

    On 30 Sep 2006 09:51:18 -0700, gw7rib@aol.com wrote:

    >Hello there. I have been using C and C++ in DOS for a number of years,
    >but I am now taking my first steps into Windows programming, with
    >Windows XP and Visual C++ Express. I understand how strings work in C,
    >but this set-up uses something slightly different, and I am getting
    >confused. Could someone talk me through it?
    >
    >As I understand it, the functions use TCHARs instead of chars. These
    >seem to be "wide characters" on my system, but as I understand it the
    >point is that I don't worry about what TCHARs are, I let the program
    >sort all that out for me.


    TCHAR and its relatives provide support for UNICODE strings. So you
    can find some more info by using google
    (http://groups.google.com/advanced_group_search) to look up
    unicode
    in this newsgroup. If you have enabled browsing in VC (2 places in
    Project->Settings), then you can right-click on TCHAR and then see the
    actual definition of TCHAR. You will find that it is defined in a file
    called tchar.h. This file is not meant for human readers (I sure
    needed several tries), but I strongly recommend reading it; it is the
    authority and will answer several of your questions.

    Also, if you use browsing to look up the definition of any "function"
    that uses string arguments, you will see the function name is actually
    a macro. I'll let you discover that yourself, so the Ahah moment is
    stronger (although it may take a bit).


    >
    >This means that I have to use slightly different functions, but I'm not
    >entirely sure which. So far I have been replacing strlen, strcpy,
    >strcat and sprintf with lstrlen, _tcscpy, _tcscat and _stprintf, but I
    >can't help feeling that I'm guessing. In particular, the fact that one
    >has an l where the others have a t suggests I'm doing something wrong.
    >
    >And what's the difference between a TCHAR * and a LPCTSTR?


    Look in tchar.h for the definitions of both.


    >
    >I'd be grateful if anyone could explain this to me.
    >
    >If this is not the best newsgroup for this sort of question, I'd also
    >be grateful if someone could point me to a better one.
    >
    >Thanks very much.
    >Paul.


    -----------------------------------------
    To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

    Robert E. Zaret, eMVP
    PenFact, Inc.
    20 Park Plaza, Suite 478
    Boston, MA 02116
    www.penfact.com


+ Reply to Thread