Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > string to const TCHAR problems

Reply
Thread Tools

string to const TCHAR problems

 
 
ree
Guest
Posts: n/a
 
      10-19-2003
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
 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      10-19-2003

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


 
Reply With Quote
 
 
 
 
ree
Guest
Posts: n/a
 
      10-19-2003
"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");
 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      10-19-2003
> > 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 --


 
Reply With Quote
 
ree
Guest
Posts: n/a
 
      10-19-2003
"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);



 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      10-19-2003
> > - 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


 
Reply With Quote
 
ree
Guest
Posts: n/a
 
      10-19-2003
"Phlip" <> wrote in
news:9Dnkb.5685$ m:


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

 
Reply With Quote
 
ree
Guest
Posts: n/a
 
      10-19-2003
ree <> wrote in news:Xns94199B34941A0reehotmailcoom@
210.49.20.254:

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



Dont worry found another way to do it. Thanks for all your help.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const vector<A> vs vector<const A> vs const vector<const A> Javier C++ 2 09-04-2007 08:46 PM
Casting int'** to 'const int * const * const' dosn't work, why? Jonas.Holmsten@gmail.com C Programming 11 07-01-2007 06:16 PM
What to prefer - TCHAR arrays, std::string or std::wstring ? rohitpatel9999@yahoo.com C++ 14 08-03-2006 06:42 PM
TCHAR in c++ to string in java dwurity@yahoo.com Java 7 12-14-2004 05:49 PM
TCHAR in c++ to string in java Bobby Java 0 12-14-2004 01:21 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57