I have already introduced XZip in a previous article. This article presents XZip and also XUnzip, which together allow you to add zip and unzip to your application without using any .lib or .dll.
First, let me acknowledge the work of Lucian Wischik, who took the many .c and .h files from Info-ZIP and produced the .cpp and .h files that XZip is based on.
XZip and XUnzip Features
Most of the functions are demonstrated in the XZip demo app. Here are the main ones:
- CreateZip() - Create a zip archive file.
- ZipAdd() - Add a file to a zip archive.
- OpenZip() - Open an existing zip archive file.
- GetZipItem() - Get information about an item in an open zip archive.
- FindZipItem() - Find item by name and return information about it.
- UnzipItem() - Find item by index and unzip it.
- CloseZip() - Close an open zip archive.
How To Use
To integrate XZip into your app, you first need to add following the files to your project:
If you include XZip in a project that uses precompiled headers, you must change C/C++ Precompiled Headers settings to Not using precompiled headers for XZip.cpp and XUnzip.cpp.
Next, include the header files XZip.h and XUnzip.h in appropriate project files. Now you are ready to start using XZip. There are many notes concerning usage of various functions in XZip.h and XUnzip.h. Please read all function headers for each function you wish to use.
have been tested only with files.
The XZipTest.exe demo tests the APIs in XZip and XUnzip. Here is some of the output:
Frequently Asked Questions
- Can I use XZip in non-MFC apps?
Yes. It has been implemented to compile with any Win32 program.
- When I try to include XZip.cpp in my MFC project, I get the compiler error
XZip.cpp(2918) : fatal error C1010: unexpected end of file while looking for precompiled header directive. How can I fix this?
When using XZip in project that uses precompiled headers, you must change C/C++ Precompiled Headers settings to Not using precompiled headers for XZip.cpp and XUnzip.cpp. Be sure to do this for All Configurations.
- When I try to build the demo app, I get the linker error
LINK : fatal error LNK1104: cannot open file "mfc42u.lib" Error executing link.exe. How can I fix this?
The default installation options of Visual C++ v6.0 don't install the Unicode libraries of MFC, so you might get an error that mfc42u.lib or mfc42ud.lib cannot be found. You can fix this either by installing the Unicode libs from the VC++ install CD, or by going to Build | Set Active Configuration and selecting one of the non-Unicode configurations.
You can configure the Visual Studio toolbars to include the Select Active Configuration combobox. This allows you to see at a glance what configuration you are working with.
- I don't need the Zip/Unzip functions. Can I exclude XZip.cpp/XUnzip.cpp?
Yes. You only need to include the .h/.cpp pair that you need.
- Can we use XZip in our (shareware/commercial) app?
Yes, you can use XZip without charge or license fee, providing you follow the Info-ZIP restrictions as defined in XZip.cpp.
- Does XZip handle pipes? in-memory zipping?
XZip has not been tested with anything other than files.
- Can I use XZip in a VS2005 project?
Yes. There is a sample VS2005 project included in the download.
- Does XZip work on Vista?
Version 1.3 - 2007 July 18
- Fixed problem with file size that is multiple of 16384, reported by Mathias Svensson.
- Fixed XZip to save file time in local time, suggested by Damir Valiulin.
Version 1.2 - 2007 June 30
- Added project for VS2005.
AddFolderContent() contributed by Renaud Deysine.
- Fixed problem with
TUnzip::Open() reported by Pete Howells.
Open() now returns correct success code.
- Fixed several bugs reported by Warren Stevens.
- Fixed a problem in
unzReadCurrentFile() reported by Kochise.
- Fixed bug in
EnsureDirectory() reported by craigmj.
ideflate() suggested by Michael B. Hansen.
- Fixed problem with
time_t reported by Ronney.
- Fixed problems found by Boundschecker as reported by Warren Stevens.
- Made changes to
PUTBYTE macros and to
TZip::write(), suggested by vielheit.
Version 1.1 - 2003 May 7
This software is released into the public domain. You are free to use it in any way you like, except that you may not sell this source code. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.