prob with MapViewOfFile
hi
i'm having a little problem with MapViewOfFile, the function returns a non-null value, the address of the mapped file but nothing appers there, just ????? values (i used **** to debbug)
invoke CreateFile <- all ok, returns file handle
invoke CreateFileMapping <- all ok, returns filemapping handle
invoke MapViewOfFile, filemappedhandle, FILE_MAP_READ, 0, 0, DWORD PTR filesize <- returns an address of uninitilized data (???? values)

what am i doing wrong? i only want to have read access.

here's the full version
....


pfft, you're beyond remedy baZik, sorry...

krono or whatever your name is, here's a working snipped i just ripped together
from one of my programs so its NOT tested but it SHOULD work...



.DATA
MAPSIZE DD 1000 ; 1000 BYTES AS EXTRA BUFFER...
FILENAME DB "TEST.TXT",0 ; (BETTER IS BETTER AND IT WONT HURT
; YOU...)
.DATA?
FILEHANDLE DD ?
FILESIZE DD ?
H_BUFFER DD ?
M_BUFFER DD ?

.CODE
INVOKE CreateFile,ADDR FILENAME,GENERIC_READ+GENERIC_WRITE,0,NULL,\
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
CMP EAX, INVALID_HANDLE_VALUE ; OPEN FILE
JZ _ERR

MOV FILEHANDLE,EAX

INVOKE GetFileSize,EAX,NULL ; GET FILESIZE
INC EAX
JZ _ERR
DEC EAX

MOV FILESIZE,EAX
ADD MAPSIZE,EAX ; MAPSIZE=EXTRA_BUFFER+FILESIZE
; CREATE FILE MAPPPING
INVOKE CreateFileMapping,FILEHANDLE,NULL,PAGE_READWRITE,NULL,MAPSIZE,0
MOV H_BUFFER, EAX
; MAP VIEW
INVOKE MapViewOfFile,H_BUFFER,FILE_MAP_WRITE,0,0,MAPSIZE
MOV M_BUFFER,EAX
MOV EDI, EAX ; POINTER TO OUR ALLOCATED MEMORY


;EDI (OR M_BUFFER) POINTS NOW TO THE START OF THE MAPPED MEMORY BLOCK...
;YOU HAVE WRITE AND READ ACCESS TO THIS REGION SO YOU CAN DO WHAT YOU WANT
;WITH THAT FILE NOW... FOR EXAMPLE CHANGE THE FIRST BYTE (MOV BYTE PTR [EDI], "A")


INVOKE UnmapViewOfFile,M_BUFFER ; UNMAP FILE
INVOKE CloseHandle,H_BUFFER ; CLOSE MAPPING OBJECT

; SET FILEPOINTER TO EOF
; (WHEN THE ORIGINAL FILE IS
; LARGER THAN BEFORE NOW AND YOU
; WANT TO SAVE IT LIKE THIS)
;INVOKE SetFilePointer,FILEHANDLE,ESI,0,FILE_BEGIN
;INVOKE SetEndOfFile,FILEHANDLE ; UPDATE FILE EOF


INVOKE CloseHandle,FILEHANDLE ; CLOSE FILEHANDLE

...

_ERR: ;SOMETHING WENT WRONG...
Posted on 2002-08-23 06:03:44 by mob
Tut13 shows how to use it. I just hate that he left out the editing features. Guess I got to dig through it too ,to see what I need to do to edit.
Posted on 2003-03-19 22:53:27 by mrgone
i do not know if this gona help u or not but u can look at this. Thist prog i full of bugs but it's working so after "open file" the size have to be > 1 as i remember u can chose one of the options.
BTW. i think that Iczellion's tut with MemoryMappedFile was the worst of all Iczelions TUTS i have readen so far.
Posted on 2003-03-20 06:11:05 by AceEmbler
Thanks freind. :)

I'll look this over. I didn't get the resource files with it so I can't really see what it does but looking at the code I see the mile mapping uses.
Posted on 2003-03-20 13:46:12 by mrgone
Resource is no needed all buttons and boxes creates during WM_CREATE
Posted on 2003-03-20 15:34:01 by AceEmbler