Beispiel #1
0
        //--------

        static void TestApiHook()
        {
            IntPtr user32dll, msgBoxOrigProc;

            user32dll      = cHook.GetModuleBaseAddress("user32.dll");
            msgBoxOrigProc = cHook.GetProcedureAddress(user32dll, "MessageBoxW");
            if (msgBoxOrigProc == IntPtr.Zero)
            {
                MessageBox.Show("Error: Cannot Cannot get address of MessageBoxW", "HookTest", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            object o = cHook.Hook(msgBoxOrigProc, Marshal.GetFunctionPointerForDelegate(new delegMessageBoxApi(Hooked_MessageBoxApi)));

            MessageBox.Show("Win32 Api Hook\r\rThis should be hooked", "HookTest", MessageBoxButtons.OK);
            cHook.Unhook(o);

            MessageBox.Show("Win32 Api Hook\r\rThis should NOT be hooked", "HookTest", MessageBoxButtons.OK);
        }