ArxBzFhblxphS Posted May 2, 2009 Share Posted May 2, 2009 (edited) Edited August 9, 2009 by Thanubis Link to comment Share on other sites More sharing options...
Authenticity Posted May 2, 2009 Share Posted May 2, 2009 Look at _WinAPI_CreateFile(), _WinAPI_SetFilePointer() and _WinAPI_SetEndOfFile(). You don't need to loop and write a null character each time just for padding. Link to comment Share on other sites More sharing options...
Authenticity Posted May 2, 2009 Share Posted May 2, 2009 (edited) I think the first code snippet is not working because AutoIt open the file internally with FILE_SHARE_READ | FILE_SHARE_WRITE and if you try to open already opened file with another FILE_SHARE_* other than those specified the function will fail.Take a look again at the first code you'll see that you're opening the file but not storing the new handle and thus the file remains opened with share read and write...Edit: Here is an example to demonstrate what it means:#include <WinAPI.au3> Dim $hFile1, $hFile2 $hFile1 = _WinAPI_CreateFile(@ScriptFullPath, 2, 6, 6) ConsoleWrite($hFile1 & @LF) $hFile2 = _WinAPI_CreateFile(@ScriptFullPath, 2, 6, 2) ConsoleWrite($hFile2 & @LF) If $hFile2 Then _WinAPI_CloseHandle($hFile2) If $hFile1 Then _WinAPI_CloseHandle($hFile1)If you'll change the second _WinAPI_CreateFile() call to $hFile2 = _WinAPI_CreateFile(@ScriptFullPath, 2, 6, 6) you'll get a valid handle of the file. So if you're trying to open an already opened file with different share mode the function will fail. Edited May 2, 2009 by Authenticity Link to comment Share on other sites More sharing options...
Authenticity Posted May 3, 2009 Share Posted May 3, 2009 $file = FileCopy($file, StringTrimRight($file, 3) & "bin", 0) $hFile = _WinAPI_CreateFile($file, 2) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now