i'm making a proc for file mapping but it does not work as planned .

Can somebody find the error ?

It shoud overwrite the file with new text but it does not work


MapFile PROTO :DWORD,:DWORD,:DWORD,:DWORD
.data
file DB "1.txt",0
a DB "Works fine!!!",0
mapv DD 0
fhwn HWND 0
fmap DD 0
nbw DD 0


.code
start:

invoke MapFile,addr file,fhwn,fmap,mapv
invoke
invoke WriteFile,fhwn,addr a,sizeof a,addr nbw,0 ;it just does not write to the file ????Wonder why ????

invoke CloseHandle,fhwn
invoke CloseHandle,fmap
invoke UnmapViewOfFile,mapv
invoke ExitProcess,0
MapFile proc fileName:DWORD,FHwn:DWORD,MapHwnd:DWORD,var:DWORD
.data?
fsize HWND ?
ofst OFSTRUCT<?>
.code

invoke OpenFile,fileName,addr ofst,OF_READWRITE
mov FHwn,eax
invoke GetFileSize,FHwn,fsize
invoke CreateFileMapping,FHwn,0,PAGE_READWRITE,fsize,0,0
mov MapHwnd,eax
invoke MapViewOfFile,eax,FILE_MAP_ALL_ACCESS,0,0,0
cmp eax,0
je error
mov var,eax


ret
error :
invoke MessageBox,0,0,0,MB_ICONERROR


ret

MapFile endp

end start
Posted on 2004-07-31 05:26:38 by Gangleri
No...one has to use FlushViewOfFile ...instead of WriteFile ....


If you want a good example go and see---->

http://pageperso.aol.fr/GerardChap/Start.html

or directly here----
http://pageperso.aol.fr/gerardchap/multi-threads.ziphttp://pageperso.aol.fr/gerardchap/multi-threads.zip


Gerard
-----
Posted on 2004-08-01 05:18:08 by gerard
When working with filemapping, you don't use WriteFile - you write to the memory pointer returned by MapViewOfFile.
Posted on 2004-08-01 06:31:41 by f0dder
thank you for the links ....

You are the best :alright:
Posted on 2004-08-03 03:07:41 by Gangleri