The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Citric on June 24, 2005, 10:57:07 AM

Title: Appending to a file
Post by: Citric on June 24, 2005, 10:57:07 AM
Hi all

When opening a file like ->

invoke CreateFile,ADDR fileName,GENERIC_WRITE,NULL,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
invoke WriteFile,[hLogger],ADDR pText,eax,ADDR numBytes,NULL

is there any way to append the file when it is open for a second time?

I have looked throught MSDN and google to find a simple solution but most the time examples use fopen and other starndard c stuff.

Any help is appreciated?

Cheers Adam
Title: Re: Appending to a file
Post by: Tedd on June 24, 2005, 10:59:39 AM
SetFilePointer?
Title: Re: Appending to a file
Post by: brixton on June 24, 2005, 11:17:18 AM
Yeah if you know how far to move the pointer then you can use SetFilePointer or _lseek I believe and get to the end of the file, so the next write will append to it.
Title: Re: Appending to a file
Post by: Citric on June 24, 2005, 11:34:15 AM
Cheers

that give me another avenue to chase down!

Thanks Adam
Title: Re: Appending to a file
Post by: Citric on June 24, 2005, 11:40:38 AM
And MSDN gave me the rest!

invoke CreateFile,ADDR fileName,GENERIC_WRITE,NULL,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL

invoke SetFilePointer,[hLogger],0,NULL, FILE_END

invoke WriteFile,[hLogger],ADDR pText,eax,ADDR numBytes,NULL

for peoples future reference!
Title: Re: Appending to a file
Post by: Tedd on June 24, 2005, 12:01:29 PM
This is what I meant.
SetFilePointer allows you to move to the end anyway (without you needing to know where that is) ::)
And if not, you could get the file's size :bdg

Anyway, problem solved :U