選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

31 行
837 B

  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.Windows.Forms;
  5. using Microsoft.Win32.SafeHandles;
  6. namespace Gma.System.MouseKeyHook.WinApi
  7. {
  8. internal class HookProcedureHandle : SafeHandleZeroOrMinusOneIsInvalid
  9. {
  10. private static bool _closing;
  11. static HookProcedureHandle()
  12. {
  13. Application.ApplicationExit += (sender, e) => { _closing = true; };
  14. }
  15. public HookProcedureHandle()
  16. : base(true)
  17. {
  18. }
  19. protected override bool ReleaseHandle()
  20. {
  21. //NOTE Calling Unhook during processexit causes deley
  22. if (_closing) return true;
  23. return HookNativeMethods.UnhookWindowsHookEx(handle) != 0;
  24. }
  25. }
  26. }