#include <lzexpand.h> |
HFILE LZInit(hfSrc) | |||||
HFILE hfSrc; | /* handle of source file | */ |
The LZInit function allocates memory for, creates, and initializes the internal data structures that are required to decompress files.
hfSrc
Identifies the source file.
The return value is the original file handle if the function is successful and the file is not compressed. If the function is successful and the file is compressed, the return value is a new file handle. If the function fails, the return value is an error value that is less than zero and may be one of the following:
Value | Meaning |
LZERROR_BADINHANDLE | The handle identifying the source file is invalid. |
LZERROR_GLOBALLOC | There is insufficient memory for the required internal data structures. This value is returned when an application attempts to open more than 16 files. |
LZERROR_GLOBLOCK | The handle identifying global memory is invalid. (The internal call to the GlobalLock function failed.) |
LZERROR_READ | The source file format is invalid. |
LZERROR_UNKNOWNALG | The file was compressed with an unrecognized compression algorithm. |
A maximum of 16 compressed files can be open at any given time.
The following example uses LZInit to initialize the internal structures that are required to decompress a file:
char szSrc[] = {"readme.cmp"};
char szFileName[128];
OFSTRUCT ofStrSrc;
OFSTRUCT ofStrDest;
HFILE hfSrcFile, hfDstFile, hfCompFile;
int cbRead;
BYTE abBuf[512];
/* Open the compressed source file. */
hfSrcFile = OpenFile(szSrc, &ofStrSrc, OF_READ);
/*
* Initialize internal data structures for the decompression
* operation.
*/
hfCompFile = LZInit(hfSrcFile);
/* Retrieve the original name for the compressed file. */
GetExpandedName(szSrc, szFileName);
/* Create the destination file using the original name. */
hfDstFile = LZOpenFile(szFileName, &ofStrDest, OF_CREATE);
/* Copy the compressed source file to the destination file. */
do {
if ((cbRead = LZRead(hfCompFile, abBuf, sizeof(abBuf))) > 0)
_lwrite(hfDstFile, abBuf, cbRead);
else {
.
. /* handle error condition */
.
}
} while (cbRead == sizeof(abBuf));
/* Close the files. */
LZClose(hfSrcFile);
LZClose(hfDstFile);