Deeps_123

I am using the following code to copy files but i am unable to do so. The value function SHFileOperation retuns is 1026

char SrcPath[_MAX_PATH];
char DestPath[_MAX_PATH];

CString srcFile;//'('\0',80);
CString destFile ;//('\0',80);
srcFile.Format("%s%s\\0",SEARCH_DIR,FileName);
destFile.Format("%s%s\\0",REPLACE_DIR,FileName);

strcpy(SrcPath,srcFile);
//strcat(SrcPath,"\0");
strcpy(DestPath,destFile);
//strcat(DestPath, "\0");


SHFILEOPSTRUCT shFileOperate;

shFileOperate.lpszProgressTitle = "Copy";
shFileOperate.wFunc = FO_COPY;
shFileOperate.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_SIMPLEPROGRESS;
shFileOperate.pFrom = SrcPath;
shFileOperate.pTo = DestPath;
shFileOperate.fAnyOperationsAborted = FALSE;

int ret = SHFileOperation(&shFileOperate);

if(ret == 0)
{
AfxMessageBox("Fine");
}
else
{
AfxMessageBox("Error");
}
Please help me out



Re: Visual C++ Language SHFileOperation returns 1026

Simple Samples

Deeps_123 wrote:
I am using the following code to copy files but i am unable to do so. The value function SHFileOperation retuns is 1026
The value 1026 seems to have no significance except it is not zero.

Deeps_123 wrote:
destFile.Format("%s%s\\0",REPLACE_DIR,FileName);
I think you are trying to add a null to the end, but that won't do it. Even if it did, it won't help; see below.

I assume that SEARCH_DIR and REPLACE_DIR end with a backslash; otherwise srcFile and destFile won't have a backslash separating the directories and the filename.

Deeps_123 wrote:
strcpy(DestPath,destFile);
This will copy to the first null, which means that any extra null that was added at the end previous to here won't be copied. I think the following will append the second null:

DestPath[strlen(DestPath)+1] = 0;

CString can be used to append a null and that would likely simplify your code, but it is tricky doing that; it is easily possible to lose the extra null that way too.

You should become familiar with the debugger; you can use it to ensure that the paths and such are valid values. It would be tricky to spot the problem of a missing null using the debugger, but it would help with most other problems.