I am facing problem with MapViewOfFile.
Microsoft function MapViewOfFile() which reads part of file and returns start address of that content. This function needs some other info which is provided by functions like CreateFile, CreateFileMapping etc. UnMapViewOfFile is to close the view.
I am using MapViewOfFile() to read data that of a remote file, and is working fine. There is new content added to the same file on the remote machine. On finding that file is modified, closed the current map and handle etc. The same sequence of steps (functions)called till MapViewOfFile to open the same remote file and read the data again, to get new content. Here is the problem occurs. Instead of newly added data there exists zeros in the memory. Old existing data is read perfectly. The file is of not big (it is just 10-14KB). Till now this observed in Windows7 and not on all Windows7 machines. At the same time it is not observed all the times on the Windows7 machine where it is reproduced.
Till now this is observed only when opening remote files.
In msdn, under explanation of CreateFileMapping they mentioned that data will not be coherent, when opened on two mahcines for write. But in my case one is write where as the other is read. Ofcourse, even I am closing the view with UnMapViewOfFile() and trying to open again. Still problem exists.
One more observation is that if you open file F1 and close F1 for many times (repeat close and open for many times) still you don't find the newly added correct data. If you open another file F2, close file F2 and then open the old file F1, then you will find newly added data correctly.
The attributes used in CreateFile and CreateFileMapping are PAGE_READONLY, FILE_MAP_READ, FILE_SHARE_READ | FILE_SHARE_WRITE.
CreateFileMapping (handle, 0, PAGE_READONLY, 0, 0, 0);
MapViewOfFile (map, FILE_MAP_READ, 0, 0, 0);
Any Idea why it is so, and how to resolve?
Am I missing anything?