Using SHFileOperation: What errors are occuring

Posted by Sascha on Stack Overflow See other posts from Stack Overflow or by Sascha
Published on 2010-12-31T04:08:36Z Indexed on 2010/12/31 4:54 UTC
Read the original article Hit count: 276

Filed under:
|

Hello

I am using the function SHFileOperation() to send a file to the recycling bin. And I am getting 2 errors that I do not know what they mean because with this function the error codes are not GetLastError() values.

Now when the function SHFileOperation() fails the return values are 0x57 (decimal 87) & 0x2 (decimal 2). Can you help me discover the definitions of these errors (expecially when you consider with this function, the errors are not part of the GetLastError() codes).

Some important information:

• I am using Windows 7 (& I know that MSDN says to use IFileOperation instead of SHFileOperation but I want to make my app backwards compatable which is why I am using SHFileOperation). If the error is occuring because I am using SHFileOperation on Windows 7 what solution could I use to make this work on all versions of windows from 2000 & up?

• I have debugged extensively & as far as I know my SHFILEOPSTRUCT is correct (correct flags used, .pFrom is a double-null ended string). One thing I know for sure is that my path to the file is correct (leads to a real file & it correctly formatted).

• About 2/5 times the SHFileOperation() works, meaning it sends the file to the recycle bin & does not returns an error

 BOOL result;
 SHFILEOPSTRUCT fileStruct;
 fileStruct.hwnd = hwnd; 
 fileStruct.wFunc = FO_DELETE;
 fileStruct.pFrom = dest.c_str();
 fileStruct.fFlags = FOF_FILESONLY; // FOF_ALLOWUNDO
 fileStruct.fAnyOperationsAborted = result;

 // Call operation(delete file)
 int success = SHFileOperation( &fileStruct );

 // if delete was successful
 if ( success != 0 ) 
 {
    printf( "%s \t %X %d \n", dest.c_str(), success, success );
    cout << result << endl;

    MessageBox( hwnd, "Failed to delete file", "Error", MB_OK|MB_ICONERROR );
    return;
 } 

© Stack Overflow or respective owner

Related posts about c++

Related posts about winapi