Partager via


Writing to a File (Windows Embedded CE 6.0)

1/6/2010

Use the WriteFile function to place data into a file. Like the ReadFile function, WriteFile uses the handle that is returned from the CreateFile function in the hFile parameter to identify the file to which to write. WriteFile then copies a specified number of bytes from the buffer that is pointed to by the lpBuffer parameter into the specified file. CreateFile begins placing the buffered data at the location in the file that is pointed to by the file pointer. Like ReadFile, WriteFile does not perform any formatting on the data, but writes the data exactly as the it exists in the buffer.

WriteFile 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.

When writing to a file, use the FlushFileBuffers function to ensure that all data is written properly from the data buffer to the file. This situation is common when writing to a file on an installed file system, such as the file allocation table (FAT) file system.

To truncate the file, call the SetEndOfFile function. SetEndOfFile truncates the file at the current location of the pointer, and then closes the file.

See Also

Concepts

File System Operations

Other Resources

Reading from and Writing to a File