Re: [VB6] Use IFileOperation to replace SHFileOperation for modern Copy/Move box/prom
Hi fafalone, First - THANK YOU for this!
I am not actually using the class, but took out the necessary parts I needed to do a basic move operation and it works fine. However, both my code and also in the class invokes an interface function like so:
In MoveFile function for instance:
iFileOp.PerformOperations
Not:
retval = iFileOp.PerformOperations
which won't work. How do I get the return value from the PerformOperations function? Surely there's a way as that's important to know what the error return code is!??
In other words, all the "functions" seem to be declared as Subs in the tlb and thus not returning their hresult/long. Yet that hresult is key to knowing what went wrong. For example, if the move didn't succeed, that hresult tells you why.
What am I missing? Is there some other way I'm supposed to be getting the return value of those interface functions?
EDIT: I ran across your notes for the TLB and see this problem is a common one. I don't understand why you declared them as HRESULT in the TLB if VB treats those as Subs? I also am not clear at all how to use the SwapvTableEntry thing to get the return value. Is there another way? What do I need to do?
Last edited by chrislong2; Feb 23rd, 2017 at 08:27 AM.
Re: [VB6] Use IFileOperation to replace SHFileOperation for modern Copy/Move box/prom
It's declared as an HRESULT because that's the default; it's not that HRESULT by definition is a Sub, that's something that VB forces behind the scenes. If you used it in another language, it would have a return value.
Changing it to a Long to get the return value has a consequence; any interface that has a return other than HRESULT cannot be implemented in VB (Implements)- that's why oleexmpimp.tlb exists, because it contains alternate versions of interfaces that do have non-HRESULT returns.
To get the return values, the TLB itself has to be changed. Swapping the v-table entry is only for when you're sending a return from your program, not receiving one, in an interface you're implementing yourself (e.g. IFileOperationProgressSink).
Since it's very uncommon to implement IFileOperation yourself, I'll go ahead and change it in the next version. I'll post the next version sometime in the next few days (as there's unrelated updates for a new version that I'm in the middle of), until then, there's two options:
1) Use IFileOperationProgressSink. In each 'Post' event, e.g. PostCopyItem, and after each series of operations, FinishOperations, the HRESULT of that particular operation is returned as one of the parameters. This has the added benefit of telling you precisely which operations failed if you were working with more than 1 file.
2) Modify the TLB yourself; IFileOperation is in exp_main.odl; change HRESULT to long, then recompile. Please do not distribute a modified TLB (a program compiled with it is fine though, as the TLB shouldn't be included with a compiled app).
Last edited by fafalone; Feb 23rd, 2017 at 09:38 PM.
Re: [VB6] Use IFileOperation to replace SHFileOperation for modern Copy/Move box/prom
Originally Posted by fafalone
Since it's very uncommon to implement IFileOperation yourself, I'll go ahead and change it in the next version. I'll post the next version sometime in the next few days
Thank you so much for the explanation! I don't have VC6 installed anymore so am not easily set up to create a TLB and I don't really need the callback function so I'll just wait for your version update - thank you!
Re: [VB6] Use IFileOperation to replace SHFileOperation for modern Copy/Move box/prom
I know this is a old thread, But thought I would let you know, started using your code and its working great, except one thing. The flag FOF_RENAMEONCOLLISION works when doing copy, but when doing a move the flag doesn't work.
Re: [VB6] Use IFileOperation to replace SHFileOperation for modern Copy/Move box/prom
Can he handle it? You copy both folders at the same time and then paste.
You can copy multiple folders directly in Explorer and paste them into other folders.
If the file you are copying has three large files and two folders.Can I cancel one of these five tasks.
I see that your initial instructions can only be all files, one file or multiple files.
Use the Explorer's method of adding compressed files to the extracted book. It can add a directory to it, but if there is an empty subdirectory inside, it will cause an error.
Can you test whether there is such a problem?Is there any parameter that can be avoided?
For example, do you want to write another piece of code to delete all the empty subdirectories under the directory first.
Re: [VB6] Use IFileOperation to replace SHFileOperation for modern Copy/Move box/prom
Originally Posted by freesix
Hi fafalone,
Your app was working perfectly until it crashes when trying to copy.
I even downloaded a new Zip folder to check maybe... but still behaving the same.
when I click on "Copy With Events" or "Copy" button, I got an error saying :
Code:
Runntime : '91'
Object Variable or Block Variable with undefined
The error is located in the below function.
Public Sub IFileOperationProgressSink_PreCopyItem(ByVal dwFlags As Long, ByVal psiItem As IShellItem, ByVal psiDestinationFolder As IShellItem, ByVal pszNewName As Long)
Dim lPtr As Long
psiDestinationFolder.GetDisplayName SIGDN_FILESYSPATH, lPtr
Debug.Print "cFileOperationProgressSink.IFileOperationProgressSink_PreCopyItem.destfolder=" & BStrFromLPWStr(lPtr, True)
DoEvents
End Sub
The debugger highlights the below line.
psiDestinationFolder.GetDisplayName SIGDN_FILESYSPATH, lPtr
-----------
I have the same problem with the current zip file.
Last edited by tmighty2; Jan 29th, 2025 at 09:40 AM.
Re: [VB6] Use IFileOperation to replace SHFileOperation for modern Copy/Move box/prom
It's mainly a demo so doesn't have robust error handling... You should check if psiDestinationFolder Is Nothing before trying to access it. Why it wouldn't be set in some circumstances would be a question for MS. Maybe if it has to be created it doesn't exist until post copy?
Re: [VB6] Use IFileOperation to replace SHFileOperation for modern Copy/Move box/prom
It turns out that you have already implemented this function. I have used this method to copy or delete files. As a result, the teacher will put forward a dialog box, and I have to close it manually. Think you have an excuse to trick him into not popping up the dialog box.