Xceed Binary Encoding Library Documentation
Examples / Encoding from memory to file (VC++ example)
In This Topic
    Encoding from memory to file (VC++ example)
    In This Topic

    This sample encodes data (using Base64) from memory to a file

    VC++ Copy Code

    // This code uses the #import directive.
    // Put the following line at the beginning of your module
    #import "XCEEDBEN.DLL" no_namespace named_guids 

    CoInitialize( NULL ); 

    try
    {
      IXceedBinaryEncodingPtr piBinEncoder; 

      piBinEncoder.CreateInstance( CLSID_XceedBinaryEncoding ); 
      piBinEncoder->License( _bstr_t( L"your license key ) ); 

      IXceedBase64EncodingFormatPtr piBase64Encode; 

      piBase64Encode.CreateInstance( CLSID_XceedBase64EncodingFormat );  

      piBinEncoder->EncodingFormat = IXceedEncodeDataPtr( piBase64Encode );  

      char* pcSource = "This is the data that we will encode"; 
      DWORD dwBytesWritten;  

      piBinEncoder->WriteFile( ( BYTE* )pcSource, lstrlen( pcSource ), bfpEncode, 
                                TRUE, "c:\\temp\\destination.b64", FALSE, &dwBytesWritten );  

      MessageBox( NULL, "Encoding successful!", "Encoding result", MB_OK ); 
    }
    catch( const _com_error& xErr )
    {
      char szMsg[250]; 
      wsprintf( szMsg, "Error 08x\ns", xErr.Error(),(char*)xErr.Description() ); 
      MessageBox( NULL, szMsg, "Error", MB_OK ); 
    }
    catch( ... )
    {
      MessageBox( NULL, "Unknown error", "Error", MB_OK ); 

    CoUninitialize();