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

      BYTE* pcData = NULL;  
      DWORD dwBytesRead; 
      DWORD dwDataSize;  

      piComp->ReadFile( "c:\\temp\\source.txt", 0, 0, cfpCompress, TRUE, &dwBytesRead, &pcData,
                        &dwDataSize );  

      MessageBox( NULL, "File compressed successfully to memory", "Decompression result", MB_OK ); 

      CoTaskMemFree( pcData ); 
    }
    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();