Virtual Developer Workshop: Containerized Development with Docker

Environment: Win98, VC 5.0

This article describes classes to zip and unzip files.  The classes use the gzip GNU source code (gzip-1.2.4a).  This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License.  See the file COPYING included in the source code.

The target DLL exports two classes:

  • CZip (for zipping files)
  • CUnzip (for unzipping files)


A CZip or CUnzip object is built with a file name.  Then, the SwapSize() method must be called on that object (with one argument which is the target file name) in order to zip/unzip the file.  SwapSize() may throw a CZipException exception.  A message bound to the exception can be retrieved using the GetString() method.  Exceptions are thrown when:

  • the source file does not exists or cannot be opened for reading
  • the target file cannot be created (for example, this file already exists)
  • the gzip code is returns an error;  in this case, the message bound to the exception contains the message returned by the gzip source code via stderr

To use CZip or CUnzip, do the following:

  1. include czip.h in your project
  2. link your project with zipdll.dll using zipdll.lib
  3. move zipdll.dll to the same directory as your executable
    Note:  You can also dynamically link to zipdll.dll (I haven't tested that, though).

Here's an example of how to zip a file:

    CZip myFileToZip ("file_to_zip_name");
    myFileToZip.SwapSize ("file_zipped_name"); 
  catch (CZipException e) 
    cout << "problem while zipping : " << e.GetString() << endl;
    delete pExcep; 


  1. The CZipped files can be unzipped using WinZip if its name doesn't have a ".zip" extension.  If the zipped file has a ".zip" extension, WinZip won't be able to open the file.

  2. An archive constructed with WinZip can be extracted using a CUnzip object if it contains only a single file.

  3. In order to know the error messages written by gzip code on stderr, a temp file is built and attached to stderr.  If this temp file cannot be built (no way to write to the current directory for example), the error messages from gzip code (if any) will not be known, but the zip/unzip operations can still be achieved.

Date Updated: 2 March 1999



  • UNZIP to a buffer or memory

    Posted by Legacy on 10/10/2003 07:00am

    Originally posted by: Rajesh Sonti

    Using c or c++ program while uncopressing encountered zip file inside a zip file,how to read the contents of the inner zip file without extracting it to hard disk .

    I could read the metadata(File name,size,creation time etc.,) for the outer zip contents since it is on hard disk and absolute path for its contents are known.But the inner zip file does not have any absolute path to read metadata for its contents, moreover i do not want it to extract to temp folder to read the metadata instead i want it to explode in memory and read the metadata of its contents.How I can do that using c or c++.

    It is as good as uncompressing the inner zip file to a buffer.
    please provide me code or info regarding this..

    Rajesh Sonti

  • Compression Level?

    Posted by Legacy on 09/15/2003 07:00am

    Originally posted by: MindBlaster

    Just wondering about the compression level.
    Is it set to default or maximum?

    If it is changeable, then where?

    Thanks for a superb source! :)

    // MindBlaster

  • very good..!!

    Posted by Legacy on 03/27/2003 08:00am

    Originally posted by: Seo won

    thanks very much!!
    your class is very helpful to me..!!

    have a nice day~

  • How to zip a folder

    Posted by Legacy on 02/24/2003 08:00am

    Originally posted by: Silvere

    Any code to zip a complete folder. Is there a better solution instead of using CInfoZip class.

  • Need C++based code(.dll)

    Posted by Legacy on 10/09/2002 07:00am

    Originally posted by: rani

    Its is completly c based code ,Can u provide me c++ based code!

  • you can open the zipped file with winzip when it has a .gz extension

    Posted by Legacy on 05/20/2002 07:00am

    Originally posted by: icestar

    you can open the zipped file with winzip when it has a .gz extension,for it only be deflated,while not been archived!

  • How to zip directory

    Posted by Legacy on 12/09/2001 08:00am

    Originally posted by: Kurt


    Does anybody know how to zip files in directory in one zip file with CZip

  • What about a static library?

    Posted by Legacy on 10/16/2001 07:00am

    Originally posted by: Rimantas

    Hello, all,

    Is there a static library, or could anybody help making one?

    Thanks for help

  • How can I uncompress a memeroy data in "deflate" format? Who can help me?

    Posted by Legacy on 03/27/2001 08:00am

    Originally posted by: Bright

    I have got the compressed data block in deflate format,such as "0x2b,0x49,0x2d,0x2e,0x51,0xa8,0xca,0x2c,0x50,0x28,0x49,0xad,0x28,0x29,0x31,0x42,0x03,0x00". Who can help me uncompress it?

  • How to compressing memory with CZip?

    Posted by Legacy on 12/01/2000 08:00am

    Originally posted by: Long Nguyen

    I was download the Czip source, it good to compress a file, but i want to compress memory but i coundn't do? You can help me? Thanks!

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date