Click here to Skip to main content
16,012,153 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how to cast cstring into char*? Pin
Ryan Binns22-Jun-04 18:34
Ryan Binns22-Jun-04 18:34 
AnswerRe: how to cast cstring into char*? Pin
Nitron22-Jun-04 8:02
Nitron22-Jun-04 8:02 
GeneralRe: how to cast cstring into char*? Pin
David Crow22-Jun-04 8:24
David Crow22-Jun-04 8:24 
GeneralRe: how to cast cstring into char*? Pin
Nitron22-Jun-04 8:44
Nitron22-Jun-04 8:44 
GeneralRe: how to cast cstring into char*? Pin
David Crow22-Jun-04 9:20
David Crow22-Jun-04 9:20 
GeneralRe: how to cast cstring into char*? Pin
vividwu22-Jun-04 8:57
vividwu22-Jun-04 8:57 
GeneralRe: how to cast cstring into char*? Pin
palbano22-Jun-04 9:35
palbano22-Jun-04 9:35 
AnswerRe: how to cast cstring into char*? Pin
mtzlplyk22-Jun-04 10:33
mtzlplyk22-Jun-04 10:33 
Let the programmer do the thinking, let the compiler do the work

You can pass a CString object to any function that expects a LPCTSTR, the compiler will extract a pointer to the CString's internal buffer so all you need to do is ...

void foo( LPCTSTR lpszBuffer )<br />
{<br />
    //  do stuff,<br />
}<br />
<br />
<br />
CString strData(_T("12345"));<br />
foo(strData);


The LPCTSTR data type is a pointer to a constant string (ansi or unicode), if you dont have UNICODE defined, LPCTSTR maps to LPCSTR which is defined as "a Pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters" i.e const char *

OR, if all you want to do is to copy the CString buffer to a char[] use strcpy(), strncpy, or _tcscpy(), _tcsncpy() e.g. strcpy(MyBuffer, LPCTSTR(MyCString));
GeneralSimple Question - About Box Pin
sweep12322-Jun-04 6:50
sweep12322-Jun-04 6:50 
GeneralRe: Simple Question - About Box Pin
Maximilien22-Jun-04 6:52
Maximilien22-Jun-04 6:52 
GeneralRe: Simple Question - About Box Pin
Ryan Binns22-Jun-04 18:38
Ryan Binns22-Jun-04 18:38 
GeneralRe: Simple Question - About Box Pin
jmkhael22-Jun-04 7:01
jmkhael22-Jun-04 7:01 
GeneralRe: Simple Question - About Box Pin
David Crow22-Jun-04 7:32
David Crow22-Jun-04 7:32 
Generalurgent help me Pin
pavanbabut22-Jun-04 5:57
pavanbabut22-Jun-04 5:57 
GeneralRe: urgent help me Pin
palbano22-Jun-04 6:00
palbano22-Jun-04 6:00 
GeneralRe: urgent help me Pin
pavanbabut22-Jun-04 6:28
pavanbabut22-Jun-04 6:28 
GeneralRe: urgent help me Pin
Maximilien22-Jun-04 6:50
Maximilien22-Jun-04 6:50 
GeneralRe: urgent help me Pin
Anonymous22-Jun-04 7:40
Anonymous22-Jun-04 7:40 
GeneralRe: urgent help me Pin
palbano22-Jun-04 6:56
palbano22-Jun-04 6:56 
Generalglobal variables Pin
dolph_loe22-Jun-04 5:20
dolph_loe22-Jun-04 5:20 
GeneralRe: global variables Pin
Johan Rosengren22-Jun-04 5:28
Johan Rosengren22-Jun-04 5:28 
GeneralRe: global variables Pin
dolph_loe22-Jun-04 6:42
dolph_loe22-Jun-04 6:42 
GeneralRe: global variables Pin
Johan Rosengren22-Jun-04 8:29
Johan Rosengren22-Jun-04 8:29 
GeneralRe: global variables Pin
jmkhael22-Jun-04 5:29
jmkhael22-Jun-04 5:29 
GeneralRe: global variables Pin
David Crow22-Jun-04 5:53
David Crow22-Jun-04 5:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.