0

I have a WPF application. I want to allow users to drag and drop "files" (or their visual representation) from my WPF windows to the real Windows explorer.

This I managed to do by using the native DoDragDrop from Ole32.dll

[DllImport("ole32.dll", CharSet = CharSet.Auto, ExactSpelling = true, PreserveSig = false)]
public static extern void DoDragDrop(System.Runtime.InteropServices.ComTypes.IDataObject dataObject IDropSource dropSource, int allowedEffects, int[] finalEffect);

This works great.

But rather then copy the file, I want to just get the destination. i.e. if the user dragged the file to an explorer opened on C:\Folder - I want to get C:\Folder... Or at least get the object on which the drop event occurred at (which is outside my application), and hopefully I could then get the path from that object.

Maverick Meerkat
  • 5,737
  • 3
  • 47
  • 66
  • The drop is handled by the target, so if you are dropping something into other application (e.g explorer) - that application will try to handle it, not you. If you tell us what are you trying to do exactly, then maybe we can suggest you something better. – Sinatr Feb 08 '18 at 10:52
  • 1
    Not being able to tell anything about the drop target was very much a design feature. It is the target that handles it, the only thing that is passed back is whether it did so successfully. Passing back anything more would greatly complicate the protocol, process interop is never simple. Pinvoking DoDragDrop is not useful. – Hans Passant Feb 08 '18 at 11:04
  • that's a bummer, lol... I did manage to get some workaround for my needs using virtual file - where I basically send my code which is being executed on the drop event (tweaking this http://dlaa.me/blog/post/9913083) but it has a lot of limitations (I must give fully executed code without callbacks). If I had the destination it would be much better... – Maverick Meerkat Feb 12 '18 at 09:54

1 Answers1

2

Unless you created both the target and destination applications, you cannot get the information about the destination or target application.. This information is abstracted by design and is limited

Caveat : unless you write some sort of hook or Dll injection method to hook on the drag on drop events and monitor for them

TheGeneral
  • 79,002
  • 9
  • 103
  • 141