The following bit of code is only the memory mapping part, but I am unsure about the output area of the code. I know how to bring in an input file, but I am unsure if this code sends out an output file. Also, is there a reference site that I can be pointed to about how to write to the output file. I am stuck on trying to figure out how to get the information from the first file (the input) to the second file (the output). I am pretty sure the code below is incomplete, only on the reason of I don't know how to connect it, and I can't find the correct reading sources to help me out. Thank you in advance.
Code:
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
HANDLE OutFile;
HANDLE InFile;
HANDLE InFileMap;
HANDLE OutFileMap;
PVOID InPVFile;
PVOID OutPVFile;
DWORD InDWFileSize;
DWORD OutDWFileSize;
int i;
//Opening an input file.
char OutFilename[] = “c:\\exe1\\testin.dat”;
OutFile = CreateFile(InFilename,
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (InFile == INVALID_HANDLE_VALUE)
{
cout << “File could not be opened.”;
return(FALSE);
}
//Creating a file-mapping kernel object for input.
InFileMap = CreatFileMapping(InFile,
NULL,
PAGE_READONLY,
0,
0,
NULL);
if (InFileMap == NULL)
{
cout << “File map could not be opened.”;
ClosrHandle(InFile);
return(FALSE);
}
//Mapping a view of the input file.
InPVFile = MapViewOfFile(InFileMap,
FILE_MAP_READ,
0,
0,
0);
if (InPVFile == NULL)
{
cout << “Could not map view of file.”;
CloseHandle(InFileMap);
CloseHandle(InFile);
return(FALSE);
}
//Gathering the size of the input file.
InDWFileSize = GetFileSize(InFile, NULL);
//Creating an output file.
char OutFilename[] = “c:\\exe1\\testout.dat”;
OutFile = CreateFile(OutFilename,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_NEW,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (OutFile == INVALID_HANDLE_VALUE)
{
cout << “File could not be created.”;
return(FALSE);
}
//Creating a file-mapping kernel object for output.
OutFileMap = CreatFileMapping(OutFile,
NULL,
PAGE_WRITECOPY,
0,
0,
NULL);
if (OutFileMap == NULL)
{
cout << “File map could not be created.”;
ClosrHandle(OutFile);
return(FALSE);
}
//Mapping a view of the output file.
OutPVFile = MapViewOfFile(OutFileMap,
FILE_MAP_COPY,
0,
0,
0);
if (OutPVFile == NULL)
{
cout << “Could not map view of file.”;
CloseHandle(OutFileMap);
CloseHandle(OutFile);
return(FALSE);
}
//Switching the ASCII characters.
//???
//Housekeeping
UnmapViewOfFile(InPVFile);
UnmapViewOfFile(OutPVFile);
CloseHandle(InFileMap);
CloseHandle(OutFileMap);
CloseHandle(InFile);
CloseHandle(OutFile);
}
Comment