Hey, i just wanna append some stuff to a file.
The code below creates the files and writes "hi" in it, but the second time i run it, it doesn't append.

.data  

stuff BYTE 'hi',0
stuff_len = ($-stuff)
myfile BYTE 'c:\myfile.txt',0

.data?
BytesWritten DWORD ?
hFile dword ?
.code
start:

invoke CreateFile,addr myfile,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE, NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,NULL
mov hFile,eax
invoke SetFilePointer,hFile,NULL,NULL,FILE_END
invoke WriteFile, hFile, addr stuff, stuff_len, addr BytesWritten ,NULL

invoke CloseHandle, hFile
invoke ExitProcess, NULL

end start



Anyone know what's wrong?
Thanks.
Posted on 2003-06-18 01:17:56 by Ghirai
Instead of CREATE_ALWAYS, use OPEN_ALWAYS.
Posted on 2003-06-18 01:29:30 by iblis
Changed to

invoke CreateFile,addr myfile,GENERIC_WRITE,FILE_SHARE_WRITE, NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL 


Now it doesn't crete the file... :(
Posted on 2003-06-18 01:46:33 by Ghirai
It should work the docs read...

OPEN_ALWAYS
Opens the file, if it exists.
If the file does not exist, the function creates the file as
if dwCreationDistribution were CREATE_NEW.

Strange,

RobotBob
Posted on 2003-06-18 02:24:03 by RobotBob
Yup, works, i had the path wrong.
Thanks everyone!
Posted on 2003-06-18 02:29:08 by Ghirai