Hey,
I'm trying to set up a hook with the Managed Windows API (http://mwinapi.sourceforge.net/); however, whenever I do, everything crashes, and I get an error message (0x0000000) for every program, which states that the memory could not be read or written to. It forces me to restart my computer (which my program is not designed to do :P).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ManagedWinapi;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
ManagedWinapi.Hooks.Hook hook
= new ManagedWinapi.Hooks.Hook(
ManagedWinapi.Hooks.HookType.WH_CALLWNDPROC,
true,
true);
public Form1()
{
InitializeComponent();
hook.Callback +=new ManagedWinapi.Hooks.Hook.HookCallback(hook_Callback);
try
{
hook.StartHook();
}
catch (Exception) { }
}
private int hook_Callback(int code, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (code >= 0)
this.Text = wParam.ToString();
return code;
}
}
}
Here is the code I'm using. Any help will be very appreciated. Thanks.