Re: problem with cstring to char * convertion
From: Paul G. Tobey [eMVP] (ptobey)
Date: 10/26/04
- Next message: r_z_aret_at_pen_fact.com: "Re: problem with cstring to char * convertion"
- Previous message: Michael Schwab: "CE4.2 INet - 5 minute timeout - code 12002?"
- In reply to: bobby: "Re: problem with cstring to char * convertion"
- Next in thread: r_z_aret_at_pen_fact.com: "Re: problem with cstring to char * convertion"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 26 Oct 2004 12:13:35 -0700
WinSock is expecting an array of bytes when you try to send something. So,
if you have a string that you want to send, and that string is in Unicode,
you must convert it to an array of bytes before passing that array, not the
raw CString, to send. There are multiple ways that you might do this and
since we don't know what's on the other end of your socket, we can't tell
you the right way. Here are some of the possibilities:
1. Send the string as Unicode, two bytes per character. You might do this
by simply casting the CString to TCHAR* and then casting that to char* for
send. You'd have to be sure that you specified the byte order, since this
might not be the same on the other end of the socket.
2. You might define what you do as 'convert to ASCII characters'. If that's
the case, you can use WideCharToMultiByte() to convert the contents of your
CString to a char* string (you have to provide a suitable char buffer to
receive the converted string). If you do this, you'll pass the pointer to
the char buffer to send.
Paul T.
"bobby" <bobby@discussions.microsoft.com> wrote in message
news:162B8753-CC82-42FA-AF9D-0229C3D6BCF0@microsoft.com...
> so what do you suggest that i do to convert it.i tried putting _T before
> it
> to get it converted but it complains for that too..
>
>
>
> "Steffen Offermann" wrote:
>
>> > I am getting the warning as follows
>> > C:\project\project\neighbordiscover\neighbordiscoverDlg.cpp(289) :
>> > warning
>> > C4244: '=' : conversion from 'unsigned short' to 'char', possible loss
>> > of
>> > data
>>
>>
>> CStrings are UNICODE under Windows CE.
>>
>>
>>
>>
>>
- Next message: r_z_aret_at_pen_fact.com: "Re: problem with cstring to char * convertion"
- Previous message: Michael Schwab: "CE4.2 INet - 5 minute timeout - code 12002?"
- In reply to: bobby: "Re: problem with cstring to char * convertion"
- Next in thread: r_z_aret_at_pen_fact.com: "Re: problem with cstring to char * convertion"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|