Xceed Zip Compression Library Documentation
Zip method example for VC++
Example topics > Zip method example for VC++

The following code uses the Zip method to compress the file "c:\test\my file.dat" into the zip file "c:\test\my test.zip". You should check the Zip method's return value once you are done – if it is xerSuccess (value 0) the operation was successful. Otherwise, look up the error code in the error codes topic to find out what went wrong.

VC++ Copy Code
#include "stdafx.h"
#include <stdio.h>
#import "xceedzip.dll" named_guids no_namespace
int main(int argc, char* argv[])
{
   CoInitialize( NULL ); 
   try
   {
      IXceedZipPtr piXceedZip( CLSID_XceedZip ); 
      piXceedZip->License( _bstr_t( L"your license key ) );
      long xErr;  
      piXceedZip->ZipFilename = "c:\\test\\my test.zip";
      piXceedZip->FilesToProcess = "c:\\test\\my file.dat"; 
      xErr = piXceedZip->Zip(); 
      if ( xErr == 0 ) // xerSuccess
      {
         printf( "Zip file created successfully" );
      }
      else
      {
         printf( "Error %08x occured while zipping\n", xErr );
      }
   }
   catch( const _com_error& xErr )
   {
      printf( "COM error %08x. %S\n", xErr.Error(), ( const char* )xErr.Description() );
   }
   catch( ... )
   {
      printf( "Unexpected error\n" );
   } 
   CoUninitialize();
   return 0;
}