.net hook

The first question: read some information, not to say that the hook function global hook must write it in DLL, but why not do this can also, I tested, sure. KeyboardHookProc like all the other code in a exe, why to call off the hook function KeyboardHookProc.
  public static int KeyboardHookProc(int nCode, int wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
}
}
       public void HookStart()
        {
            if (hKeyboardHook == 0)
            {
                // Create an instance of HookProc
                KeyboardHookProcedure = new HookProc(KeyboardHookProc);
                hKeyboardHook = SetWindowsHookEx(14, KeyboardHookProcedure, GetModuleHandle(System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName), 0);
                if (hKeyboardHook == 0)
                {
                    HookStop();
                    throw new Exception("SetWindowsHookEx failed.");
                }
            }
        }

The second question hook, why not in the main thread to install the hook has no effect. . . . .
        private void Form1_Load(object sender, EventArgs e)
        {
            Thread th = new Thread(new ThreadStart(() =>
             {
                 Hook hook = new Hook();
                 hook.HookStart();
             }));
             th.Start();
        }

And this is the effect. .
        private void Form1_Load(object sender, EventArgs e)
        {
                 Hook hook = new Hook();
                 hook.HookStart();
        }

Started by Richie at November 13, 2016 - 5:40 PM

Problem a: because you hook type is WH_MOUSE_LL, this is used to monitor the mouse input events at the bottom, a total of the following four types of hooks are not written in DLL: WH_JOURNALPLAYBACK, WH_JOURNALRECORD, WH_KEYBOARD_LL, WH_MOUSE_LL, these hooks are installed on which thread, the hook function is executed in which thread while other types, through the DLL into the target process approach has enabled the callback function can be executed

Question two: does not understand

Posted by Cassie at November 17, 2016 - 6:35 PM