I hooked the CopyItems method of IFileOperation to monitor/intercept file copy in windows.
My problem is how can i retrieve the full file name from IShellItem(last param of CopyItems)
function New_CopyItems(p: Pointer; punkItems: IUnknown;psiDestinationFolder: IShellItem): HResult; stdcall;
The psiDestinationFolder have a method called GetDisplayName that return only the folder name of current file was begin copied!! But i want to get full file name and don't know what i should to do !? There is any other method to help me getting full name ?? Or i have to using another API ....?
Excuse me if my English is bad!
The
CopyItemsmethod copies potentially multiple items. So right off the bat you are mistaken looking for a single file name. This is a very complex API and you do need to read the documentation carefully and understand clearly how the function works.The
psiDestinationFolderparameter is anIShellItemthat identifies the destination. Use theGetDisplayNamemethod to get the file path.The other parameter,
punkItemsis more complex. It is documented like this:This is telling you that there could be an
IShellItemArray,IDataObject,IEnumShellItemsor aIPersistIDListobject behind theIUnknowninterface that you receive. And that there could be multiple items in that single object, each one to be copied to the destination folder. You will need to querypunkItemsfor each possible interface in turn until you find out which of these possibilities you have to deal with. And then handle each one with special code. In order to test this you'll need to write code that callsCopyItemswith each of the possible interfaces. You'll find out how to do all of this from the documentation of each of the four interfaces. If you don't already know shell programming and COM well, expect to do so by the time you complete this work.Finally, I doubt that this is a very good way to detect file copying. Files are copied using many different APIs. And
IFileOperation.CopyItemsis but one of them. If you only hookIFileOperation.CopyItemsthen you'll miss a lot of file copy operations.