Jump to content

Recommended Posts

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 by Authenticity
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...