请问怎么把CString转换成BYTE?

解决方案 »

  1.   

    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
      

  2.   

    CString str="ok,go";
    BYTE bt[100];
    memset(bt,0,sizeof(bt));
    memcpy(bt,str,str.GetLength());