Re: Cast CString to unsigned char*
From: Nathan Holt (nathanh_at_ccei-nm.com)
Date: 08/06/04
- Next message: Vincent Finn: "Re: Mfc dead ?"
- Previous message: Trevor: "Re: CoCreateInstance"
- In reply to: Dan Bloomquist: "Re: Cast CString to unsigned char*"
- Next in thread: Simon: "Re: Cast CString to unsigned char*"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 6 Aug 2004 09:20:16 -0600
"Dan Bloomquist" <EXTRApublic20@lakeweb.com> wrote in message
news:41113785.1060109@lakeweb.com...
>
>
> Frank E Rogers wrote:
> > Is there anyone who can tell me how to cast a CString to unsigned char*
?
>
> use two casts:
> (unsigned char*)(LPCTSTR)str;
>
> The LPCTSTR cast is necessary to invoke the overloaded operator of
> CString to return a pointer. Once you have that pointer, you can recast
it.
>
> Best, Dan.
>
> --
> http://lakeweb.net
> http://ReserveAnalyst.com
> No EXTRA stuff for email.
As for (unsigned char*)(LPCTSTR)str; I recommend NOT doing that. It may
be useful for calling functions in a library that isn't const correct, but
I'd tend to assume that such a library actually does change the characters
in the string. This is bad because the string buffer may be shared with
several other string objects, and a change to the string's characters will
change all of the strings that use the buffer.
The proper way to get an "unsigned char *" is to use GetBuffer and call
ReleaseBuffer after you are done with it. You may have to cast the result
of GetBuffer from "char *" to "unsigned char *".
Nathan Holt
- Next message: Vincent Finn: "Re: Mfc dead ?"
- Previous message: Trevor: "Re: CoCreateInstance"
- In reply to: Dan Bloomquist: "Re: Cast CString to unsigned char*"
- Next in thread: Simon: "Re: Cast CString to unsigned char*"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|