I looked at boost's mapped_file, and CreateFileMapping/MapViewOfFile, but they seem overly complicated to use.
Anything simpler I can use to overwrite a few bytes here and there in an existing file? Performance is not a very high consideration.
I looked at boost's mapped_file, and CreateFileMapping/MapViewOfFile, but they seem overly complicated to use.
Anything simpler I can use to overwrite a few bytes here and there in an existing file? Performance is not a very high consideration.
Something like this (untested, and you should also check the HRESULTS error codes):
CAtlFile f;
f.Create( L"MyFile.txt", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, OPEN_ALWAYS );
CAtlFileMapping<BYTE> map;
map.MapFile( f , 0, 0, PAGE_READWRITE, FILE_MAP_ALL_ACCESS );
printf( "%d bytes\n", (int)map.GetMappingSize() );
// Overwrite the 3-rd byte with 21
map[2] = 21;