Virtual Developer Workshop: Containerized Development with Docker

Click this link for a Screen Shot.

Environment: MSVC++6.0 SP3, Win98/2000/NT4(SP5)

Code Description


This article features a HowTo to write, set and make use of system wide hooks.


To set system wide hooks, you need to reference a DLL in the SetWindowsHookEx()-command. The demonstrational workspace constists of two separate projects. One builds the DLL with its exported member functions SetHook() and RemoveHook().

Note, that we make use of a memory mapped file to save the instance-, hook- and window-handles which is wrapped in the struct SCGLOBALDATA.

The HookProc()-callback function is called from the system, when keycodes are recieved. We then pass the values in lParam, wParam (virtual keycode and keystroke-message information) via a WM_COPYDATA-message to a controlling (separate) executable that determines by its return value if the hook is to be forwarded through CallNextHookEx().

For additional information, the controlling procedure displays various information on the keystroke it has currently processed. Due to the system wide character of the hook, it even logs keys that are pressed in other applications or a DOS-Prompt.

Member functions:

The DLL exports BOOL SetHook(HWND hWnd) and BOOL RemoveHook() which are pretty self-explaining. You need to pass a valid HWND to SetHook which limits the functionality to window-applications. To bypass this, you can create a dialogbox-based application with an initially hidden window.


Download the precompiled executable to get an idea of what hooks are all about. The complete VC++6.0 workspace contains all necessary sourcecode to build the demo application for you to play around with.

Final word:

I hope, you find the supplied code useful and instructive.
Please feel free to send comments to VolkerBartheld@reetcom.de


HookDemoExe.zip is a compiled executable of the demo application.
HookDemo.zip is a MSVC++ V6 workspace of the demo application.

Download demo project executable HookDemoExe.zip - 19.990 kBytes
Download demo project workspace HookDemo.zip - 18.120 kBytes


  • psapi is part of the platform SDK??

    Posted by Legacy on 09/19/2003 07:00am

    Originally posted by: rich

    I'm sorry to say this~ you said "psapi is part of the platform SDK", but It's not easy to find.
    please, tell me where It is.

  • what is system wide hook?

    Posted by Legacy on 08/17/2003 07:00am

    Originally posted by: ashiq

    what is the purpose of using system wide hook?

  • It's GREAT! Thanks a lot!

    Posted by Legacy on 05/03/2003 07:00am

    Originally posted by: Jasion Wa

    It's GREAT! Thanks a lot!

  • Hook message ....

    Posted by Legacy on 04/06/2003 08:00am

    Originally posted by: anhThuan

    I want to know how to hook message from other computer....
    For example :
    somebody use "net.exe" to send me a short message, so i want to hook this message ....
    goto run command : net send * text here
    teach me...

  • Help ! How can i hook up the printer

    Posted by Legacy on 11/02/2002 08:00am

    Originally posted by: Ashok

    Hai i need a help
    Both WIndows 9x/ME and NT /2000
    I need to hook the printer port i.e. if any application tries to print any job i should catch it and with validation job should enter for printing
    Kindly help me

  • Help! How can I hook Menu Clicks?

    Posted by Legacy on 09/04/2002 07:00am

    Originally posted by: Guru Prasad

    I want to hook a Menu Click when the user clicks on a particular Menu Item. The problem with a WM_MENUSELECT hook is that it traps all events when the user "browses" over a particular menu item (the moment when the text of the Status Bar in a standard Windows application changes to reflect the menu item in focus. Like, you take the cursor over File > New and the Status bar says "Opens a new Document").
    I want to trap the events when the user clicks or otherwises "chooses" a menu item (mapped using ON_COMMAND). In the hook I want the option to discard the Menu Item Click if I want to.
    I tried using the WM_CALLWNDPROC hook which traps the WM_COMMAND message but the documentation in MSDN (Win32 Hooks by Kyle Marsh) says that we shouldn't (and cannot) modify the messages using this hook. Plus this hook is also a drain on the system as it traps most Windows messages.
    As for the details - I am using this hook in an ActiveX control and this hook will be used only on a particular thread (So I don't need a system hook) - if that helps.
    Can someone help me tackle this Menu Click beast?
    Any help will be appreciated.
    Best Regards and thanx in advance,

  • list api

    Posted by Legacy on 03/08/2002 08:00am

    Originally posted by: prabhu


    how can i list the details of the api called by an application. the details including parameters and return values.

  • how can I monitor if a app was started without VXD ?

    Posted by Legacy on 02/06/2002 08:00am

    Originally posted by: Pascut Cristian

    I need to log to a file (eventually to terminate it) every application that is started on a WIN9x, WINME system. CAn you help me here ? It can be done with a hook on WH_SHELL ? If yes, how ?

  • ncode of Call Back doesn't receive values

    Posted by Legacy on 01/17/2002 08:00am

    Originally posted by: Aravindhan

    I am using C++ Builder to create system wide Keyboard hooks
    using the SetWindowsHookEx() command but the ncode parameter of the CALLBACK function does not receive any values.It's value is always equal to 0.

    Please help me.


  • How can interrupts be hooked systemwide

    Posted by Legacy on 01/07/2002 08:00am

    Originally posted by: Daniel Kumar

    How can I hook an Interrupt systemwide? Whenever I hook an
    Interrupt, it is limited to that program only. Is there any
    way for hooking an Interrupt so that once it is hooked, all
    programs should follow the new Interrupt Service Routine?
    Please halp me in this.

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date