0

My requirement is to get details about the items which are being dragged from outlook 2007.

I have used a windows API to register drag drop event on Outlook 2007 as following ... (public static extern int RegisterDragDrop(IntPtr hwnd, IOleDropTarget target);), and used IOleDropTarget interface to retrieve information when the drag drop events occur.

Following is what I have done so far

IOleDropTarget Interface

[ComImport, Guid("00000122-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleDropTarget
{
    [PreserveSig]
    int OleDragEnter([In, MarshalAs(UnmanagedType.Interface)] object pDataObj, [In, MarshalAs(UnmanagedType.U4)] int grfKeyState, [In, MarshalAs(UnmanagedType.U8)] long pt, [In, Out] ref int pdwEffect);
    [PreserveSig]
    int OleDragOver([In, MarshalAs(UnmanagedType.U4)] int grfKeyState, [In, MarshalAs(UnmanagedType.U8)] long pt, [In, Out] ref int pdwEffect);
    [PreserveSig]
    int OleDragLeave();
    [PreserveSig]
    int OleDrop([In, MarshalAs(UnmanagedType.Interface)] object pDataObj, [In, MarshalAs(UnmanagedType.U4)] int grfKeyState, [In, MarshalAs(UnmanagedType.U8)] long pt, [In, Out] ref int pdwEffect);
}

At event of an item being dragged from outlook, following method fires with all the parameters passed in to the method .

int IOleDropTarget.OleDragEnter(object pDataObj, int grfKeyState, long pt, ref int pdwEffect)
    {           
      retirn 0;
    }

Is it possible to get the information about the item which is being dragged using the pDataObj ?

So far i have tried following to get information out of this object which gave me no information about the item being dragged.

Type myType = pDataObj.GetType();

Is there other things to do to get the information I want ?

Code examples will be appreciated

Thank you

Nilaksha Perera
  • 715
  • 2
  • 12
  • 36

1 Answers1

1

You need to get the running Outlook instance and then get the Selection object from the active explorer window. It will contain the dragged data.

 // Check whether there is an Outlook process running.
 if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
 {
    // If so, use the GetActiveObject method to obtain the process and cast it to an Application object.
   application = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
  }

See How to: Get and Log On to an Instance of Outlook for more information.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Thank you for the reply Eugene. Is it possible to get the information of attachments which are being dragged using this method ? – Nilaksha Perera Jun 29 '15 at 09:55
  • Try to play with the pDataObj object to extract any information which allows to identify the dragged object. Then you will be able to find a corresponding object in Outlook. – Eugene Astafiev Jun 29 '15 at 10:13
  • Ive been trying to get something out of that object since several hours. I even tried parsing this object to Outlook.MailItem object , and some other types that i can imagine. Still the code will execute without throwing any error, leaving a null values in the variables. Example : Executing following code will not throw errors but still the variable will hold null after executing . `Outlook.MailItem mail = pDataObj as Outlook.MailItem;` – Nilaksha Perera Jun 29 '15 at 10:32
  • You will not be able to cast the pDataObj object to any Outlook type. – Eugene Astafiev Jun 29 '15 at 10:58
  • okay Eugene. Thank you for the help. ill try to get something out of the pDataObj =) AND I'll let you know.. – Nilaksha Perera Jun 29 '15 at 11:03