CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2004
    Location
    Pakistan
    Posts
    466

    Question 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
    » Please 'Rate This Post' if it helped (encourage us to help you more)
    » Build GUI in minute using rad c++
    » Free IDE + GUI code generator - screenshot
    » Free WINAPI sourcecode and tutorials

  2. #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/

  3. #3
    Join Date
    Nov 2004
    Location
    Pakistan
    Posts
    466

    Re: MapViewOfFile fails

    No difference, same results.
    The handle to the memory is completly empty.

    Any one else please ?
    » Please 'Rate This Post' if it helped (encourage us to help you more)
    » Build GUI in minute using rad c++
    » Free IDE + GUI code generator - screenshot
    » Free WINAPI sourcecode and tutorials

  4. #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/

  5. #5
    Join Date
    Nov 2004
    Location
    Pakistan
    Posts
    466

    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
    » Please 'Rate This Post' if it helped (encourage us to help you more)
    » Build GUI in minute using rad c++
    » Free IDE + GUI code generator - screenshot
    » Free WINAPI sourcecode and tutorials

  6. #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/

  7. #7
    Join Date
    Nov 2004
    Location
    Pakistan
    Posts
    466

    Re: MapViewOfFile fails

    05, that is error code, you have corrosponding string, I could not on msdn.
    » Please 'Rate This Post' if it helped (encourage us to help you more)
    » Build GUI in minute using rad c++
    » Free IDE + GUI code generator - screenshot
    » Free WINAPI sourcecode and tutorials

  8. #8

    Re: MapViewOfFile fails

    Access denied
    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/

  9. #9
    Join Date
    Nov 2004
    Location
    Pakistan
    Posts
    466

    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
    » Please 'Rate This Post' if it helped (encourage us to help you more)
    » Build GUI in minute using rad c++
    » Free IDE + GUI code generator - screenshot
    » Free WINAPI sourcecode and tutorials

  10. #10
    Join Date
    Nov 2004
    Location
    Pakistan
    Posts
    466

    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
    » Please 'Rate This Post' if it helped (encourage us to help you more)
    » Build GUI in minute using rad c++
    » Free IDE + GUI code generator - screenshot
    » Free WINAPI sourcecode and tutorials

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured