Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 724
  • Last Modified:

SHFileOperation and SHFILEOPSTRUCT problem

windows nt 4.0
I'm trying to copy a bunch of folders and files under a directory to some destination...eg:
CString strSource, strDestination;
strSource = "d:\\lou\\some area\\*.*;
strDestination = "d:\\SomeDestination";
SHFILEOPSTRUCT oshf;
oshf.pFrom = strSource;
oshf.pTo = strDestination;
SHFileOperation(&oshf);

This code works....But for some reason when i try this program on another computer with the IE 6.0... It craps out with a return code 1026.

Interesting thing is : if i hardcode the string value to pFrom and pTo.. it works. But for some reason it doesn't like CString...

Thanks in Advance,
Lou
0
loudogz
Asked:
loudogz
  • 3
  • 2
1 Solution
 
jkrCommented:
Have you tried to

SHFILEOPSTRUCT oshf;
ZeroMemory ( &oshf, sizeof ( oshf));

?
0
 
Roshan DavisCommented:
Yes, understood the problem


      CString      acqFileName;
      SHFILEOPSTRUCT sFileOp;

      char szPATH[260];
            
            sprintf(szPATH, "C:\\Old Watch\\*.txt");
            int nLen = lstrlen(szPATH);
            szPATH[nLen] = 0;                         <------ BOTH THESE
            szPATH[nLen+1] = 0;                    <------ SHOULD BE NULL !!!

            ZeroMemory(&sFileOp, sizeof(SHFILEOPSTRUCT));
            sFileOp.wFunc = FO_COPY;
            sFileOp.pFrom = /*acqFileName*/szPATH;
            sFileOp.pTo = arguments[1];
            sFileOp.fFlags = FOF_SILENT|FOF_NOCONFIRMATION|FOF_NOERRORUI;

            if ( SHFileOperation(&sFileOp) )
            {
              DWORD dwError = GetLastError();
                  return FALSE;
            }
            else
            {
                  return TRUE;
            }

MSDN Says

pFrom, pTo
Each file name must be terminated by a single NULL character. An additional NULL character must be appended to the end of the final name to indicate the end of pFrom.


Good Luck
0
 
loudogzAuthor Commented:
jkr,
I do this, I just didn't include it to make my post a little shorter.
SHFILEOPSTRUCT oshf;
ZeroMemory ( &oshf, sizeof ( oshf));

thanks,
lou
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
loudogzAuthor Commented:
roshman,
Can I pass a CString value to that this function sprintf(szPATH, "C:\\Old Watch\\*.txt"); instead of hardcoding "C:\\Old Watch\\*.txt" .... because I don't know the value it changes.... Another thing is that I know about this:
"pFrom, pTo
Each file name must be terminated by a single NULL character. An additional NULL character must be appended to the end of the final name to indicate the end of pFrom. "

But for some reason I'm having a hard time working with CString and adding double null character....

Thanks,
Lou
0
 
Roshan DavisCommented:
Yes,

Like this
   

CString csYourString;   <-- this contains the path


        sprintf(szPATH, csYourString);
         int nLen = lstrlen(szPATH);
         szPATH[nLen] = 0;                         <------ BOTH THESE
         szPATH[nLen+1] = 0;                 <------ SHOULD BE NULL !!!
Rosh :)
0
 
loudogzAuthor Commented:
thanks roshman.... that worked!
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now