Export (0) Print
Expand All
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Reading from a File

Windows CE 3.0

After you open or create a file by using the CreateFile function, use the returned file handle to gain access to the file. Windows 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 CE places the file pointer at the beginning of the file. Windows CE advances the file pointer after reading or writing each byte between the buffer and the file.

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

Use the ReadFile function to read data from a file. ReadFile uses the handle that is returned from the CreateFile function 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 it 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 reads up until the end of the file. 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 in 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 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.

Show:
© 2015 Microsoft