You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 8 месеци
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // This code is distributed under MIT license.
  2. // Copyright (c) 2015 George Mamaladze
  3. // See license.txt or https://mit-license.org/
  4. using System;
  5. using System.Runtime.InteropServices;
  6. namespace Gma.System.MouseKeyHook.WinApi
  7. {
  8. internal static class HookNativeMethods
  9. {
  10. /// <summary>
  11. /// The CallNextHookEx function passes the hook information to the next hook procedure in the current hook chain.
  12. /// A hook procedure can call this function either before or after processing the hook information.
  13. /// </summary>
  14. /// <param name="idHook">This parameter is ignored.</param>
  15. /// <param name="nCode">[in] Specifies the hook code passed to the current hook procedure.</param>
  16. /// <param name="wParam">[in] Specifies the wParam value passed to the current hook procedure.</param>
  17. /// <param name="lParam">[in] Specifies the lParam value passed to the current hook procedure.</param>
  18. /// <returns>This value is returned by the next hook procedure in the chain.</returns>
  19. /// <remarks>
  20. /// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp
  21. /// </remarks>
  22. [DllImport("user32.dll", CharSet = CharSet.Auto,
  23. CallingConvention = CallingConvention.StdCall)]
  24. internal static extern IntPtr CallNextHookEx(
  25. IntPtr idHook,
  26. int nCode,
  27. IntPtr wParam,
  28. IntPtr lParam);
  29. /// <summary>
  30. /// The SetWindowsHookEx function installs an application-defined hook procedure into a hook chain.
  31. /// You would install a hook procedure to monitor the system for certain types of events. These events
  32. /// are associated either with a specific thread or with all threads in the same desktop as the calling thread.
  33. /// </summary>
  34. /// <param name="idHook">
  35. /// [in] Specifies the type of hook procedure to be installed. This parameter can be one of the following values.
  36. /// </param>
  37. /// <param name="lpfn">
  38. /// [in] Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a
  39. /// thread created by a different process, the lpfn parameter must point to a hook procedure in a dynamic-link
  40. /// library (DLL). Otherwise, lpfn can point to a hook procedure in the code associated with the current process.
  41. /// </param>
  42. /// <param name="hMod">
  43. /// [in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter.
  44. /// The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by
  45. /// the current process and if the hook procedure is within the code associated with the current process.
  46. /// </param>
  47. /// <param name="dwThreadId">
  48. /// [in] Specifies the identifier of the thread with which the hook procedure is to be associated.
  49. /// If this parameter is zero, the hook procedure is associated with all existing threads running in the
  50. /// same desktop as the calling thread.
  51. /// </param>
  52. /// <returns>
  53. /// If the function succeeds, the return value is the handle to the hook procedure.
  54. /// If the function fails, the return value is NULL. To get extended error information, call GetLastError.
  55. /// </returns>
  56. /// <remarks>
  57. /// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp
  58. /// </remarks>
  59. [DllImport("user32.dll", CharSet = CharSet.Auto,
  60. CallingConvention = CallingConvention.StdCall, SetLastError = true)]
  61. internal static extern HookProcedureHandle SetWindowsHookEx(
  62. int idHook,
  63. HookProcedure lpfn,
  64. IntPtr hMod,
  65. int dwThreadId);
  66. /// <summary>
  67. /// The UnhookWindowsHookEx function removes a hook procedure installed in a hook chain by the SetWindowsHookEx
  68. /// function.
  69. /// </summary>
  70. /// <param name="idHook">
  71. /// [in] Handle to the hook to be removed. This parameter is a hook handle obtained by a previous call to
  72. /// SetWindowsHookEx.
  73. /// </param>
  74. /// <returns>
  75. /// If the function succeeds, the return value is nonzero.
  76. /// If the function fails, the return value is zero. To get extended error information, call GetLastError.
  77. /// </returns>
  78. /// <remarks>
  79. /// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp
  80. /// </remarks>
  81. [DllImport("user32.dll", CharSet = CharSet.Auto,
  82. CallingConvention = CallingConvention.StdCall, SetLastError = true)]
  83. internal static extern int UnhookWindowsHookEx(IntPtr idHook);
  84. }
  85. }