I'm writing windows program with C and Visual Studio. I have to map a file than access it from it's 750th byte. I tried
pFile = (char *) MapViewOfFile(hMMap,FILE_MAP_ALL_ACCESS,0,(DWORD) 750,0)
open file with this but it returns error 1132.
ERROR_MAPPED_ALIGNMENT 1132 (0x46C) The base address or the file offset specified does not have the proper alignment.
How can resolve this?
The documentation of MapViewOfFile is pretty clear that the offset has to be a multiple of the allocation granularity (which is normally 64KB I believe, but call GetSystemInfo
to get true actual value as the documentation states).
So since 750 is smaller than the allocation granularity you'll have to map the file from 0. If you really need your pointer to the 750th byte, then just increment the pointer
pFile = (char *) MapViewOfFile(hMMap,FILE_MAP_ALL_ACCESS,0,(DWORD) 0,0);
char* pBuffer = pFile + 750;
You'll need a second buffer because you will have to pass pFile to UnmapViewOfFile