gpt4 book ai didi

delphi - Shell 函数的失败返回值

转载 作者:行者123 更新时间:2023-12-03 19:41:07 30 4
gpt4 key购买 nike

我在用:

Result := not Boolean(SHFileOperation(lpFileOp));
FOperationAborted := lpFileOp.fAnyOperationsAborted

复制文件,在极少数情况下,文件复制由于某种原因没有完成。除了 OpAbort 和函数的 bool 值本身之外,我似乎找不到返回值。

我尝试使用 GetLastError但这总是零。

有什么办法可以找出错误是什么?
它可能是磁盘已满、文件名无效、目标写保护、硬件磁盘写入错误或其他任何问题,如果发生错误,我似乎不知道如何处理。

最佳答案

您需要阅读 documentation仔细看功能。它说:

Return value

Type: int

Returns zero if successful; otherwise nonzero. Applications normally should simply check for zero or nonzero.

It is good practice to examine the value of the fAnyOperationsAborted member of the SHFILEOPSTRUCT. SHFileOperation can return 0 for success if the user cancels the operation. If you do not check fAnyOperationsAborted as well as the return value, you cannot know that the function accomplished the full task you asked of it and you might proceed under incorrect assumptions.

Do not use GetLastError with the return values of this function.

To examine the nonzero values for troubleshooting purposes, they largely map to those defined in Winerror.h. However, several of its possible return values are based on pre-Win32 error codes, which in some cases overlap the later Winerror.h values without matching their meaning. Those particular values are detailed here, and for these specific values only these meanings should be accepted over the Winerror.h codes. However, these values are provided with these warnings:

  • These are pre-Win32 error codes and are no longer supported or defined in any public header file. To use them, you must either define them yourself or compare against the numerical value.
  • These error codes are subject to change and have historically done so.
  • These values are provided only as an aid in debugging. They should not be regarded as definitive.

.... table removed, please refer to documentation ....



所以,简而言之,你必须捕获返回值,它是一个整数。如果该返回值非零,则该函数将失败。然后文档会告诉您如何将该返回值解释为推断失败原因的一种方法。请注意,文档清楚地表明这些失败原因不是确定的。并且文档清楚地表明 GetLastError不应该被调用。

如果报告准确的错误消息对您很重要,那么您应该使用 IFileOperation 反而。其 documentation提供了一长串喜欢它而不是 SHFileOperation 的理由.其中之一是:

More accurate error reporting through HRESULT values in conjunction with an API such as FormatMessage. Return codes from SHFileOperation could be misleading or inaccurate.

关于delphi - Shell 函数的失败返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23449071/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com