Note: this question is about the Windows LZ functions, which are File Management Functions beginning with the prefix LZ: LZOpenFile, LZCopy, LZClose, etc. If Google isn't wrong, these are probably among the most poorly documented functions of the Windows API.
I'm trying to figure out what kind of files are actually suited for usage with the Windows LZ functions. The official documentation mentions "data that was compressed using Compress.exe", but the functions are also able to handle uncompressed files, in which case no decompression is applied.
Now, when I compress a file with the compress.exe utility from the resource kit (using either the -Z or -ZX switches), and then decompress it using the procedure described here, all I get is the source file unchanged, as if it were not compressed as expected. Even with a compressed file from the original Windows XP setup CD (those named with an underscore at the end in the i386 folder), I get the same result. Conclusion: no matter what file I try to decompress, I get it back unchanged.
The code I'm using is pretty straightforward, it basically reproduces the steps described in the MSDN article, so if I have a bug, I guess it must be somewhere else. But I'm still prone to thinking I'm just using the wrong input files. Does anyone have any experience with those LZ functions already? Here's my code in C++.
#include <iostream>
#include <Windows.h>
using namespace std;
int main(int argc, char ** argv) {
OFSTRUCT ofs1, ofs2;
INT hfSrc = -1, hfDest = -1;
if (argc <= 2) {
cerr << "Usage: LZTEST Source Destination";
return 1;
}
__try {
hfSrc = LZOpenFile(argv[1], &ofs1, OF_READ);
if (hfSrc < 0) {
cerr << "Error invoking LZOpenFile on source file: " << hfSrc;
return 1;
}
hfDest = LZOpenFile(argv[2], &ofs2, OF_CREATE);
if (hfDest < 0) {
cerr << "Error invoking LZOpenFile on destination file: " << hfDest;
return 1;
}
INT result = LZCopy(hfSrc, hfDest);
if (result < 0) {
cerr << "Error invoking LZCopy: " << result;
return 1;
}
} __finally {
if (hfSrc >= 0) LZClose(hfSrc);
if (hfDest >= 0) LZClose(hfDest);
}
cout << "Success";
return 0;
}
Try the compress.exe
here with no options.
Unless you need to uncompress some old files, use DotNetZip instead.