how to convert from CString to LPSTR
-
LPSTR pszText; CString sbuffer; pszText = sbuffer; how can I make the last line work? how to cast?
You can use the CString::LPCTSTR operator as follows LPSTR pszText; CString sbuffer; //No copy takes place only pointer is returned pszText = (LPCTSTR)sbuffer; //This returns a pointer to a Null terminated 'C' String :( :( But beware if you change the CString there will be a reallocation of existing memory which will invalidate pszText ----------------- Atul #ifndef C #define C damn_powerful #endif
-
LPSTR pszText; CString sbuffer; pszText = sbuffer; how can I make the last line work? how to cast?
You can use the CString::LPCTSTR operator as follows LPSTR pszText; CString sbuffer; //No copy takes place only pointer is returned pszText = (LPCTSTR)sbuffer; //This returns a pointer to a Null terminated 'C' String :( :( But beware if you change the CString there will be a reallocation of existing memory which will invalidate pszText ----------------- Atul #ifndef C #define C damn_powerful #endif
-
LPSTR pszText; CString sbuffer; pszText = sbuffer; how can I make the last line work? how to cast?
pszText = sbuffer.GetBuffer(); Now the pszText 'owns' the CString until you call ReleaseBuffer();. By the way, if you're doing this to turn a CString into a pszText for a function, the CString should cast to a char array by itself. Christian #include "std_disclaimer.h"