Jump to content

DllCall kernel32.dll CloseHandle doesn't close?


Squeeto
 Share

Recommended Posts

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

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...