SetWinEventHook (user32)
Last changed: -38.94.164.162

.
Summary

C# Signature:

[DllImport("user32.dll")]
static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr
   hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess,
   uint idThread, uint dwFlags);

VB Signature:

    <System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint:="SetWinEventHook")> _
    Private Shared Function SetWinEventHook( _
        ByVal eventMin As UInteger, _
        ByVal eventMax As UInteger, _
        ByVal hmodWinEventProc As IntPtr, _
        ByVal lpfnWinEventProc As WinEventDelegate, _
        ByVal idProcess As UInteger, _
        ByVal idThread As UInteger, _
        ByVal dwFlags As UInteger _
    ) As IntPtr
    End Function

User-Defined Types:

WinEventDelegate

Notes:

The MSDN documentation states:

When you use a Win32 API that has a callback in managed code, such as SetWinEventHook, you should use GCHandle class structure to avoid exceptions.

This is apparently not accurate as the P/Invoke layer automatically generates a marshaling stub at a fixed address:

http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx

Tips & Tricks:

Please add some!

Sample Code:

Please add some!

Alternative Managed API:

The ManagedWindowsApi project (http://mwinapi.sourceforge.net) provides a SystemAccessibleObject class to access accessible objects and handle accessible events.

Documentation