0

我正在使用 SHFileOperation 将文件删除到回收站。但有时我收到“系统调用级别不正确”错误。它不是每次或每个文件都发生。只是随机时间的一些随机文件。有人知道原因吗?谢谢。

更新:这是我正在使用的代码:

function DeleteToRecycleBin(const ADir : WideString) : Integer;
var
  op : SHFILEOPSTRUCTW;
begin
  ZeroMemory(@op, sizeof(op));
  op.pFrom := PWideChar(ADir + #0#0);
  op.wFunc := FO_DELETE;
  op.fFlags := FOF_SILENT or FOF_NOCONFIRMATION or FOF_NOERRORUI or FOF_ALLOWUNDO;
  Result := SHFileOperationW(op); 
end;
4

1 回答 1

2

您收到错误代码 124 (0x7C)。Win32 错误代码 124 是ERROR_INVALID_LEVEL. 但是,如果您阅读的文档SHFileOperation()它的一些错误代码早于 Win32,因此与相同的 Win32 错误代码具有不同的含义。错误代码 124 是这些值之一。在 的上下文中SHFileOperation(),错误 124 实际上意味着:

DE_INVALIDFILES 0x7C

源或目标或两者中的路径无效。

更新:试试这个:

function DeleteToRecycleBin(const ADir : WideString) : Integer;
var
  op : SHFILEOPSTRUCTW;
  sFrom: WideString;
begin
  // +1 to copy the source string's null terminator.
  // the resulting string will have its own null
  // terminator, effectively creating a double
  // null terminated string...
  SetString(sFrom, PWideChar(ADir), Length(ADir)+1);
  
  ZeroMemory(@op, sizeof(op));
  op.pFrom := PWideChar(sFrom);
  op.wFunc := FO_DELETE;
  op.fFlags := FOF_SILENT or FOF_NOCONFIRMATION or FOF_NOERRORUI or FOF_ALLOWUNDO;
  
  Result := SHFileOperationW(op); 
end;
于 2012-10-07T17:23:46.223 回答