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

Copy
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

Ignored.

Return Value

If the function succeeds, it returns TRUE. If the function fails, it returns FALSE.

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.

Applications must not read from nor write to the input buffer that a read operation is using until the read operation completes. 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 Header Library

eRTOS 1.0 SDK

windows.h rtkrnl.lib

See Also: