_lopen

2.x

  HFILE _lopen(lpszFilename, fnOpenMode)    
  LPCSTR lpszFilename; /* address of file to open */
  int fnOpenMode; /* file access, */  

The _lopen function opens an existing file and sets the file pointer to the beginning of the file.

Parameters

lpszFilename

Points to a null-terminated string that names the file to be opened. The string must consist of characters from the Windows character set.

fnOpenMode

Specifies the modes in which to open the file. This parameter consists of one access mode and an optional share mode.

Value Access mode

READ Opens the file for reading only.
READ_WRITE Opens the file for reading and writing.
WRITE Opens the file for writing only.

Value Share mode (optional)

OF_SHARE_COMPAT Opens the file in compatibility mode, allowing any process on a given machine to open the file any number of times. If the file has been opened by using any of the other sharing modes, _lopen fails.
OF_SHARE_DENY_NONE Opens the file without denying other programs read or write access to the file. If the file has been opened in compatibility mode by any other program, _lopen fails.
OF_SHARE_DENY_READ Opens the file and denies other programs read access to the file. If the file has been opened in compatibility mode or for read access by any other program, _lopen fails.
OF_SHARE_DENY_WRITE Opens the file and denies other programs write access to the file. If the file has been opened in compatibility mode or for write access by any other program, _lopen fails.
OF_SHARE_EXCLUSIVE Opens the file in exclusive mode, denying other programs both read and write access to the file. If the file has been opened in any other mode for read or write access, even by the current program, _lopen fails.

Return Value

The return value is a file handle if the function is successful. Otherwise, it is HFILE_ERROR.

Example

The following example uses the _lopen function to open an input file:

HFILE hfReadFile;
/* Open the input file (read only). */

hfReadFile = _lopen("testfile", READ);

if (hfReadFile == HFILE_ERROR) {
    ErrorHandler();
}

See Also

OpenFile