The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ecube on May 02, 2010, 04:19:05 AM

Title: CreateFile OPEN_ALWAYS flag doesn't work
Post by: ecube on May 02, 2010, 04:19:05 AM
can't get the 'OPEN_ALWAYS' flag to work, it suppose to open the file if it exists otherwise create.

invoke CreateFile,addr filename,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,0

Title: Re: CreateFile OPEN_ALWAYS flag doesn't work
Post by: MichaelW on May 02, 2010, 05:23:16 AM
OPEN_ALWAYS works for me, just as it is documented to work. If the file does not exist then the function returns a handle and GetLastError returns zero. If the file does exist then the function returns a handle and GetLastError returns ERROR_ALREADY_EXISTS. If the function fails (returns INVALID_HANDLE_VALUE) then the problem is elsewhere.
Title: Re: CreateFile OPEN_ALWAYS flag doesn't work
Post by: ecube on May 02, 2010, 05:30:34 AM
herm...not workin correctly on my xp, works on win7 :\ same code,both places have write permission for the directory they're in.
Title: Re: CreateFile OPEN_ALWAYS flag doesn't work
Post by: MichaelW on May 02, 2010, 05:33:12 AM
How is it failing, and what does GetLastError return?