SHFileOperation()

I want to use SHFileOperation() to copy/move files.
  For some files, SHFileOperation() will succeed. But for other Files, SHFileOperation() will return a ERROR MessageBox which said "File System Error(1026)". Why?
 
  ===CODE BEGIN===
        UINT OpResult;
      char SrcDir[MAX_PATH];
      char DstDir[MAX_PATH];
      SHFILEOPSTRUCT sendFileOp;

        memset(&sendFileOp,0,sizeof(sendFileOp));
      m_EDITCtrl.GetWindowText(DstDir,MAX_PATH);
      int n;

      for(n=0;n<sumFiles;n++){
           sendFileOp.hwnd=GetSafeHwnd();
           if(m_radioMode==0){
                 sendFileOp.wFunc=FO_COPY;
             }
           else{
                  sendFileOp.wFunc=FO_MOVE;
             }
       m_LISTsCtrl.GetText(n,SrcDir);
         //the list box contains the files which to be copied/moved.

       sendFileOp.pFrom=SrcDir;
         sendFileOp.pTo=DstDir;
         sendFileOp.fFlags=NULL;
         sendFileOp.hNameMappings=NULL;
         sendFileOp.lpszProgressTitle="FreeSender is sending";

           OpResult=SHFileOperation(&sendFileOp);
      }
 ===CODE END===

Looking forwards your suggestion?
henry3Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DrDelphiCommented:
Have you tried call GetLastError to see what error 1026 is?
0
nietodCommented:
Are you sure that is the error code, It does not seem to be defined.

Is it possible that some of the files are open?  If a file is open it can't be moved.
0
nietodCommented:
One potential problem is

m_LISTsCtrl.GetText(n,SrcDir);
                        //the list box contains the files which to be copied/moved.

The source string must be DOUBLE NUL terminated.   But GetText() returns a string that is only single NUL terminated.  To get around this, fill SrcDir with NULs before doing the GetText.  I suspect that the problem will go away (certainly one problem will go away.)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.