-
MapViewOfFile fails
Everything seems to go fine when using memory mapped files, but problem is handle to map is completely empty.
Code:
HANDLE hFile = CreateFile(infile, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE hFileMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, filesize, NULL);
PVOID pvFile = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 0);
char *temp = (char*) pvFile;
//now trying to write to another file al lthe data
FILE *f = fopen("test.txt","w");
//filesize already obtained and is more than 8 mb
fwrite(temp,1,filesize,f);
fclose(f);
now newly written file is of same size as source, but completely empty, ann bytes are empty.
What may be the problem ?
regards
-
Re: MapViewOfFile fails
try :
FILE *f = fopen("test.txt","wb");
-
Re: MapViewOfFile fails
No difference, same results.
The handle to the memory is completly empty.
Any one else please ?
-
Re: MapViewOfFile fails
pvFile is empty?
please check your infile, if the file is OK, please useabsolute path try again.
I think there maybe has a file sa same as like infile in your current path.
-
Re: MapViewOfFile fails
Actually the file am writing test.txt is for testing.
All the paths including "infile" are 100% correct I printed them already.
It is problem in MapViewOfFile that fails. It returns NULL.
regards
-
Re: MapViewOfFile fails
The source is no problem, please use getlasterror to show what is the error code.
-
Re: MapViewOfFile fails
05, that is error code, you have corrosponding string, I could not on msdn.
-
Re: MapViewOfFile fails
-
Re: MapViewOfFile fails
Now, GetLastError() returns 0, I have applied some fixes after reading msdn.
There seems no eror at all, but still the pointer 'pvFile' pointing to all places empty.
This is strange and is really bad, am exhousted of this.
regards
-
Re: MapViewOfFile fails
RESOLVED
Done, I got everything working perfectly, sorry for the hassle, it was my mistake (which was not actually error), I left file open and was trying to reopen it when windows returned me empty handle.
Thanks for your input.
regards