I have been developing a Outlook plugin where I want to intercept the drag drop of attachments so that I can change the property of IDataObject but somehow my callback function is never executed.I have been using EasyHook open library to achieve the same,I have successfully hooked few other common APIs like CreateFile etc though.
Below is code snapshot.
public partial class DragDrop {
private LocalHook DragDropHook;
Stack<String> Queue = new Stack<string>();
internal class HookCallbackHelper
{
public HookCallbackHelper(bool isUnicode) { IsUnicode = isUnicode; }
public bool IsUnicode;
}
private void DragDrop_Load(object sender, RibbonUIEventArgs e)
{
}
private void btnHook_Click(object sender, RibbonControlEventArgs e)
{
try
{
DragDropHook = LocalHook.Create(LocalHook.GetProcAddress("Ole32.dll", "DoDragDrop"),
new DDoDragDrop(DoDragDrop_Hooked),new HookCallbackHelper(true));
DragDropHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 });
}
catch (Exception ExtInfo)
{
System.Windows.Forms.MessageBox.Show(ExtInfo.Message);
//Interface.ReportException(ExtInfo);
return;
}
}
private int DoDragDrop_Hooked(IDataObject pDataObj, IDropSource pDropSource, uint dwOKEffects, uint[] pdwEffect)
{
System.Windows.Forms.MessageBox.Show("Hooked");
try
{
HookCallbackHelper hch = HookRuntimeInfo.Callback as HookCallbackHelper;
lock (Queue)
{
Queue.Push("[" + RemoteHooking.GetCurrentProcessId() + ":" +
RemoteHooking.GetCurrentThreadId() + "]");
}
}
catch
{
}
// call original API...
return DoDragDrop(pDataObj, pDropSource, dwOKEffects, pdwEffect);
}
[UnmanagedFunctionPointer(CallingConvention.StdCall,
CharSet = CharSet.Ansi,
SetLastError = true)]
public delegate int DDoDragDrop(
IDataObject pDataObj,
IDropSource pDropSource,
UInt32 dwOKEffects,
UInt32[] pdwEffect
);
[DllImport("Ole32.dll",
CharSet = CharSet.Unicode,
SetLastError = true,
CallingConvention = CallingConvention.StdCall)]
public static extern int DoDragDrop(IDataObject pDataObj, IDropSource pDropSource,
UInt32 dwOKEffects, UInt32[] pdwEffect);
}
[ComImport, Guid("00000121-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IDropSource
{
[PreserveSig]
UInt32 QueryContinueDrag(
[MarshalAs(UnmanagedType.Bool)] bool fEscapePressed,
UInt32 grfKeyState);
[PreserveSig]
UInt32 GiveFeedback(
UInt32 dwEffect);
}