CodePlexProject Hosting for Open Source Software
An unexpected error has occured.
There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
Closed
isotoxin wrote Aug 2, 2010 at 8:20 AM
bpell wrote Nov 22, 2010 at 7:01 PM
saamorim wrote Dec 27, 2011 at 9:45 PM
/// Installs the actual unsafe hook /// </summary> private void InstallHook() { /// Error check if (Handle != 0) throw new Exception("Hook is already installed"); #region htype int htype = 0; switch (HookType) { case HookTypes.Mouse: htype = WinApi.WH_MOUSE_LL; break; case HookTypes.Keyboard: htype = WinApi.WH_KEYBOARD_LL; break; default: throw new Exception("HookType is not supported"); } #endregion /// Delegate to recieve message _HookProc = new HookProcCallBack(HookProc); /// Hook _hHook = WinApi.SetWindowsHookEx(htype, _HookProc, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0); _hHook = WinApi.SetWindowsHookEx(htype, _HookProc, GetCurrentModule().BaseAddress, 0); /// Error check if (Handle == 0) throw new Win32Exception(Marshal.GetLastWin32Error()); }
{ // need instance handle to module to create a system-wide hook Module[] list = System.Reflection.Assembly.GetExecutingAssembly().GetModules(); System.Diagnostics.Debug.Assert(list != null && list.Length > 0); var currentProcess = Process.GetCurrentProcess(); var modules = currentProcess.Modules; ProcessModule mod = null; foreach (ProcessModule m in modules) /* //for .net 2 we will find module here if (m.ModuleName == list[0].Name) { mod = m; break; } */ //for .net 4 take current module if (mod == null) mod = Process.GetCurrentProcess().MainModule; return mod; }
adriancs wrote Apr 29, 2012 at 1:21 AM
imranshafqat wrote Aug 29, 2012 at 11:10 AM
adriancs wrote May 16 at 12:19 PM
Sign in to add a comment
Keyboard shortcuts are available for this page.