#include <lzexpand.h> |
HFILE LZOpenFile(lpszFile, lpof, style) | |||||
LPCSTR lpszFile; | /* address of filename, */ | ||||
OFSTRUCT FAR* lpof; | /* address of structure for file info | */ | |||
UINT style; | /* action to be taken, */ |
The LZOpenFile function creates, opens, reopens, or deletes the file specified by the string to which lpszFile points.
lpszFile
Points to a string that specifies the name of a file.
lpof
Points to the OFSTRUCT structure that is to receive information about the file when the file is opened. The structure can be used in subsequent calls to LZOpenFile to refer to the open file.
The szPathName member of this structure contains characters from the OEM character set. For more information about the OEM character set, see the Microsoft Windows Guide to Programming.
style
Specifies the action to be taken. These styles can be combined by using the bitwise OR operator:
Value | Meaning |
OF_CANCEL | Adds a Cancel button to the OF_PROMPT dialog box. Choosing the Cancel button directs LZOpenFile to return a file-not-found error message. |
OF_CREATE | Directs LZOpenFile to create a new file. If the file already exists, it is truncated to zero length. |
OF_DELETE | Deletes the file. |
OF_EXIST | Opens the file, and then closes it. This action is used to test for file existence. |
OF_PARSE | Fills the OFSTRUCT structure, but carries out no other action. |
OF_PROMPT | Displays a dialog box if the requested file does not exist. The dialog box informs the user that Windows cannot find the file and prompts the user to insert the disk containing the file in drive A. |
OF_READ | Opens the file for reading only. |
OF_READWRITE | Opens the file for reading and writing. |
OF_REOPEN | Opens the file using information in the reopen buffer. |
OF_SHARE_DENY_NONE | Opens the file without denying other programs read access or write access to the file. LZOpenFile fails if the file has been opened in compatibility mode by any other program. |
OF_SHARE_DENY_READ | Opens the file and denies other programs read access to the file. LZOpenFile fails if the file has been opened in compatibility mode or for read access by any other program. |
OF_SHARE_DENY_WRITE | Opens the file and denies other programs write access to the file. LZOpenFile fails if the file has been opened in compatibility mode or for write access by any other program. |
OF_SHARE_EXCLUSIVE | Opens the file in exclusive mode, denying other programs both read access and write access to the file. LZOpenFile fails if the file has been opened in any other mode for read access or write access, even by the current program. |
OF_WRITE | Opens the file for writing only. |
The return value is a handle identifying the file if the function is successful and the value specified by style is not OF_READ. If the file is compressed and opened with style set to the OF_READ value, the return value is a special file handle. If the function fails, the return value is –1.
If style is OF_READ (or OF_READ and any of the OF_SHARE_ flags) and the file is compressed, LZOpenFile calls the LZInit function, which performs the required initialization for the decompression operations.
The following example uses LZOpenFile to open a source file and create a destination file into which the source file can be copied:
char szSrc[] = {"readme.txt"};
char szDst[] = {"readme.bak"};
OFSTRUCT ofStrSrc;
OFSTRUCT ofStrDest;
HFILE hfSrcFile, hfDstFile;
/* Open the source file. */
hfSrcFile = LZOpenFile(szSrc, &ofStrSrc, OF_READ);
/* Create the destination file. */
hfDstFile = LZOpenFile(szDst, &ofStrDest, OF_CREATE);
/* Copy the source file to the destination file. */
LZCopy(hfSrcFile, hfDstFile);
/* Close the files. */
LZClose(hfSrcFile);
LZClose(hfDstFile);