Click here to Skip to main content
12,299,012 members (46,920 online)
Click here to Skip to main content

Stats

228.1K views
7.6K downloads
219 bookmarked
Posted

Global Windows Hooks

, 24 Sep 2010 CPOL
A single component that contains various Windows hooks
Library Files
WindowsHookLib.dll
Source Code and Demo
WindowsHookDemo
WindowsHookDemo.suo
WindowsHookDemo
bin
Debug
WindowsHookDemo.exe
WindowsHookDemo.vshost.exe
WindowsHookLib.dll
Release
My Project
Application.myapp
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
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

Arman Ghazanchyan
Software Developer (Senior) ZipEdTech
United States United States
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 24 Sep 2010
Article Copyright 2007 by Arman Ghazanchyan
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid