Share via


Reading from a File (Windows Embedded CE 6.0)

1/6/2010

After you open or create a file by using the CreateFile function, use the returned file handle to gain access to the file. Windows Embedded CE maintains a file pointer to read and write data between a file and a buffer. When you open a file for the first time, Windows Embedded CE places the file pointer at the beginning of the file. Windows Embedded CE advances the file pointer after reading or writing each byte between the buffer and the file.

Use the ReadFile function to read data from a file. ReadFile uses the handle that is returned by CreateFile in the hFile parameter to identify the file from which to read. ReadFile begins reading at the location that is pointed to by the file pointer and continues reading up to the number of bytes that is specified in the nNumberOfBytesToRead parameter or to the end of the file. If ReadFile finds the end of the file, it does not return an error value. Instead, ReadFile returns as much data as it has read. Therefore, check the value that is returned in lpNumberOfBytesRead against the value that is passed to the function in nNumberOfBytesToRead. ReadFile returns the read data through the buffer that is pointed to by the lpBuffer parameter. During the copying process, ReadFile does not perform any formatting or parsing; ReadFile reads the data exactly as the data exists in the file.

ReadFile does not support asynchronous write operations.

Note

Accessing the data buffer while Windows Embedded CE is performing a read or write operation on that buffer might lead to data corruption. Therefore, ensure that you do not modify a data buffer that is currently being read or written to. If you use multiple threads or semaphores, ensure that one thread does not access the data buffer while another thread performs a read or write operation.

See Also

Concepts

File System Operations

Other Resources

Reading from and Writing to a File