如何在AutoIt中找到复制失败的原因?

AutoIt FileCopy method定义了以下返回值:

Return Value

Success: 1.
Failure: 0.

显然,当文件复制操作失败时,我想告诉用户它失败的原因.我如何获得这些信息?

最佳答案 编辑:带有消息输出的重写功能(最后一个错误不适用于au3 filecopy)

ConsoleWrite(copyFile("./ft", "./tg8"))


Func copyFile($source, $dest)

    $ret = DllCall("kernel32.dll", "int", _
            "CopyFileEx", _ ; W
            "str", $source, _
            "str", $dest, _
            "ptr", Null, _ ;no callback
            "str", Null, _
            "int", 0, _
            "int", 0)

    Return _GetLastErrorFormatMessage()

EndFunc   ;==>copyFile



Func _GetLastErrorFormatMessage()
    Local Const $FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
    Local $ret = ""
    Local $message = ""
    Local $err = ""
    Local $buff = DllStructCreate("char[4096]")

    $err = DllCall("Kernel32.dll", "int", "GetLastError")
    $ret = DllCall("kernel32.dll", "int", "FormatMessage", _
            "int", $FORMAT_MESSAGE_FROM_SYSTEM, _
            "ptr", 0, _
            "int", $err[0], _
            "int", 0, _
            "ptr", DllStructGetPtr($buff), _
            "int", 4096, _
            "ptr", 0)
    $message = DllStructGetData($buff, 1)
    $buff = Null
    Return $message
EndFunc   ;==>_GetLastErrorFormatMessage
点赞