EasyHook太不Easy了,想实现一个很Easy的功能,一直没弄出来。
需求很简单,只需要LocalHook,不需要全局Hook,能在C#WinForm中Hook住本进程的MessageBoxW就可以了。初学不太懂,高人们给点提示吧?
我的代码如下,运行后没有任何反应:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Diagnostics; using Microsoft.Win32; using System.Runtime.InteropServices; using EasyHook; namespace WindowsFormsApplication1 { public partial class Form1 : Form,IEntryPoint { delegate IntPtr MessageBoxWCallback(int hwnd, IntPtr lpText, IntPtr lpCaption, int wType); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { var MyHook = LocalHook.Create(LocalHook.GetProcAddress("user32.dll", "MessageBoxW"), new MessageBoxWCallback(MessageBoxWProc), this); MyHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 }); } static IntPtr MessageBoxWProc(int hwnd, IntPtr lpText, IntPtr lpCaption, int wType) { return new IntPtr(0); } private void button2_Click(object sender, EventArgs e) { MessageBox.Show("ok"); } } }
MyHook.ThreadACL.SetInclusiveACL(new Int32[] { 0 });