The OpenFile function creates, opens, reopens, or deletes a file.
This function is provided for compatibility with 16-bit versions of Windows. In particular, the OpenFile function cannot open a named pipe. Win32-based applications should use the CreateFile function.
HFILE OpenFile(
LPCSTR lpFileName, |
// pointer to filename |
LPOFSTRUCT lpReOpenBuff, |
// pointer to buffer for file information |
UINT uStyle |
// action and attributes |
); |
The OFSTRUCT structure contains a pathname string member whose length
is limited to OFS_MAXPATHNAME characters. OFS_MAXPATHNAME is currently defined
to be 128. Because of this, you cannot use the OpenFile function to
open a file whose path length exceeds 128 characters. The CreateFile
function does not have such a path length limitation.
Value |
Meaning |
OF_CANCEL |
Ignored. In the Win32 application programming interface (API), the OF_PROMPT style produces a dialog box containing a Cancel button. |
OF_CREATE |
Creates 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. Used to test for a file’s 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 it contains Retry and Cancel buttons. Choosing the Cancel button directs OpenFile to return a file-not-found error message. |
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_COMPAT |
For MS-DOS-based file systems using the Win32 API, opens the file with compatibility mode, allowing any process on a specified computer to open the file any number of times. Other efforts to open with any other sharing mode fail. Windows NT: This flag is mapped to the CreateFile function's FILE_SHARE_READ | FILE_SHARE_WRITE flags. |
OF_SHARE_DENY_NONE |
Opens the file without denying read or write access to other processes. On MS-DOS-based file systems using the Win32 API, if the file has been opened in compatibility mode by any other process, the function fails. Windows NT: This flag is mapped to the CreateFile function's FILE_SHARE_READ | FILE_SHARE_WRITE flags. |
OF_SHARE_DENY_READ |
Opens the file and denies read access to other processes. On MS-DOS-based file systems using the Win32 API, if the file has been opened in compatibility mode or for read access by any other process, the function fails. Windows NT: This flag is mapped to the CreateFile function's FILE_SHARE_WRITE flag. |
OF_SHARE_DENY_WRITE |
Opens the file and denies write access to other processes. On MS-DOS-based file systems using the Win32 API, if the file has been opened in compatibility mode or for write access by any other process, the function fails. Windows NT: This flag is mapped to the CreateFile function's FILE_SHARE_READ flag. |
OF_SHARE_EXCLUSIVE |
Opens the file with exclusive mode, denying both read and write access to other processes. If the file has been opened in any other mode for read or write access, even by the current process, the function fails. |
OF_VERIFY |
Verifies that the date and time of the file are the same as when it was previously opened. This is useful as an extra check for read-only files. |
OF_WRITE |
Opens the file for writing only. |
If the function succeeds, the return value specifies a file handle.
If the function fails, the return value is HFILE_ERROR. To get extended error information, call GetLastError.
If the lpFileName parameter specifies a filename and extension only, this function searches for a matching file in the following directories, in the order shown:
Windows NT: The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is SYSTEM32.
The lpFileName parameter cannot contain wildcard characters.
The Win32 OpenFile function does not support the OF_SEARCH flag supported by the 16-bit Windows OpenFile function. The OF_SEARCH flag directs Windows to search for a matching file even when the filename includes a full path. To search for a file in a Win32-based application, use the SearchPath function.
To close the file after use, call the _lclose function.
CreateFile, GetSystemDirectory, GetWindowsDirectory, _lclose, OFSTRUCT, SearchPath
See also:
Comments:
file: /Techref/os/win/api/win32/func/src/f66.htm, 11KB, , updated: 2008/4/1 15:25, local time: 2024/11/9 07:43,
3.140.186.218:LOG IN ©2024 PLEASE DON'T RIP! THIS SITE CLOSES OCT 28, 2024 SO LONG AND THANKS FOR ALL THE FISH!
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://linistepper.com/Techref/os/win/api/win32/func/src/f66.htm"> OpenFile</A> |
Did you find what you needed? |