Under Windows XP, Vista and Windows 7 32-bit this all works correctly. Under Windows 7 x64 both the CopyFile operations fail. Initially, I thought it may be a permissions issue but running as administrator makes no difference. I then considered that there may be some problem with the underlying operation so I replaced the use of CopyFiles with direct calls to CopyFileA in kernel32.dll, and still the problem persisted. I made a small test app which perfoms the same operations using CopyFileA from kernel32 which does work, even without Admin privilidges.
Does anyone have any idea why this is the case?
Edit:
I have built a plugin DLL with the following function (just a wrapper around CopyFileA) which does work.
I can't imagine why this works, but the builtin CopyFiles command itself fails. Surely CopyFiles just does this, along with some other book keeping and error checking?
void __declspec(dllexport) copy(
HWND hWndParent, int string_size, char* variables, stack_t** stacktop, extra_parameters* extraParams)
{
char srcPath[1024], dstPath[1024];
DWORD error;
g_hwndParent = hWndParent;
EXDLL_INIT();
memset(srcPath, 0, 1024);
memset(dstPath, 0, 1024);
if (popstringn(srcPath, 1023) || popstringn(dstPath, 1023))
{
return;
}
if (!CopyFileA(srcPath, dstPath, FALSE))
{
char buffer[1024];
memset(buffer, 0, 1024);
error = GetLastError();
sprintf(buffer, "error: %d\n", error);
MessageBoxA(hWndParent, buffer, "CopyFile failed.", MB_OK);
}
}