Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Global Windows Hooks

, 24 Sep 2010 CPOL
A single component that contains various Windows hooks
Library_Files.zip
Library Files
WindowsHookLib.dll
Source_Code_and_Demo.zip
Source Code and Demo
WindowsHookDemo
WindowsHookDemo.suo
WindowsHookDemo
bin
Debug
WindowsHookDemo.exe
WindowsHookDemo.vshost.exe
WindowsHookLib.dll
Release
My Project
Application.myapp
Settings.settings
WindowsHookDemo.vbproj.user
WindowsHookLib
WindowsHookLib.suo
WindowsHookLib
bin
Release
x86
Release
WindowsHookLib.dll
WindowsHookLib.dll.lastcodeanalysissucceeded
WindowsHookLib.pdb
Properties
Resources
clipboard.ico
keyboard.ico
mouse.ico
Thumbs.db
WindowsHookLib_Component.zip
WindowsHookLib Component
WindowsHookLib.dll
using System;
using System.Runtime.Serialization;
using System.Diagnostics;
using System.Globalization;
using System.Security.Permissions;

namespace WindowsHookLib
{
    /// <summary>
    /// Represents errors that occur in WindowsHookLib.ClipboardHook, 
    /// WindowsHookLib.MouseHook and WindowsHookLib.KeyboardHook.
    /// </summary>
    [Serializable]
    [DebuggerNonUserCode]
    public class WindowsHookException : ArgumentException
    {
        #region ' Members '

        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        private object _actualValue = null;
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        private const string DEFAULT_MESSAGE = "Exception of type 'WindowsHookLib.WindowsHookException' was thrown.";

        #endregion

        #region ' Properties '

        /// <summary>
        /// Gets the actural value of the parameter that causes this exception.
        /// </summary>
        public object ActualValue
        {
            get
            {
                return this._actualValue;
            }
        }

        /// <summary>
        /// Gets the error message of the exception.
        /// </summary>
        public override string Message
        {
            get
            {
                string message = base.Message;
                if (this._actualValue == null)
                {
                    return message;
                }
                string value = "Actual value was " + this._actualValue.ToString() + ".";
                if (string.IsNullOrEmpty(message))
                {
                    return value;
                }
                return (message + Environment.NewLine + value);
            }
        }

        #endregion

        #region ' Methods '

        /// <summary>
        /// Default constructor.
        /// </summary>
        public WindowsHookException()
            : base(DEFAULT_MESSAGE) { }

        /// <param name="message">The exception message.</param>
        public WindowsHookException(string message)
            : base(message = (string.IsNullOrEmpty(message) ? DEFAULT_MESSAGE : message)) { }

        /// <param name="message">The exception message.</param>
        /// <param name="innerException">The inner exception.</param>
        public WindowsHookException(string message, Exception innerException)
            : base(message = (string.IsNullOrEmpty(message) ? DEFAULT_MESSAGE : message), innerException) { }

        /// <param name="message">The exception message.</param>
        /// <param name="parameterName">The invalid parameter name.</param>
        public WindowsHookException(string message, string parameterName)
            : base(message = (string.IsNullOrEmpty(message) ? DEFAULT_MESSAGE : message), parameterName) { }

        /// <param name="message">The exception message.</param>
        /// <param name="parameterName">The invalid parameter name.</param>
        /// <param name="actualValue">The parameter value.</param>
        public WindowsHookException(string message, string parameterName, object actualValue)
            : base(message = (string.IsNullOrEmpty(message) ? DEFAULT_MESSAGE : message), parameterName)
        {
            this._actualValue = actualValue;
        }

        /// <param name="info">The serialization information.</param>
        /// <param name="context"></param>
        protected WindowsHookException(SerializationInfo info, StreamingContext context)
            : base(info, context) { }

        /// <summary>
        /// Sets the System.Runtime.Serialization.SerializationInfo object 
        /// with the parameter name, actual value and additional exception information.
        /// </summary>
        /// <param name="info">The object that holds the serialized object data.</param>
        /// <param name="context">The contextual information about the source or destination.</param>
        [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            base.GetObjectData(info, context);
            info.AddValue("ActualValue", this._actualValue, typeof(object));
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

VBDT
Software Developer (Senior) ZipEdTech
United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 24 Sep 2010
Article Copyright 2007 by VBDT
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid