CString to LPCTSTR
-
How i can convert a CString to LPCTSTR? I can't found an easy solution for this. Please give a help. Thank's bros.
Nothing easier than that:
CString cstr; LPCTSTR lpString = (LPCTSTR)cstr;
:-D Dominik
_outp(0x64, 0xAD);
and__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? ;) (doesn't work on NT) -
How i can convert a CString to LPCTSTR? I can't found an easy solution for this. Please give a help. Thank's bros.
-
You don't need to convert anything, CString has an implicit LPCTSTR cast. If a function takes a
const char*
as parameter, simply take your CString. regards -
For unicode you better use the following
CString cstr; char * myString = (char *) (LPCTSTR) (cstr);
Binayak wrote: char * myString = (char *) (LPCTSTR) (cstr) No, that is wrong. Casting blindly without understanding the underlying strings leads to problems. --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber CP SearchBar v2.0.2 released
-
Binayak wrote: char * myString = (char *) (LPCTSTR) (cstr) No, that is wrong. Casting blindly without understanding the underlying strings leads to problems. --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber CP SearchBar v2.0.2 released
sorry I forgot to put const. this works definitely
(const char *) mystring = (const char *) LPCTSTR(temp) //where temp is the CString
FYI look at: http://www-tcsn.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20702176.html -
For unicode you better use the following
CString cstr; char * myString = (char *) (LPCTSTR) (cstr);
:eek: This is just wrong, whether UNICODE is used or not. If you need me to explain, let me know. Now it's quittin' time! Regards, Alvaro
Hey! It compiles! Ship it.
-
Nothing easier than that:
CString cstr; LPCTSTR lpString = (LPCTSTR)cstr;
:-D Dominik
_outp(0x64, 0xAD);
and__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? ;) (doesn't work on NT)No need to cast:
LPCTSTR lpString = cstr;
Regards, Alvaro
Hey! It compiles! Ship it.
-
sorry I forgot to put const. this works definitely
(const char *) mystring = (const char *) LPCTSTR(temp) //where temp is the CString
FYI look at: http://www-tcsn.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20702176.htmlThat is so wrong in so many ways. First off, if it is a UNICODE build, then you will end up with a pointer to data such as. 0x65 0x00 0x66 0x00 0x97 0x00 To convert from a T string to a const char string, use the following macro: T2CA (temp) Tim Smith I'm going to patent thought. I have yet to see any prior art.
-
For unicode you better use the following
CString cstr; char * myString = (char *) (LPCTSTR) (cstr);
NO. Simply casting an
LPCTSTR
to achar *
simply converts the pointer, not the characters. You must convert the characters, which requires using something likeWideCharToMultiByte
.
Software Zen:
delete this;