Xceed Streaming Compression Library Documentation
Examples / Compressing from file to file (VC++ example)
In This Topic
    Compressing from file to file (VC++ example)
    In This Topic

    Here are two examples for compressing from file to file. One for compression, the other for decompression.

    VC++ - Compression Copy Code

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

    CoInitialize( NULL ); 

    try
    {
      IXceedStreamingCompressionPtr piComp; 
      piComp.CreateInstance( CLSID_XceedStreamingCompression ); 
      piComp->License( _bstr_t( L"your license key ) ); 

      IXceedBZip2CompressionFormatPtr piBZip2; 
      piBZip2.CreateInstance( CLSID_XceedBZip2CompressionFormat );  

      piComp->CompressionFormat = IXceedCompressDataPtr( piBZip2 );  

      DWORD dwBytesRead; 
      DWORD dwBytesWritten;  

      piComp->ProcessFile( "c:\\temp\\source.txt", 0, 0, cfpCompress,
                           TRUE, "c:\\temp\\compressed.cmp", FALSE, &dwBytesRead, &dwBytesWritten );  

      MessageBox( NULL, "File compressed successfully", "Compression result", MB_OK ); 
    }
    catch( const _com_error& xErr )
    {
      char szMsg[50]; 
      wsprintf( szMsg, "Error %08x\n", xErr.Error() ); 
      MessageBox( NULL, szMsg, "Error", MB_OK ); 
    }
    catch( ... )
    {
      MessageBox( NULL, "Unknown error", "Error", MB_OK ); 

    CoUninitialize();

    VC++ - Decompression Copy Code

    // This code uses the #import directive.
    // Put the following line at the beginning of your module

    #import "XCEEDSCO.DLL" no_namespace named_guids 

    CoInitialize( NULL ); 

    try
    {
      IXceedStreamingCompressionPtr piComp; 
      piComp.CreateInstance( CLSID_XceedStreamingCompression ); 
      piComp->License( _bstr_t( L"your license key ) ); 

      IXceedBZip2CompressionFormatPtr piBZip2; 
      piBZip2.CreateInstance( CLSID_XceedBZip2CompressionFormat );  

      piComp->CompressionFormat = IXceedCompressDataPtr( piBZip2 );  

      DWORD dwBytesRead; 
      DWORD dwBytesWritten;  

      piComp->ProcessFile( "c:\\temp\\compressed.cmp", 0, 0, cfpDecompress,
                           TRUE, "c:\\temp\\decompressed.txt", FALSE,
                           &dwBytesRead, &dwBytesWritten );  

      MessageBox( NULL, "File decompressed successfully", "Decompression result", MB_OK ); 
    }
    catch( const _com_error& xErr )
    {
      char szMsg[50]; 
      wsprintf( szMsg, "Error %08x\n", xErr.Error() ); 
      MessageBox( NULL, szMsg, "Error", MB_OK ); 
    }
    catch( ... )
    {
      MessageBox( NULL, "Unknown error", "Error", MB_OK ); 

    CoUninitialize();