Squeeto Posted February 12, 2009 Posted February 12, 2009 Hi guys, I have been troubled with this one a while; it is time to ask. I would like to delete a file after a DllCall for CreateFile but the call holds up the file. Am I not releasing it somehow? #include <GUIConstants.au3> $main = GUICreate("", 115, 65) $btn = GUICtrlCreateButton("", 20, 20, 75, 25, $BS_DEFPUSHBUTTON) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg(1) Select Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $main ExitLoop Case $msg[0] = $btn And $msg[1] = $main $s = @ScriptDir & "\asdf.txt" a($s) FileDelete($s) ;<---why doesn't this work? EndSelect WEnd Func a($file) $hFile = DllCall("kernel32.dll", "ptr", "CreateFile", _ "str", $file, _ "dword", $GENERIC_READ, _ "dword", $FILE_SHARE_READ, _ "dword", "", _ "dword", $OPEN_EXISTING, _ "dword", $FILE_ATTRIBUTE_NORMAL, _ "ptr", 0) If Not @error Then ;... I will do more here later DllCall("kernel32.dll", "int", "CloseHandle", "ptr", $hFile) If Not @error=0 Then MsgBox(0,"Error",@error) Else MsgBox(16, "Error", "Error retreaving file.") EndIf EndFunc TIA
monoceres Posted February 12, 2009 Posted February 12, 2009 Both CreateFile and CloseHandle are available in WinAPI.au3 as _WinAPI_CreateFile and _WinAPI_CloseHandle, so you don't need to worry about the calling of the functions. Broken link? PM me and I'll send you the file!
Authenticity Posted February 12, 2009 Posted February 12, 2009 Read again DllCall documentation and what kind of variable it returns ^^
Squeeto Posted February 12, 2009 Author Posted February 12, 2009 Read again DllCall documentation and what kind of variable it returns ^^Crap. I have done this before! Thanks guys. DllCall("kernel32.dll", "int", "CloseHandle", "ptr", $hFile[0])
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