Jump to content
Sign in to follow this  
ArxBzFhblxphS

..

Recommended Posts

ArxBzFhblxphS
Posted Image Edited by Thanubis

Share this post


Link to post
Share on other sites
Authenticity

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.

Share this post


Link to post
Share on other sites
Authenticity

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

Share this post


Link to post
Share on other sites
Authenticity

$file = FileCopy($file, StringTrimRight($file, 3) & "bin", 0)

$hFile = _WinAPI_CreateFile($file, 2)

;)^_^

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.