-1

"Ole32","DoDragDrop" function Hooking to the explorer is successful but whenever i drag a file in explorer my DoDragDropHook function is not calling, am new to the hooking concepts and i trying for this from last 3 months but till now no proper result. please help me where am going wrong

 namespace DragDrop_DLL
{
    public class Main : EasyHook.IEntryPoint
    {     

        DragDrop_Console.RemoteMon Interface;        

        public LocalHook dragDropHook;

        public Main(RemoteHooking.IContext InContext, String InChannelName)
        {
            try
            {
                Interface = RemoteHooking.IpcConnectClient<DragDrop_Console.RemoteMon>(InChannelName);  

                File.AppendAllText(@"F:\DragDropLog.txt", "Main : Channel Name passed" + Environment.NewLine);
            }
            catch (Exception ex)
            {
                Interface.ErrorHandle(ex);

                File.AppendAllText(@"F:\DragDropLog.txt", "Main Exception :"+ ex.ToString() + Environment.NewLine);
            }

        }

        public void Run(RemoteHooking.IContext InContext, String InChannelName)
        {
            try
            {
                dragDropHook = LocalHook.Create(LocalHook.GetProcAddress("Ole32.dll", "DoDragDrop"), new DragDropDelegate(DoDragDropHook), null);


                dragDropHook.ThreadACL.SetInclusiveACL(new Int32[] { 0 });
                //Also tried with setExclusiveACL  
                //dragDropHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 }); 
                File.AppendAllText(@"F:\DragDropLog.txt", "Run : LocalHook Created" + Environment.NewLine);
            }
            catch (Exception ex)
            {
                Interface.ErrorHandle(ex);

                File.AppendAllText(@"F:\DragDropLog.txt", "Run Exception :" + ex.ToString() + Environment.NewLine);

                return;
            }

            Interface.IsInstalled(RemoteHooking.GetCurrentProcessId());

            RemoteHooking.WakeUpProcess();

            while (true)
            {
                Thread.Sleep(1000);                           
            }
        }       

        [DllImport("Ole32.dll",CharSet=CharSet.Unicode,SetLastError =true,CallingConvention =CallingConvention.StdCall)]
        static extern int DoDragDrop(
            IDataObject pDataObj,
            IDropSource pDropSource,
            UInt32 dwOKEffects,
            UInt32[] pdwEffect);

        [UnmanagedFunctionPointer(CallingConvention.StdCall,CharSet =CharSet.Ansi, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.I4)]
        delegate int DragDropDelegate(
            IDataObject pDataObj,
            IDropSource pDropSource,
            UInt32 dwOKEffects,
            UInt32[] pdwEffect);

        static int DoDragDropHook(
            IDataObject pDataObj,
            IDropSource pDropSource,
            UInt32 dwOKEffects,
            UInt32[] pdwEffect)
        {
            try
            {
                ((Main)HookRuntimeInfo.Callback).Interface.GotDragFileObject(pDataObj);

                File.AppendAllText(@"F:\DragDropLog.txt", "DoDragDrop Hit :" + pDataObj.ToString() + Environment.NewLine);

            }
            catch(Exception ex)
            {
                File.AppendAllText(@"F:\DragDropLog.txt", "DoDragDropHook Exception :" + ex.ToString() + Environment.NewLine);
            }

            return DoDragDrop(pDataObj, pDropSource, dwOKEffects, pdwEffect);
        }
    }   

    internal interface IDropSource
    {
    }       

}
Krish
  • 376
  • 3
  • 14

1 Answers1

0

this is a pseudo code:

    private void CanvasLP_Drop(object sender, DragEventArgs e)
    {
       if (e.Handled == false)
        {
          Thumb thumb = (Thumb)e.Data.GetData("Object");
          //thumb is used to store the dropped item, as in my case it is of type Thumb 
          //Object here is the item being dragged
          //You can get file path from file name by using:
          //Path.Combine(Directory.GetCurrentDirectory(), filename)

        }
     }
boop_the_snoot
  • 3,209
  • 4
  • 33
  • 44
  • this event will raise once a file is dropped in to the application right, but this is not am expecting i want know dragsource object before the DragDrop and DragEnter – Krish Jun 29 '17 at 10:42