Ejemplo n.º 1
0
 public void InstallHook(Form window)
 {
     if (this.State == HookState.Uninstalled)
     {
         if (window != null)
         {
             NativeExports.SetLastError(0);
             IntPtr nextWindow = NativeExports.SetClipboardViewer(window.Handle);
             if (nextWindow == IntPtr.Zero)
             {
                 var errorCode = NativeExports.GetLastError();
                 if (errorCode == 0)
                 {
                     OnSuccessfullHook(window.Handle, nextWindow);
                 }
                 else
                 {
                     var message = ErrorCodeHelper.GetMessage(errorCode);
                     throw new Exception(message);
                 }
             }
             else
             {
                 OnSuccessfullHook(window.Handle, nextWindow);
             }
         }
     }
 }
Ejemplo n.º 2
0
 public void RemoveHook()
 {
     if (this.State == HookState.Installed)
     {
         NativeExports.SetLastError(0);
         NativeExports.ChangeClipboardChain(this.clipboard.Handle, this.clipboard.NextWindow);
         var errorCode = NativeExports.GetLastError();
         if (errorCode == 0)
         {
             this.OnSuccessfullUnhook();
         }
         else
         {
             var message = ErrorCodeHelper.GetMessage(errorCode);
             throw new Exception(message);
         }
     }
 }