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

Global Windows Hooks

, 24 Sep 2010
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
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="c:\program files\microsoft visual studio 9.0\team tools\static analysis tools\fxcop\Xml\CodeAnalysisReport.xsl"?>
<FxCopReport Version="1.36">
 <Targets>
  <Target Name="C:\Documents and Settings\HP_Administrator\My Documents\Visual Studio 2008\Projects\C#\Goodies\WindowsHookLib\WindowsHookLib\bin\x86\Release\WindowsHookLib.dll">
   <Modules>
    <Module Name="windowshooklib.dll">
     <Namespaces>
      <Namespace Name="WindowsHookLib">
       <Types>
        <Type Name="ClipboardHook" Kind="Class" Accessibility="Public" ExternallyVisible="True">
         <Members>
          <Member Name="#InstallHook(System.Windows.Forms.Form)" Kind="Method" Static="False" Accessibility="Public" ExternallyVisible="True">
           <Messages>
            <Message TypeName="ConsiderPassingBaseTypesAsParameters" Category="Microsoft.Design" CheckId="CA1011" Status="Active" Created="2010-09-23 22:48:37Z" FixCategory="Breaking">
             <Issue Certainty="50" Level="Error" Path="C:\Documents and Settings\HP_Administrator\My Documents\Visual Studio 2008\Projects\C#\Goodies\WindowsHookLib\WindowsHookLib" File="ClipboardHook.cs" Line="105">Consider changing the type of parameter 'window' in 'ClipboardHook.InstallHook(Form)' from 'Form' to its base type 'Control'. This method appears to only require base class members in its implementation. Suppress this violation if there is a compelling reason to require the more derived type in the method signature.</Issue>
            </Message>
           </Messages>
          </Member>
         </Members>
        </Type>
        <Type Name="ClipboardHook+ClipboardPorc" Kind="Class" Accessibility="Private" ExternallyVisible="False">
         <Members>
          <Member Name="#NextWindow" Kind="Property" Static="False" Accessibility="Public" ExternallyVisible="False">
           <Accessors>
            <Accessor Name="#set_NextWindow(System.IntPtr)" Kind="Method" Static="False" Accessibility="Public" ExternallyVisible="False">
             <Messages>
              <Message TypeName="AvoidUncalledPrivateCode" Category="Microsoft.Performance" CheckId="CA1811" Status="Active" Created="2010-09-23 22:48:37Z" FixCategory="NonBreaking">
               <Issue Certainty="75" Level="Warning" Path="C:\Documents and Settings\HP_Administrator\My Documents\Visual Studio 2008\Projects\C#\Goodies\WindowsHookLib\WindowsHookLib" File="ClipboardHook.cs" Line="264">'ClipboardHook.ClipboardPorc.NextWindow.set(IntPtr)' appears to have no upstream public or protected callers.</Issue>
              </Message>
             </Messages>
            </Accessor>
           </Accessors>
          </Member>
         </Members>
        </Type>
        <Type Name="KeyboardHook" Kind="Class" Accessibility="Public" ExternallyVisible="True">
         <Members>
          <Member Name="#_hKeyboardHook" Kind="Field" Static="False" Accessibility="Private" ExternallyVisible="False">
           <Messages>
            <Message TypeName="UseSafeHandleToEncapsulateNativeResources" Category="Microsoft.Reliability" CheckId="CA2006" Status="Active" Created="2010-09-23 22:48:37Z" FixCategory="NonBreaking">
             <Issue Certainty="75" Level="CriticalWarning">Review usage of 'KeyboardHook._hKeyboardHook' (a 'IntPtr' instance) to determine whether it should be replaced with a SafeHandle or CriticalHandle.</Issue>
            </Message>
           </Messages>
          </Member>
         </Members>
        </Type>
        <Type Name="MouseHook" Kind="Class" Accessibility="Public" ExternallyVisible="True">
         <Members>
          <Member Name="#_cHandle" Kind="Field" Static="False" Accessibility="Private" ExternallyVisible="False">
           <Messages>
            <Message TypeName="UseSafeHandleToEncapsulateNativeResources" Category="Microsoft.Reliability" CheckId="CA2006" Status="Active" Created="2010-09-23 22:48:37Z" FixCategory="NonBreaking">
             <Issue Certainty="75" Level="CriticalWarning">Review usage of 'MouseHook._cHandle' (a 'IntPtr' instance) to determine whether it should be replaced with a SafeHandle or CriticalHandle.</Issue>
            </Message>
           </Messages>
          </Member>
          <Member Name="#_hMouseHook" Kind="Field" Static="False" Accessibility="Private" ExternallyVisible="False">
           <Messages>
            <Message TypeName="UseSafeHandleToEncapsulateNativeResources" Category="Microsoft.Reliability" CheckId="CA2006" Status="Active" Created="2010-09-23 22:48:37Z" FixCategory="NonBreaking">
             <Issue Certainty="75" Level="CriticalWarning">Review usage of 'MouseHook._hMouseHook' (a 'IntPtr' instance) to determine whether it should be replaced with a SafeHandle or CriticalHandle.</Issue>
            </Message>
           </Messages>
          </Member>
         </Members>
        </Type>
        <Type Name="UnsafeNativeMethods" Kind="Class" Accessibility="Assembly" ExternallyVisible="False">
         <Members>
          <Member Name="#GetLastError()" Kind="Method" Static="True" Accessibility="Public" ExternallyVisible="False">
           <Messages>
            <Message TypeName="UseManagedEquivalentsOfWin32Api" Category="Microsoft.Usage" CheckId="CA2205" Status="Active" Created="2010-09-23 22:48:37Z" FixCategory="NonBreaking">
             <Issue Name="PlatformInvokeDeclaration" Certainty="50" Level="Error">Remove the declaration for 'UnsafeNativeMethods.GetLastError()'. Callers should use the following managed alternative: Runtime.InteropServices.Marshall.GetLastWin32Error</Issue>
            </Message>
           </Messages>
          </Member>
          <Member Name="#WindowFromPoint(System.Drawing.Point)" Kind="Method" Static="True" Accessibility="Public" ExternallyVisible="False">
           <Messages>
            <Message Id="0" TypeName="PInvokeDeclarationsShouldBePortable" Category="Microsoft.Portability" CheckId="CA1901" Status="Active" Created="2010-09-23 22:48:37Z" FixCategory="NonBreaking">
             <Issue Name="Parameter" Certainty="95" Level="Error">As it is declared in your code, parameter 'pt' of P/Invoke 'UnsafeNativeMethods.WindowFromPoint(Point)' will be 8 bytes wide on 32-bit platforms. This is not correct, as the actual native declaration of this API indicates it should be 4 bytes wide on 32-bit platforms. Consult the MSDN Platform SDK documentation for help determining what data type should be used instead of 'Point'.</Issue>
            </Message>
           </Messages>
          </Member>
         </Members>
        </Type>
       </Types>
      </Namespace>
     </Namespaces>
    </Module>
   </Modules>
  </Target>
 </Targets>
 <Rules>
  <Rule TypeName="AvoidUncalledPrivateCode" Category="Microsoft.Performance" CheckId="CA1811">
   <Name>Avoid uncalled private code</Name>
   <Description>There is uncalled code that is not externally visible and is not a known runtime entry point. If this violation fires in error, please send a problem report to the Visual Studio Code Analysis team.</Description>
   <Resolution Name="Default">{0} appears to have no upstream public or protected callers.</Resolution>
   <Owner />
   <Url>http://msdn2.microsoft.com/library/ms182264(VS.90).aspx</Url>
   <Email>[none]</Email>
   <MessageLevel Certainty="75">Warning</MessageLevel>
   <File Name="PerformanceRules.dll" Version="9.0.0.0" />
  </Rule>
  <Rule TypeName="ConsiderPassingBaseTypesAsParameters" Category="Microsoft.Design" CheckId="CA1011">
   <Name>Consider passing base types as parameters</Name>
   <Description>Using base types as parameters to methods improves re-use of these methods if you only use methods &amp; properties from the parameter's base class. E.g. use Stream instead of FileStream as a parameter when only calling Stream.Read(), this makes the method work on all kind of streams instead of just File streams.</Description>
   <Resolution Name="Default">Consider changing the type of parameter {0} in {1} from {2} to its base type {3}. This method appears to only require base class members in its implementation. Suppress this violation if there is a compelling reason to require the more derived type in the method signature.</Resolution>
   <Owner />
   <Url>http://msdn2.microsoft.com/library/3hk32yyz(VS.90).aspx</Url>
   <Email>[none]</Email>
   <MessageLevel Certainty="50">Error</MessageLevel>
   <File Name="DesignRules.dll" Version="9.0.0.0" />
  </Rule>
  <Rule TypeName="PInvokeDeclarationsShouldBePortable" Category="Microsoft.Portability" CheckId="CA1901">
   <Name>P/Invoke declarations should be portable</Name>
   <Description>.</Description>
   <Resolution Name="Parameter">As it is declared in your code, parameter {0} of P/Invoke {1} will be {2} bytes wide on {3} platforms. This is not correct, as the actual native declaration of this API indicates it should be {4} bytes wide on {3} platforms. Consult the MSDN Platform SDK documentation for help determining what data type should be used instead of {5}.</Resolution>
   <Owner />
   <Url>http://msdn2.microsoft.com/library/ms182284(VS.90).aspx</Url>
   <Email>[none]</Email>
   <MessageLevel Certainty="95">Error</MessageLevel>
   <File Name="PortabilityRules.dll" Version="9.0.0.0" />
  </Rule>
  <Rule TypeName="UseManagedEquivalentsOfWin32Api" Category="Microsoft.Usage" CheckId="CA2205">
   <Name>Use managed equivalents of Win32 API</Name>
   <Description>Use managed equivalents to Win32 API whenever possible.</Description>
   <Resolution Name="PlatformInvokeDeclaration">Remove the declaration for {0}. Callers should use the following managed alternative: {1}</Resolution>
   <Owner />
   <Url>http://msdn2.microsoft.com/library/ms182365(VS.90).aspx</Url>
   <Email>[none]</Email>
   <MessageLevel Certainty="50">Error</MessageLevel>
   <File Name="UsageRules.dll" Version="9.0.0.0" />
  </Rule>
  <Rule TypeName="UseSafeHandleToEncapsulateNativeResources" Category="Microsoft.Reliability" CheckId="CA2006">
   <Name>Use SafeHandle to encapsulate native resources</Name>
   <Description>Use of IntPtr in managed code may indicate a potential security and reliability problem. All uses of IntPtr must be reviewed to determine whether use of a SafeHandle (or similar technology) is required in its place. Problems will occur if the IntPtr represents some native resource (memory, file handle, socket etc.) that managed code is considered to own. I.e. managed code is expected to in some way release the resource and failure to do so would cause resource leakage. In such scenarios security or reliability problems will also exist if multithreaded access is allowed to the IntPtr and a means of releasing the resource represented by the IntPtr. These problems involve recycling of the IntPtr value on resource release while simultaneous use of the resource is being made on another thread, leading to race conditions where one thread can read or write data associated with the wrong resource. For example, if your type stores an OS handle as an IntPtr and allows users to call both Close and any other method using that handle simultaneously (without some kind of synchronization), your code has a handle recycling problem, which causes data corruption and often a security vulnerability. SafeHandle (and its sibling class CriticalHandle) provide a mechanism for encapsulating a native handle to a resource so that such threading problems can be avoided (along with other issues such as the need to carefully control the lifetime of managed objects that contain a copy of the native handle over calls to native methods; ie, you can often remove calls to GC.KeepAlive). There are performance overheads implicit in using SafeHandle (and, to a lesser degree, CriticalHandle) which can often be mitigated through careful design.</Description>
   <Resolution Name="Default">Review usage of {0} (a {1} instance) to determine whether it should be replaced with a SafeHandle or CriticalHandle.</Resolution>
   <Owner />
   <Url>http://msdn2.microsoft.com/library/ms182294(VS.90).aspx</Url>
   <Email>[none]</Email>
   <MessageLevel Certainty="75">CriticalWarning</MessageLevel>
   <File Name="ReliabilityRules.dll" Version="9.0.0.0" />
  </Rule>
 </Rules>
 <Localized>
  <String Key="Category">Category</String>
  <String Key="Certainty">Certainty</String>
  <String Key="CollapseAll">Collapse All</String>
  <String Key="CheckId">Check Id</String>
  <String Key="Error">Error</String>
  <String Key="Errors">error(s)</String>
  <String Key="ExpandAll">Expand All</String>
  <String Key="Help">Help</String>
  <String Key="Line">Line</String>
  <String Key="Messages">message(s)</String>
  <String Key="LocationNotStoredInPdb">[Location not stored in Pdb]</String>
  <String Key="Project">Project</String>
  <String Key="Resolution">Resolution</String>
  <String Key="Rule">Rule</String>
  <String Key="RuleFile">Rule File</String>
  <String Key="RuleDescription">Rule Description</String>
  <String Key="Source">Source</String>
  <String Key="Status">Status</String>
  <String Key="Target">Target</String>
  <String Key="Warning">Warning</String>
  <String Key="Warnings">warning(s)</String>
  <String Key="ReportTitle">Code Analysis Report</String>
 </Localized>
</FxCopReport>

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 | Mobile
Web02 | 2.8.140926.1 | Last Updated 24 Sep 2010
Article Copyright 2007 by VBDT
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid