Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i have build this in 32 bit machine and it works perfectly fine in 32 bit machine but when i tried it on a 64 bit machine it doesn't work

C#
void _CopyItem(LPCWSTR src, PCWSTR dest, PCWSTR newname)
{
    IFileOperation *pfo;
    IShellItem *psiTo = NULL;
    IShellItem *psiFrom = NULL;

    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
    {
        if(S_OK == CoCreateInstance(CLSID_FileOperation,
            NULL,
            CLSCTX_ALL,
            IID_PPV_ARGS(&pfo)))
        {
            pfo->SetOperationFlags(FOF_NOCONFIRMATION
                | FOF_SILENT
                | FOFX_SHOWELEVATIONPROMPT
                | FOFX_NOCOPYHOOKS
                | FOFX_REQUIREELEVATION
                | FOF_NOERRORUI);
            {

                if(S_OK == SHCreateItemFromParsingName(src,
                    NULL,
                    IID_PPV_ARGS(&psiFrom)))
                {

                    if(NULL != &psiFrom)
                    {
                        if(S_OK == SHCreateItemFromParsingName(dest,
                            NULL,
                            IID_PPV_ARGS(&psiTo)))
                        {
                            CopyItem(psiFrom, psiTo, newname, NULL);
                            if(NULL != psiTo)
                                psiTo->Release();
                        }
                    }
                    psiFrom->Release();
                }
                pfo->PerformOperations();
            }
            pfo->Release();
        }
        CoUninitialize();
    }

}


i have a feeling if i compiled it on 64 bit machine it will work on 64 bit and will not work on 32 bit machine, im using VS2008
any ideas why this isn't working well ?

EDIT* it doenst' copy the file that i want
Posted
Updated 30-Jun-13 17:10pm
v3
Comments
[no name] 30-Jun-13 8:17am    
"it doesn't work" is neither helpful nor informative when you are trying to describe some sort of a problem.
H.Brydon 30-Jun-13 8:51am    
Agreed, what does "doesn't work" mean?

If it compiles properly but doesn't do what you expect at runtime, this looks like something you could easily figure out with the debugger.
Ronni2013 30-Jun-13 9:20am    
it doesn't copy the file, just nothing happens, no errors pop up either
krmed 30-Jun-13 9:27am    
Perhaps if you remove the FOF_NOERRORUI you might get some more information. This could be why you don't see any errors.

1 solution

This looks like the same/similar code found at the IFileOperation::CopyItem help page (here[^]) but with some of the return code checking removed. This looks like a straightforward problem. First, you should look at each return code and act accordingly. Second, just run this code in the debugger and step through each statement. Look at the return code and results of each statement as it executes. This is not a complicated problem.
 
Share this answer
 
Comments
[no name] 30-Jun-13 23:57pm    
This answer sounds reasonable and gets a 3 without any explanation. Does this mean someone else knows the "real" solution?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900