CZip/CUnzip Classes for Zipping and Unzipping Files

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



  • A propos de Paon pourpre Ghd Lisseur

    Posted by umziab430 on 07/16/2013 04:18pm

    Lisseur céramique chaleur plus uniforme que les redresseurs métalliques et la distribution de chaleur permet un style orienté lisse. Redresseurs en céramique ne sont pas aussi sujettes à l'écaillage ou de fissuration comme redresseurs de métal et de verre. Pour profiter des avantages de votre lisseur en céramique pour une longue période, nettoyez les plaques en céramique. Une accumulation de laque et d'autres produits de coiffage peut aussi affecter votre style de cheveux. Nettoyage des plaques en céramique ne nécessitent que quelques produits et quelques minutes de votre time.So comment nettoyer un GHD Styler? [url=]ghd lisseur prix[/url] Étonnamment GHD (bonne journée de cheveux) avec pratiquement aucune publicité, atteint le statut d'icône en un temps incroyablement court, primé à gauche, à droite et au centre et toutes ces crédits va à un ex-coiffeur pour un salon haut Robert Powles, l'homme qui a pris cette possession.According prix pour le client GHD MK4 styler est considéré comme un bon investissement, il vaut bien le prix. Et les raisons sont assez fantastique et dans l'ensemble ils font le mieux. Une marque GHD mondial superbe est une société britannique, et c'est une entreprise Yorkshire qui croit dur labeur à l'avant-garde des soins capillaires mondiale. [url=]ghd pas cher lisseur[/url] GHD Styler Hair utilise des plaques en céramique chauffées à la fois les cheveux raides et boucle. Un bon entretien permettra d'assurer votre styler GHD dure aussi longtemps que possible. Nettoyage des résidus de produits coiffants de style devrait faire partie de l'entretien régulier. Il gardera le styler est à son meilleur. Vous pouvez facilement nettoyer votre styler GHD sans causer de défrisants damage.Ceramic sont préférés pour le salon et le style de la maison.

  • Jordan shoes mentioned Gene to buy the variety, a margin of Nike

    Posted by TaddyGaffic on 04/20/2013 03:50pm

    But in an e mail concerning the LSU activity from South Carolina on October 13, the faculty included the image but digitally erased the cross. The picture was in any other case untouched. A minimum of 15 folks have already been injured as Polish and Russian football enthusiasts clashed in Warsaw forward of your teams' 1-1 attract.. Once I have said, the soccer cleats by [url=]nike free run[/url] Adidas have the similar characteristics, therefore in order to know all of them, then expect to have a lengthy list. Obviously, those are the same in ways that Adidas is the one brand that they carry. The lightness of the weight of the materials used in making the Adidas soccer cleats is definitely the main reason why the soccer cleats the manufacture and they are sold in the market are lightweight too. Pokhara is our base for this aerial playground. The [url=]nike free uk[/url] choppy green hills all around offer a lifetime's worth of glorious flying possibilities, many of them still virgin. I Alpine (forward) launch, leaning forward, pulling my lines taut, with my glider laid out in an arc behind me. That is, you want something whose design is similar to that of a ski boot. That means that the inside removable liner, is a moldable type. ( it forms to the contours of your foot, providing maximum comfort and support.) You want the boot itself, made of a stiff plastic, or waterproof outer shell, again for support and insulation. Self defense purposes purposes dealing with #3 * Having the ability to contemplate [url=]nike free run[/url] gets and in addition leg techinques will not likely typically injure. I propose you will get out there applying reside training goods and rehearse fighting and also staying get to that has a close friend and even martial arts university undergraduate. Physical exercise diffusing strikes, using images, supplying photos, and in addition keeping crystal clear focused although becoming bombarded with plenty hits in addition to tennis shoes

  • UNZIP to a buffer or memory

    Posted by Legacy on 10/10/2003 12: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 12: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 12: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 12: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 12: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 12: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 12: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 12:00am

    Originally posted by: Rimantas

    Hello, all,

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

    Thanks for help

  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Entire organizations suffer when their networks can't keep up and new opportunities are put on hold. Waiting on service providers isn't good business. In these examples, learn how to simplify network management so that your organization can better manage costs, adapt quickly to business demands, and seize market opportunities when they arise.

Most Popular Programming Stories

More for Developers

RSS Feeds

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