I've been working on getting this right for a few hours now, and it works perfectly on Windows Vista & Windows 7, but when I run it on Windows XP it fails without any message. Unfortunately I don't have a development environment under XP so I can't just run it through a debugger to check, have I missed something blindingly obvious? The same piece of code does actually use a CopyFile
and a few commands to write out data to C:\
so if it's a permissions error it's an odd one.
EDIT: The return value is 1223, ERROR_CANCELLED
which means cancelled by user.
EDIT 2: I disabled the s.fFlags and it immediately popped a dialog box up asking if it should create the dir-test
folder, so I switched to FOF_NOCONFIRMATION
and it appeared to ignore the flag. I do also use that during a deletion using the same SHFileOperation
method so it either doesn't apply to file copies.
LPTSTR source = L"dir-test\\*\0";
LPTSTR dest = L"C:\\dir-test\0";
SHFILEOPSTRUCT s = { 0 };
s.hwnd = 0;
s.wFunc = FO_COPY;
s.fFlags = FOF_SILENT;
s.pTo = dest;
s.pFrom = source;
int n;
n = SHFileOperation(&s);`