Previously,

I Opened an existing file and readed by create file-mapping. (CreateFileMapping)
It was successful!

Now, I want to write a new file (NOT existing file) by file-mapping. So, I coded this:

-----------------------------------------------------------------------------------
invoke CreateFile,szFilename,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
.if eax==INVALID_HANDLE_VALUE
xor eax,eax
ret
.endif
mov hFile,eax

invoke CreateFileMapping,eax,NULL,PAGE_READWRITE,0,0,NULL
; -> Return value is NULL!!! :(

-----------------------------------------------------------------------------------

CreateFileMapping function return NULL.

Please help me!

Thank you for reading.
Have a good day! :)
Posted on 2002-05-29 21:55:30 by nyam
Hey
Just took a quick look at CreateFileMapping and it says

PAGE_READWRITE Gives read-write access to the committed region of pages. The file specified by hFile must have been created with GENERIC_READ and GENERIC_WRITE access.


Your file is not being created with GENERIC_READ. I would start there. As far as I can tell, the rest is cool


--Chorus
Posted on 2002-05-29 23:25:10 by chorus
Thank you for replying chorus!!! :)

But...
I tested with GENERIC_READ|GENERIC_WRITE option.

But It didn't work.

How can I do? :(
Posted on 2002-05-29 23:28:31 by nyam
My second guess would have to do with CreateFile. You might try using

CreateFile, addr FileName,...

instead. Don't forget that this first param should be the offset of FileName, not filename itself. Or, should I say, the first 4 bytes of FileName. Of course, if you had this working before this way... (which would surprise me to be honest)...

After that, I might double check Icz's tut on memory management and File I/O...
--Chorus
Posted on 2002-05-29 23:45:54 by chorus