System call level is not correct

2.2k Views Asked by At

I'm using SHFileOperation to delete files to Recycle bin. But sometimes I received a "System call level is not correct" error. It not happens every time or every file. Just some random files at random time. Anyone knows the reason? Thanks.

Update: Here it the code I am using:

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;
1

There are 1 best solutions below

10
On

You are receiving error code 124 (0x7C). Win32 error code 124 is ERROR_INVALID_LEVEL. However, if you read the documentation for SHFileOperation(), some of its error codes pre-date Win32 and thus do not have the same meaning as the same Win32 error codes. Error code 124 is one of those values. In the context of SHFileOperation(), error 124 actually means:

DE_INVALIDFILES 0x7C

The path in the source or destination or both was invalid.

Update: try this:

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;