Use the WriteFile function to place data into a file. Like ReadFile, WriteFile uses the handle that is returned from CreateFile in the hFile parameter to identify which file to write to. 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 within the file that is pointed to by the file pointer. Like ReadFile, WriteFile does not perform any formatting on the data; WriteFile writes the data exactly as the data exists in the buffer.
Note Windows CE does not support simultaneous read/write operations. Further, WriteFile does not support asynchronous write operations.
When writing to a file, use the FlushFileBuffers function to be sure that all data is properly written from the data buffer to the file. This situation is common when writing to a file on an installed file system, such as the FAT file system.
If you want to truncate the file when you close it, call the SetEndOfFile function. SetEndOfFile truncates the file at the current location of the pointer, and then it closes the file.