internal IntPtr addHook(Win32.HookingIDs hID, WinAPI.LowLevelMouseProc callback) { if (ModuleHandle == IntPtr.Zero) { using (var curProcess = Process.GetCurrentProcess()) using (var curModule = curProcess.MainModule) { IntPtr ret = WinAPI.SetWindowsHookEx((int)hID, callback, WinAPI.GetModuleHandle(curModule.ModuleName), 0); HookInfo info = new HookInfo(); info.hookID = ret; info.callback = callback; info.hID = hID; hookIDs.Add(info); return ret; } } else { IntPtr ret = WinAPI.SetWindowsHookEx((int)hID, callback, ModuleHandle, 0); HookInfo info = new HookInfo(); info.hookID = ret; info.callback = callback; info.hID = hID; hookIDs.Add(info); hookIDs.Add(info); return ret; } }
internal HookInfo GetHookInfo(Win32.HookingIDs hID, WinAPI.LowLevelMouseProc callback) { foreach (HookInfo info in hookIDs) { if (info.hID == hID && info.callback == callback) return info; } return HookInfo.Empty; }
internal IntPtr reHook(Win32.HookingIDs hID, WinAPI.LowLevelMouseProc callback) { removeHook(GetHookInfo(hID, callback).hookID); return addHook(hID, callback); }