views:

61

answers:

2

Hi guys,

Ive got an annoying problem, I cant append any text to the text file. Every time I open it for writing, I overwrite the data. I tried to move the file pointer to the end of the file, but no result (no writing to the file at all). Here is the code:

INVOKE CreateFile, offset filePath, GENERIC_WRITE, FILE_SHARE_WRITE, 0, OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0
mov hFile, eax
mov edx, 10
INVOKE SetFilePointer, hFile, 0, 0, FILE_END
INVOKE WriteFile, hFile, offset buffer, edx, ADDR SizeReadWrite, NULL
INVOKE CloseHandle, hFile

Any ideas? Thank you in advance!

+1  A: 

See the MSDN example. You might also want the reference of the CreateFile function.

Andreas Rejbrand
+1  A: 

You're setting the value of edx before the call to SetFilePointer and using it after the call. However, Windows API functions use the stdcall calling convention which is not guaranteed to preserve the edx register, so the value in it is destroyed, and the call to WriteFile fails.

interjay
interjay, that is the point! :)thanks
Bruce