Search code examples
c#wpfoledragdrop

Can I get a destination/target of a DoDragDrop call?


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.


Solution

  • 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