string to const TCHAR problems

R

ree

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
 
R

Ron Natalie

ree said:
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.
 
R

ree

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");
 
P

Phlip

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
- learn C++ first before learning MFC. (MS should
have followed that one.)

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

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

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

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

- try on
Are you starting to see any subtle hints in my post?
 
R

ree

- 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
- 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);
 
P

Phlip

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

ree

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top