Either something fail so lpBaseAddr is NULL or you do something bad in Checksummapfile. Single-step your code in the debugger and check the result from every single line.
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
Access violation will typically mean that you are trying to access a relative offset in the filemapping that exceeds the mapped file.
As in you have a file of 10 bytes, and you are trying to read/write the byte at lpBaseAddr+10
Access violation is pointer error. The code snippet you posted doesn't make any check on nFileSize, hFile, hMap, lpBaseAddress though any of these handles, sizes, pointers could be invalid. I would bet that either lpBaseAddress is NULL or nFileSize is invalid and that the crash is because of that.
Thank you everyone for your ideas, I changed pointers into references and the problem went away.
However, I am still stuck on the NULL return of the function, the dwOldSum always becomes zero. MSDN doesn't provide information why that is so. GetLastError after the CheckSumMappedFile also offers a value of 0 which states nothing about the extended error itself. Somebody helps me please?
The linker computes the original checksum at link time, if you use the appropriate linker switch. For more details, see your linker documentation.
and, yes they were right... in my project the Set Checksum option was No so I changed it to Yes and voila!
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
Bookmarks