_lread

2.x

  UINT _lread(hf, hpvBuffer, cbBuffer)    
  HFILE hf; /* file handle */
  void _huge* hpvBuffer; /* address of buffer for read data */
  UINT cbBuffer; /* length of data buffer */

The _lread function reads data from the specified file.

Parameters

hf

Identifies the file to be read.

hpvBuffer

Points to a buffer that is to receive the data read from the file.

cbBuffer

Specifies the number of bytes to be read from the file. This value cannot be greater than 0xFFFE (65,534).

Return Value

The return value indicates the number of bytes that the function read from the file, if the function is successful. If the number of bytes read is less than the number specified in cbBuffer, the function reached the end of the file (EOF) before reading the specified number of bytes. The return value is HFILE_ERROR if the function fails.

Example

The following example uses the _lread and _lwrite functions to copy data from one file to another:

HFILE hfReadFile;
int cbRead;
PBYTE pbBuf;

/* Allocate a buffer for file I/O. */

pbBuf = (PBYTE) LocalAlloc(LMEM_FIXED, 2048);

/* Copy the input file to the temporary file. */

do {
    cbRead = _lread(hfReadFile, pbBuf, 2048);
    _lwrite(hfTempFile, pbBuf, cbRead);
} while (cbRead != 0);

/* Free the buffer and close the files. */

LocalFree((HLOCAL) pbBuf);

_lclose(hfReadFile);
_lclose(hfTempFile);

See Also

_hread, _lwrite