I have a problem understanding how to use the API function CreateFileMapping(...).
I’ve been trying to map a small file and then reverse it’s content. It has only about 1 Kb, but I keep getting the “Not enough memory” error.
I have opened the file by calling CreateFile and got it’s size with GetFileSize.
Then I call:
CreateFileMapping(fileHandle,
NULL,
PAGE_READWRITE | SEC_RESERVE,
fileSize + 1,
fileSize + 1,
NULL);
I suspect that the problem is with passing the fileSize + 1 as dwFileOffsetHighand dwFileOffsetLow, but I have a hard time understanding what should I pass to it instead.
Any hints are greatly appreciated!
dwFileOffsetHighanddwFileOffsetLoware two 32 bit values that are combined to form a single 64 bit value. This function was implemented this way because it pre-dates widespread compiler support for 64 bit values.I think your misunderstanding is in believing that the high and low mean upper and lower limits.
In your case your value (assuming
fileSizeis around 1KB) is nowhere near requiring 64 bits so you should passfileSize+1fordwFileOffsetLowand0fordwFileOffsetHigh.However, if you are attempting to map the entire file you can simply pass
0for both parameters.From the documentation: