-
September 22nd, 2007, 09:20 PM
#1
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
-
September 24th, 2007, 11:58 PM
#2
Re: MapViewOfFile fails
try :
FILE *f = fopen("test.txt","wb");
Best Api Monitor tool.
Trace the target program automatically and monitor the parameters of all API and COM interfaces.
Auto Debug for Windows 4.0
Auto Debug for .Net
http://www.autodebug.com/
-
September 25th, 2007, 12:03 AM
#3
Re: MapViewOfFile fails
No difference, same results.
The handle to the memory is completly empty.
Any one else please ?
-
September 25th, 2007, 12:20 AM
#4
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.
Best Api Monitor tool.
Trace the target program automatically and monitor the parameters of all API and COM interfaces.
Auto Debug for Windows 4.0
Auto Debug for .Net
http://www.autodebug.com/
-
September 25th, 2007, 12:24 AM
#5
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
-
September 25th, 2007, 12:43 AM
#6
Re: MapViewOfFile fails
The source is no problem, please use getlasterror to show what is the error code.
Best Api Monitor tool.
Trace the target program automatically and monitor the parameters of all API and COM interfaces.
Auto Debug for Windows 4.0
Auto Debug for .Net
http://www.autodebug.com/
-
September 25th, 2007, 02:25 AM
#7
Re: MapViewOfFile fails
05, that is error code, you have corrosponding string, I could not on msdn.
-
September 25th, 2007, 03:59 AM
#8
Re: MapViewOfFile fails
Best Api Monitor tool.
Trace the target program automatically and monitor the parameters of all API and COM interfaces.
Auto Debug for Windows 4.0
Auto Debug for .Net
http://www.autodebug.com/
-
September 25th, 2007, 04:31 AM
#9
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
-
September 25th, 2007, 07:14 AM
#10
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|