string to const TCHAR problems

Discussion in 'C++' started by ree, Oct 19, 2003.

  1. ree

    ree Guest

    I need to use a function from a wininet library, it requires the use of
    const TCHAR.
    The problem is the value needs to be calculated, so at the end I have this
    string but I am having troubles converting it into a const TCHAR so I can
    use it in the function.

    TIA
    ree, Oct 19, 2003
    #1
    1. Advertising

  2. ree

    Ron Natalie Guest

    "ree" <> wrote in message news:Xns94196DA40EEBDreehotmailcoom@210.49.20.254...
    > I need to use a function from a wininet library, it requires the use of
    > const TCHAR.
    > The problem is the value needs to be calculated, so at the end I have this
    > string but I am having troubles converting it into a const TCHAR so I can
    > use it in the function.


    TCHAR is a microsoft specific typedef for either char or wchar_t (or perhaps
    unsigned short knowing these clowns). It's a single character, not a string.
    You'd be better off asking on microsoft.public.vc.mfc but show a better example
    there of what you are trying to do.
    Ron Natalie, Oct 19, 2003
    #2
    1. Advertising

  3. ree

    ree Guest

    "Ron Natalie" <> wrote in
    news:3f91e248$0$165$:


    > TCHAR is a microsoft specific typedef for either char or wchar_t (or
    > perhaps unsigned short knowing these clowns). It's a single
    > character, not a string. You'd be better off asking on
    > microsoft.public.vc.mfc but show a better example there of what you
    > are trying to do.
    >



    oops sorry its actually a static TCHAR[]....eg.

    static TCHAR hdrs[] = _T("Content-Type: application/x-www-form-rlencoded");
    ree, Oct 19, 2003
    #3
  4. ree

    Phlip Guest

    > > TCHAR is a microsoft specific typedef for either char or wchar_t (or
    > > perhaps unsigned short knowing these clowns). It's a single
    > > character, not a string. You'd be better off asking on
    > > microsoft.public.vc.mfc but show a better example there of what you
    > > are trying to do.

    >
    > oops sorry its actually a static TCHAR[]....eg.
    >
    > static TCHAR hdrs[] = _T("Content-Type:

    application/x-www-form-rlencoded");

    At this juncture we frequently find ourselves reminding newbies...

    - try on news:microsoft.public.vc.mfc

    - learn C++ first before learning MFC. (MS should
    have followed that one.)

    - try on news:microsoft.public.vc.mfc

    - don't use TCHAR unless you intend to turn on the
    magic UNICODE option, which you probably won't.

    - try on news:microsoft.public.vc.mfc

    - Use a CString. It will match TCHAR's type, and
    it has the common set of string operations

    - try on news:microsoft.public.vc.mfc

    - post some of /your/ code - we know what a
    TCHAR looks like

    - try on news:microsoft.public.vc.mfc

    - if you absolutely must use std::string, yield its
    char const * using myString.c_str()

    - try on news:microsoft.public.vc.mfc

    Are you starting to see any subtle hints in my post?

    --
    Phlip
    http://www.greencheese.org/BrunoTheBandit
    -- The smoker you drink, the programmer you get --
    Phlip, Oct 19, 2003
    #4
  5. ree

    ree Guest

    "Phlip" <> wrote in news:5wmkb.12781$u6.4228
    @newssvr33.news.prodigy.com:

    >
    >
    > - learn C++ first before learning MFC. (MS should
    > have followed that one.)
    >
    >
    > - don't use TCHAR unless you intend to turn on the
    > magic UNICODE option, which you probably won't.
    >
    > - try on news:microsoft.public.vc.mfc
    >
    > - Use a CString. It will match TCHAR's type, and
    > it has the common set of string operations
    >
    >
    > - post some of /your/ code - we know what a
    > TCHAR looks like
    >
    >
    > - if you absolutely must use std::string, yield its
    > char const * using myString.c_str()
    >
    >


    I am not sure if the problem is entirely TCHAR, it was just that I
    didn't how to get a string variable into a constant expression. I just
    thought there is something I am missing. Anyway I will try the ms
    newsgroup.

    Here is an example...
    ----------
    static TCHAR frmdata2[] = _T("action=checkpassword&new_loc=%2Fbin");


    I need to get the string variable in there
    i.e
    static TCHAR frmdata2[] = _T(string_variable);
    ree, Oct 19, 2003
    #5
  6. ree

    Phlip Guest

    > > - try on news:microsoft.public.vc.mfc
    > >
    > > - if you absolutely must use std::string, yield its
    > > char const * using myString.c_str()

    >
    > I am not sure if the problem is entirely TCHAR, it was just that I
    > didn't how to get a string variable into a constant expression. I just
    > thought there is something I am missing. Anyway I will try the ms
    > newsgroup.
    >
    > Here is an example...
    > ----------
    > static TCHAR frmdata2[] = _T("action=checkpassword&new_loc=%2Fbin");
    >
    >
    > I need to get the string variable in there
    > i.e
    > static TCHAR frmdata2[] = _T(string_variable);


    The function you want to call does not care about the 'static' or [], so you
    could just pass string_variable.c_str() directly into that function. You
    have copied example code and tried to change it without understanding it
    first.

    Try this question on news:microsoft.public.vc.mfc . But read a book about
    C++. Asking this newsgroup to spoon-feed you the most basic things about how
    the language works wastes both your time and ours.

    --
    Phlip
    Phlip, Oct 19, 2003
    #6
  7. ree

    ree Guest

    "Phlip" <> wrote in
    news:9Dnkb.5685$:


    >
    > The function you want to call does not care about the 'static' or [],
    > so you could just pass string_variable.c_str() directly into that
    > function. You have copied example code and tried to change it without
    > understanding it first.


    I tried what you said but it just gives me an error

    error C2664: 'HttpSendRequestA' : cannot convert parameter 4 from 'const
    char *' to 'void *'
    ree, Oct 19, 2003
    #7
  8. ree

    ree Guest

    ree <> wrote in news:Xns94199B34941A0reehotmailcoom@
    210.49.20.254:

    > "Phlip" <> wrote in
    > news:9Dnkb.5685$:
    >
    >



    Dont worry found another way to do it. Thanks for all your help.
    ree, Oct 19, 2003
    #8
    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. Replies:
    7
    Views:
    1,241
    MaSTeR
    Dec 14, 2004
  2. Bobby
    Replies:
    0
    Views:
    386
    Bobby
    Dec 14, 2004
  3. sorty
    Replies:
    4
    Views:
    20,692
    Rolf Magnus
    Nov 25, 2003
  4. Replies:
    14
    Views:
    4,369
    Phlip
    Aug 3, 2006
  5. Javier
    Replies:
    2
    Views:
    533
    James Kanze
    Sep 4, 2007
Loading...

Share This Page