-1

I have problems converting CString to const char *. I tried the methods from other forums and msdn way and it doesn't work:

CString value1("text1");
const char * value2= LPCTSTR(value1);

Any idea ?

Martin Ba
  • 37,187
  • 33
  • 183
  • 337
Clax
  • 207
  • 2
  • 9
  • 3
    possible duplicate of [Convert CString to const char\*](http://stackoverflow.com/questions/859304/convert-cstring-to-const-char) – zar Oct 03 '14 at 19:02

1 Answers1

-1

Get pointer of the internal character buffer of CString

const char * value2 = (const char *) value1.GetBuffer( value1.GetLength() );

Release the buffer when done.

value1.ReleaseBuffer()

The ReleaseBuffer() gives ownership of the buffer back to CString.

zar
  • 11,361
  • 14
  • 96
  • 178