The following code example shows how to append one file to the end of another file. The example uses the CreateFile function to open two text (.txt) files: One.txt for reading and Two.txt for writing. Then, the example uses the ReadFile and WriteFile functions to append the contents of One.txt to the end of Two.txt by reading and writing 4-KB blocks.
void AppendExample (void)
{
HANDLE hFile, hAppend;
DWORD dwBytesRead, dwBytesWritten, dwPos;
char buff[4096];
TCHAR szMsg[1000];
// Open the existing file.
hFile = CreateFile (TEXT("\\ONE.TXT"), // Open One.txt
GENERIC_READ, // Open for reading
0, // Do not share
NULL, // No security
OPEN_EXISTING, // Existing file only
FILE_ATTRIBUTE_NORMAL, // Normal file
NULL); // No template file
if (hFile == INVALID_HANDLE_VALUE)
{
// Your error-handling code goes here.
wsprintf (szMsg, TEXT("Could not open ONE.TXT"));
return;
}
// Open the existing file, or, if the file does not exist,
// create a new file.
hAppend = CreateFile (TEXT("\\TWO.TXT"), // Open Two.txt.
Memory-Mapped FilesWindows CE supports both named and unnamed file-mapping objects. Unnamed files provide a method both for interprocess communication and as a way to allocate virtual memory regions larger than the 32-MB slot size limit.
In Windows CE, unnamed, or page file backed, memory-mapped files are not backed up by a page file nor do they have to be unnamed. The name of this type of memory-mapped file comes from Windows NT where an application could use the paging file of the OS to create a huge, sparse array of virtual pages. The memory-mapped file was unnamed because it was not backed up by a real file on the disk. In Windows CE, the created object can have a name and that name can be passed to other processes so they can access the same object.