Solved

SHFileOperation and SHFILEOPSTRUCT problem

Posted on 2003-12-03
6
691 Views
Last Modified: 2013-11-20
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
Comment
Question by:loudogz
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 9871658
Have you tried to

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

?
0
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 250 total points
ID: 9872057
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
 

Author Comment

by:loudogz
ID: 9873242
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:loudogz
ID: 9873248
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
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9873277
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
 

Author Comment

by:loudogz
ID: 9875263
thanks roshman.... that worked!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 56
Best tools for Backup and restore of Wordpress site 6 55
isEverywhere  challenge 19 72
wordappend challenge 8 150
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now