// This code is distributed under MIT license. // Copyright (c) 2015 George Mamaladze // See license.txt or https://mit-license.org/ using System; using System.Runtime.InteropServices; namespace Gma.System.MouseKeyHook.WinApi { internal static class HookNativeMethods { /// /// The CallNextHookEx function passes the hook information to the next hook procedure in the current hook chain. /// A hook procedure can call this function either before or after processing the hook information. /// /// This parameter is ignored. /// [in] Specifies the hook code passed to the current hook procedure. /// [in] Specifies the wParam value passed to the current hook procedure. /// [in] Specifies the lParam value passed to the current hook procedure. /// This value is returned by the next hook procedure in the chain. /// /// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp /// [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] internal static extern IntPtr CallNextHookEx( IntPtr idHook, int nCode, IntPtr wParam, IntPtr lParam); /// /// The SetWindowsHookEx function installs an application-defined hook procedure into a hook chain. /// You would install a hook procedure to monitor the system for certain types of events. These events /// are associated either with a specific thread or with all threads in the same desktop as the calling thread. /// /// /// [in] Specifies the type of hook procedure to be installed. This parameter can be one of the following values. /// /// /// [in] Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a /// thread created by a different process, the lpfn parameter must point to a hook procedure in a dynamic-link /// library (DLL). Otherwise, lpfn can point to a hook procedure in the code associated with the current process. /// /// /// [in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. /// The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by /// the current process and if the hook procedure is within the code associated with the current process. /// /// /// [in] Specifies the identifier of the thread with which the hook procedure is to be associated. /// If this parameter is zero, the hook procedure is associated with all existing threads running in the /// same desktop as the calling thread. /// /// /// If the function succeeds, the return value is the handle to the hook procedure. /// If the function fails, the return value is NULL. To get extended error information, call GetLastError. /// /// /// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp /// [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)] internal static extern HookProcedureHandle SetWindowsHookEx( int idHook, HookProcedure lpfn, IntPtr hMod, int dwThreadId); /// /// The UnhookWindowsHookEx function removes a hook procedure installed in a hook chain by the SetWindowsHookEx /// function. /// /// /// [in] Handle to the hook to be removed. This parameter is a hook handle obtained by a previous call to /// SetWindowsHookEx. /// /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero. To get extended error information, call GetLastError. /// /// /// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp /// [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)] internal static extern int UnhookWindowsHookEx(IntPtr idHook); } }