Windows file: using both ReadFile and mapping
c++, file, memory, windows
Solution
No. MapViewOfFile() requires you telling it where the view is mapped relative from the start of the file. Specified in the dwFileOffset arguments. If you need it to work this way then simply use SetFilePointerEx() with a zero move to obtain the current position.
Problem
Suppose I have a file on disk and then create its handle using `CreateFile`, its mapping object using `CreateFileMapping`, its mapping view using `MapViewOfFile`. The start of the file address in virtual memory is held in pointer `StartPtr` which was returned by `MapViewOfFile` function. If, before calling `CreateFileMapping` function, I use `ReadFile` to read some bytes `N`, would be the pointer returned by `MapViewOfFile` point to (`StartPtr` + `N`) ?