Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7976909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:02:32+00:00 2026-06-04T09:02:32+00:00

HHOOK WINAPI SetWindowsHookEx( __in int idHook, __in HOOKPROC lpfn, __in HINSTANCE hMod, __in DWORD

  • 0
HHOOK WINAPI SetWindowsHookEx(
 __in  int idHook,
 __in  HOOKPROC lpfn,
 __in  HINSTANCE hMod,
 __in  DWORD dwThreadId
);

In this as the doc says lpfn is a pointer to the hook procedure. Let the hook procedure be :

keyboardProcessing(.....) {
}

How do i call this hook procedure ? Even if i call this hook procedure how am i going to receive the keystrokes ?

Please explain how does SetWindowsHookEx function and how does it call the actual programmer-defined hook method to handle keys ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:02:33+00:00Added an answer on June 4, 2026 at 9:02 am

    The SetWindowsHookEx function is used to register a custom handler for some Windows events. From MSDN:

    Installs an application-defined hook procedure into a hook chain. You would install a hook procedure to monitor the system for certain types of events. These events are associated either with a specific thread or with all threads in the same desktop as the calling thread.

    It means that, for a selected hook type (keyboard events, for example) Windows will call the supplied procedure (lpfn) to notify that an event of that type occured. You can use it, for example, to get all the events from the keyboard even when they’re not directed to your application window (imagine to write a macro recorder).

    How do i call this hook procedure?

    You do not have to call that procedure, you’ll supply its address in the call to SetWindowsHookEx and then Windows will call it for you when needed.

    Even if i call this hook procedure how am i going to receive the keystrokes?

    As said you do not have to call it, if you register a hook for WH_KEYBOARD then Windows will call that procedure for each keyboard event. Do not forget to call CallNextHookEx
    inside your procedure, hook is a chain of procedures and each one is responsible to call the next procedure in the chain. Finally release the hook before you quit your application with UnhookWindowsHookEx.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm calling the HtmlHelpA winapi method to display the .chm of my app. This
I'd like to hook this so I remember to remove it if I don't
I am trying to set a global GetMessage hook on all threads. This is
I just wonder... I mainly use .NET but now I started to investigate WINAPI
#include <windows.h> #include <process.h> HWND MainHwnd; HHOOK MouseHook; LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM
I'm trying to capture global mouse and keyboard input. LRESULT CALLBACK MouseHookProc(int nCode, WPARAM
I am using SetWindowsHookEx() to create a keyboard hook. The creation seems to be
Referring to the Netfilter hook code at this page The port to be checked
I would like to hook into this question, however perhaps rephrase it from a
I would like to add a hook to an application. I am using SetWindowsHookEx

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.