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



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

最佳答案

编辑:带有消息输出的重写函数(最后一个错误不适用于 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

关于autoit - 如何在 AutoIt 中找到复制失败的原因?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38913130/

10-12 21:07