ReadFile

ReadFile reads data from a file, starting at the position indicated by the file pointer. After the read operation has been completed, the file pointer is adjusted by the number of bytes actually read.

Syntax

BOOL ReadFile(
    HANDLE hFile,
    LPVOID lpBuffer,
    DWORD nNumberOfBytesToRead,
    LPDWORD lpNumberOfBytesRead,
    LPOVERLAPPED lpOverlapped
);

Parameters

hFile

The file to be read. The file handle must have been created with GENERIC_READ access to the file.

lpBuffer

A pointer to the buffer that receives the data read from the file.

nNumberOfBytesToRead

The number of bytes to be read from the file.

lpNumberOfBytesRead

A pointer to the number of bytes read. ReadFile sets this value to zero before doing any work or error checking.

lpOverlapped (not supported)

This parameter must be set to NULL.

Return Value

TRUE if the function succeeds, FALSE if the function fails

NOTE: If the return value is TRUE and the number of bytes read is zero, the file pointer was beyond the current end of the file at the time of the read operation.

To get extended error information, call GetLastError.

Remarks

ReadFile returns when the number of bytes requested has been read, or an error occurs.

If part of the file is locked by another process and the read operation overlaps the locked portion, this function fails.

Applications must not read from nor write to the input buffer that a read operation is using until the read operation completes. A premature access to the input buffer may lead to corruption of the data read into that buffer.

When a synchronous read operation reaches the end of a file, ReadFile returns TRUE and sets *lpNumberOfBytesRead to zero.

Requirements

Minimum Supported Version RTX64 2013
Header windows.h
Library Rtx_Rtss.lib

See Also:

CreateFile

WriteFile