Reads data from a file or a communications device.
BOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED *lpOverlapped);
hFile
A handle to the file or device (aCommunications device, for example) that is to be read.
This handle can be created by the CreateFile function. The handle must have been created with the GENERIC_READ access right.
lpBuffer
A pointer to the buffer that receives the data read from a file or device.
nNumberOfBytesToRead
The maximum number of bytes to be read.
lpNumberOfBytesRead
A pointer to a 32-bit variable that receives the number of bytes read by this function. This parameter can be NULL on Windows Server 2003 and later.
If lpOverlapped is NULL, this parameter must not be NULL.
lpOverlapped
A pointer to an OVERLAPPED structure.
If hFile was opened with the FILE_FLAG_OVERLAPPED flag, the OVERLAPPED structure specifies how and when the read operation is to be completed. If hFile was opened without the FILE_FLAG_OVERLAPPED flag, this parameter is ignored.
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError.
If lpOverlapped is not NULL and the read operation is pending, the return value is zero and GetLastError returns ERROR_IO_PENDING.
This function is a file system and device-specific function. For more information, see the documentation for the specific file system or device.
A named pipe server process can use the ReadFile function to read messages sent by a client process. The pipe must be created with the FILE_TYPE_PIPE flag.
When reading from a named pipe, the nNumberOfBytesToRead parameter specifies the maximum number of bytes to read. If the message is larger than this value, ReadFile returns false and GetLastError returns ERROR_MORE_DATA. If the message is smaller than this value, ReadFile returns true and reads the entire message.
If the pipe is in message-read mode, ReadFile reads one message at a time. If the pipe is in byte-stream mode, ReadFile reads up to nNumberOfBytesToRead bytes.
If the client process has closed the other end of the pipe, ReadFile returns false and GetLastError returns ERROR_BROKEN_PIPE.