Tech Support > Computers & Technology > Programming > [VC++] Passing parameters to the function. Not working. Why?
[VC++] Passing parameters to the function. Not working. Why?
Posted by Vojtek on November 10th, 2003


/////////////////////// THIS DOES NOT WORK

BOOL myCopy( CString &myFrom, CString &myTo)
{
SHFILEOPSTRUCT myFile;

myFile.hwnd=NULL;
myFile.wFunc=FO_COPY;
myFile.pFrom=myFrom;
myFile.pTo=myTo;
if (!((SHFileOperation(&myFile))==0))
{
AfxMessageBox("Error");
return FALSE;
}
return TRUE;
}

///// (...)

CString sCompFrom="C:\\*.jpg";
CString sCompTo="D:\\";

myCopy(sCompFrom,sCompTo);
-------------------------------------------------------------------------

///////////////////// THIS WORKS PERFECTLY!

BOOL myCopy( CString &myFrom, CString &myTo)
{
SHFILEOPSTRUCT myFile;

myFile.hwnd=NULL;
myFile.wFunc=FO_COPY;
myFile.pFrom="C:\\*.jpg"; //CHANGES HERE
myFile.pTo="D:\\"; //CHANGES HERE
if (!((SHFileOperation(&myFile))==0))
{
AfxMessageBox("Error");
return FALSE;
}
return TRUE;
}

///// (...)

CString sCompFrom="C:\\*.jpg";
CString sCompTo="D:\\";

myCopy(sCompFrom,sCompTo);
-------------------------------------------------------------------------

In first case, parameters are being passed correctly (I'm tracing those
variables). There is no problems with datatype conversion - I would be
getting something during compilation. O errors, 0 warnings. In both cases.
But only the second version works. First one does nothing. Just returns my
"Error" message.

What am I doing wrong ???

Thanks,
Wojtek


Posted by Programmer Dude on November 10th, 2003


Vojtek wrote:

Put a break point on the unsnipped line above and check to see
what myFile.pTo and myFile.pFrom actually point to. That should
tell you where the problem lies.


--
|_ CJSonnack <Chris@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|___ ____________________|

Posted by Vojtek on November 11th, 2003


I did. I even did something extra:

/.../
AfxMessageBox(myFile.pFrom);
AfxMessageBox(myFile.pFrom);
/.../

- right before calling SHFileOperation.

They both point exactly where I want to. The problem is - with that -
SHFileOperation doesn't want to work. It returns error message immediately
after executing and does nothing. And it's not just the problem of the
SHFileOperation(). I have identical situation with the CreateProcess()
function - to executing external commands. Exactly the same problem...



Posted by ak on November 12th, 2003


On Tue, 11 Nov 2003 09:41:41 +0100, "Vojtek"
<vojtek11@ANTISPAMMERpoczta.onet.pl> wrote:

try using myFile.pTo = myTo.GetBuffer() instead

/ak

Posted by Vojtek on November 12th, 2003



"ak" <ak@workmail.com> wrote in message
news:bd54rvcsjlhk2vqivqe50gco1vd4b01apa@4ax.com...
I did long a time ago. Not working either.




Posted by Programmer Dude on November 12th, 2003


Vojtek wrote:

I just noticed this with regard to SHFILEOPSTRUCT:

pFrom
Address of a buffer to specify one or more source file names.
Multiple names must be null-separated. The list of names must
be double null-terminated.
pTo
Address of a buffer to contain the name of the destination
file or directory. The buffer can contain multiple destination
file names if the fFlags member specifies FOF_MULTIDESTFILES.
Multiple names must be null-separated. The list of names must
be double null-terminated.

From your original post, it doesn't look like you're double-null-
terminating your strings?


CreateProcess() can be a little weird to use, AIR. I found that
I needed to send NULL for the first argument and the whole command
line as the second. Do you have it working, *except* if you use
CStrings?

--
|_ CJSonnack <Chris@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|___ ____________________|


Similar Posts