Convert CString to char *
-
How can I convert a CString to a char * variable? CString str; char *szBuffer; //code . . . szBuffer = (const char *) str; //why does this not work, and what do I have to do?
-
How can I convert a CString to a char * variable? CString str; char *szBuffer; //code . . . szBuffer = (const char *) str; //why does this not work, and what do I have to do?
-
Rage wrote: TCHAR *szBuffer=(LPTSTR)(LPCTSTR)str; This only works is you do not write into the CString. If you really need to write into it, you have to use
GetBuffer()
/ReleaseBuffer()
.
My opinions may have changed, but not the fact that I am right.
-
Rage wrote: TCHAR *szBuffer=(LPTSTR)(LPCTSTR)str; This only works is you do not write into the CString. If you really need to write into it, you have to use
GetBuffer()
/ReleaseBuffer()
.
My opinions may have changed, but not the fact that I am right.
-
Yep, I know, but in his initial example he tried to typecaste in a const char *, so ... ~RaGE();
Yeah, but that type of stuff IS really dangerous. It works once you understood when to use it (at a
InsertItem()
with aLVITEM
/TVITEM.pszText
for example). But IMHO it is nothing to tell beginners. Shhhh!:-D
My opinions may have changed, but not the fact that I am right.
-
NO NO NO. :mad: Please don't encourage people to throw casts in without understanding the initial cause of their problem. The
GetBuffer()
method exists for precisely this case. --Mike-- Latest blog entry: *drool* (Alyson) [May 10] Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber "You have Erica on the brain" - Jon Sagara to me