Win32 API Reference

ReadFileEx

The ReadFileEx function reads data from a file or from the communications resource that is associated with a particular asynchronous I/O handle.

BOOL ReadFileEx(
  HANDLE hFile,
  LPVOID lpBuffer,
  DWORD nNumberOfBytesToRead,
  LPOVERLAPPED lpOverlapped,
  LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);

Parameters

Parameter Description
hFile

A handle to the file or communications resource to be read.

The handle must have been created with the GENERIC_READ access flag.

lpBuffer

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

nNumberOfBytesToRead

The maximum number of bytes to be read.

lpOverlapped

A pointer to an OVERLAPPED structure.

This structure must contain a handle to an event object that is set when the read operation is complete.

lpCompletionRoutine

A pointer to the completion routine to be called when the read operation is completed.

This parameter can be NULL.

Return Value

If the function succeeds, the return value is TRUE.

If the function fails, the return value is FALSE. To get extended error information, call GetLastError.

If lpCompletionRoutine is not NULL, the return value is TRUE if the operation is successfully queued for execution. The actual success or failure of the operation is reported to the completion routine.

Remarks

The ReadFileEx function is similar to the ReadFile function, but it supports asynchronous operations. When the read operation is completed, the system calls the function pointed to by lpCompletionRoutine.

Note

The system requires that the buffer passed to ReadFileEx remain valid until the completion routine is called.

Important

If the handle hFile is a handle to a console screen buffer, the function is not supported and returns FALSE.

Requirements

Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Header windows.h
Library Kernel32.lib
DLL Kernel32.dll

See Also