Use the method 'GetBuffer' but be careful with UNICODE where one char is 2 bytes and not 1From MSDN: // example for CString::GetBuffer CString s( "abcd" ); #ifdef _DEBUG afxDump << "CString s " << s << "\n"; #endif LPTSTR p = s.GetBuffer( 10 ); lstrcpy( p, _T("Hello") ); // directly access CString buffer s.ReleaseBuffer( ); #ifdef _DEBUG afxDump << "CString s " << s << "\n"; #endif
bytes and not 1From MSDN:
// example for CString::GetBuffer
CString s( "abcd" );
#ifdef _DEBUG
afxDump << "CString s " << s << "\n";
#endif
LPTSTR p = s.GetBuffer( 10 );
lstrcpy( p, _T("Hello") ); // directly access CString buffer
s.ReleaseBuffer( );
#ifdef _DEBUG
afxDump << "CString s " << s << "\n";
#endif
BYTE bt[100];
memset(bt,0,sizeof(bt));
memcpy(bt,str,str.GetLength());