Hi guys,

This is my first time trying to implement something using the Windows API... I want to send a file to Trash on Windows. I searched the internet and found a couple more or less helpful pages, and I eventually ended up with the following couple lines of code:

Qt Code:
  1. QString filepath = "C:\\some\\file";
  2.  
  3. QFile f(filepath);
  4. if(!f.exists())
  5. qDebug() << "ERROR: File doesn't exist";
  6.  
  7. SHFILEOPSTRUCT FileOPStruct;
  8.  
  9. filepath += '\0';
  10.  
  11. FileOPStruct.hwnd=NULL;
  12. FileOPStruct.wFunc=FO_DELETE;
  13. FileOPStruct.pFrom=LPCWSTR(filepath.toStdString().c_str());
  14. FileOPStruct.pTo=NULL;
  15. FileOPStruct.fFlags=FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_ALLOWUNDO | FOF_SILENT;
  16. FileOPStruct.hNameMappings=NULL;
  17. FileOPStruct.lpszProgressTitle=NULL;
  18.  
  19. if(SHFileOperation(&FileOPStruct))
  20. qDebug() << "ERROR: Deletion failed";
  21. else
  22. qDebug() << "Deleted :)";
To copy to clipboard, switch view to plain text mode 

The file in QString filepath exists (the check passes just fine), but I always get to "ERROR: Deletion failed", and the file (obviously) is still there. I don't have any previous experience of using the Win API and am just not able to resolve the issue... would anyone mind helping me?

Thanks a million!! :-)