public GlobalHookBase(GlobalHookTypes Type, bool OnThread) { this.HookType = Type; del = ProcessMessage; if (OnThread) { hook = NativeMethod.SetWindowsHookEx(Type, del, IntPtr.Zero, NativeMethod.GetCurrentThreadId()); } else { var hmod = IntPtr.Zero; // Marshal.GetHINSTANCE(GetType().Module); hook = NativeMethod.SetWindowsHookEx(Type, del, hmod, IntPtr.Zero); } if (hook == IntPtr.Zero) { int err = Marshal.GetLastWin32Error(); string msg = err.GetErrorMessage(); if (err != 0) { throw new Exception("Hookに失敗しました : " + msg); } } }
/*public WMSG(GlobalHookTypes Type):this(Type,false) * { * }*/ public WMSG(GlobalHookTypes Type, bool OnThread, IntPtr handle) { this.HookType = Type; this.HookId = (int)Type; del = ProcessMessage; if (OnThread) { hook = SetWindowsHookEx(HookId, del, IntPtr.Zero, handle);//GetCurrentThreadId() } else { var hmod = IntPtr.Zero; // Marshal.GetHINSTANCE(GetType().Module); hook = SetWindowsHookEx(HookId, del, hmod, IntPtr.Zero); } if (hook == IntPtr.Zero) { int err = Marshal.GetLastWin32Error(); if (err != 0) { OnHookFailed(err); } } }
public GlobalHookBase(GlobalHookTypes Type) : this(Type, false) { }
public GlobalHookTrapper(GlobalHookTypes Type) : this(Type, false) { }
public static extern IntPtr SetWindowsHookEx(GlobalHookTypes idHook, MessageDelegate lpfn, IntPtr hmod, IntPtr dwThreadId);
public static extern IntPtr SetWindowsHookEx(GlobalHookTypes hookType, KeyboardHookDelegate hookDelegate, IntPtr hInstance, uint threadId);