Windows API

Howdy folks!
I'm trying to learn more about calling Windows API through .NET.  Does any of you know of a website I could learn more about it   
I'm really searching for a list of all the DLL's I could use...
Like, how to capture key events, but not limited to just one app.  You know, have it do things when certain keys are pressed, even when the app doesn't have the focus.
   - did that make sense  :S

Anyway. if any of you know of a good site, please post!
Thanks!!


Answer this question

Windows API

  • Shawn Bankert

    What you've described is a Windows Hook.  
    http://support.microsoft.com/default.aspx scid=kb;EN-US;Q318804#3

    Unfortunately it wont work in .Net:

    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.

    You'll have to do this in unmanaged code - the best place to start is here:

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Hooks/HookReference/HookFunctions/SetWindowsHookEx.asp

    Hooks are generally a last resort for UI though; I am sure you'd be suprised if your app started behaving the way you described above.  ;-)

    Hope this helps -
    Jessica

  • Windows API