Xceed Streaming Compression Library Documentation
Examples / Compressing from memory to file (VC++ example)
In This Topic
    Compressing from memory to file (VC++ example)
    In This Topic
    VC++ 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 );  

      char* pcData = "This is the data to compress compress";  

      DWORD dwBytesWritten;  

      piComp->WriteFile( ( BYTE* )pcData, strlen(pcData) , cfpCompress, 
                         TRUE, "c:\\temp\\compressed.cmp", FALSE, &dwBytesWritten );  

      MessageBox( NULL, "Memory compressed successfully to file", "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();