Desktop Functions: Smart Device Functions:
|
SetWindowsHookEx (user32)
@msdn=http://search.microsoft.com/search/results.aspx?qu=$$$ C# Signature:
[DllImport("user32.dll")] VB Signature:
<DllImport("user32.dll")> _ User-Defined Types:A HookType constant specifying the type of hook to install. A HookProc delegate representing the hook procedure method. Notes:This will enable you to install application hooks. However, you cannot implement global hooks in Microsoft .NET Framework. To install a global hook, a hook must have a native dynamic-link library (DLL) export to inject itself in another process that requires a valid, consistent function to call into. This requires a DLL export, which .NET Framework does not support. Managed code has no concept of a consistent value for a function pointer because these function pointers are proxies that are built dynamically. Tips & Tricks:Remember to keep the HookProc delegate alive manually, otherwise the garbage collector will clean up your hook delegate eventually, resulting in your code throwing a System.NullReferenceException. Sample Code:
// this sample installs a keyboard hook
using System.Windows.Forms;
// setup a keyboard hook
[DllImport("user32.dll")]
private void MyCallbackFunction(int code, IntPtr wParam, IntPtr lParam) Alternative Managed API:Do you know one? Please contribute it! Please edit this page!Do you have...
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more). |
|