Click to See Complete Forum and Search --> : Problem with SHFileOperation()
Donotalo
November 20th, 2007, 07:23 AM
#include <windows.h>
#include <iostream>
int main()
{
char source_name[1024], dest_name[1024];
SHFILEOPSTRUCT shFileOp;
strcpy(dest_name, "C:\\");
dest_name[strlen(dest_name)] = NULL;
strcpy(source_name, "D:\\Maya\\aw.txt");
source_name[strlen(source_name)] = NULL;
shFileOp.hwnd = NULL;
shFileOp.wFunc = FO_COPY;
shFileOp.pFrom = source_name;
shFileOp.pTo = dest_name;
shFileOp.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR;
if (SHFileOperation(&shFileOp))
std::cout << i << std::endl;
return 0;
}
The code is 1026. Why the operation is failing? Thanks in advance.
laitinen
November 20th, 2007, 07:48 AM
The code is 1026. Why the operation is failing? Thanks in advance.
What code is 1026?
What operation is failing?
What is i?
Donotalo
November 20th, 2007, 07:57 AM
Oh, sorry. The code is not complete. i is an int. 1026 is the return value of SHFileOperation(). When I run this program, a message box pops up and displays an error message: Cannot copy file: Cannot read from the source file or disk. This is happening with every file on my system. There is a file named aw.txt in my computer's D drive Maya folder (D:\Maya\aw.txt). Where is my mistake? Please help.
#include <windows.h>
#include <iostream>
int main()
{
char source_name[1024], dest_name[1024];
int i;
SHFILEOPSTRUCT shFileOp;
strcpy(dest_name, "C:\\");
dest_name[strlen(dest_name)] = NULL;
strcpy(source_name, "D:\\Maya\\aw.txt");
source_name[strlen(source_name)] = NULL;
shFileOp.hwnd = NULL;
shFileOp.wFunc = FO_COPY;
shFileOp.pFrom = source_name;
shFileOp.pTo = dest_name;
shFileOp.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR;
i = SHFileOperation(&shFileOp);
if (i)
std::cout << i << std::endl;
return 0;
}
Marc G
November 20th, 2007, 09:10 AM
According to MSDN 1026 means:
An unknown error occurred. This is typically due to an invalid path in the source or destination. This error does not occur on Windows Vista and later.
Try to initialize the structure to all zeros like:
SHFILEOPSTRUCT shFileOp = {0};
golanshahar
November 20th, 2007, 02:18 PM
pFrom
Note This string must be double-null terminated.
pTo
Note This string must be double-null terminated.
Thats mean that
char source_name[1024]={0}, dest_name[1024]={0};
Will solve you problem. ;)
Cheers
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.