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

  • Home
  • SEARCH
  • 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 66479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:06:35+00:00 2026-05-10T19:06:35+00:00

I can correctly setup up a windows hook, but I get confused by the

  • 0

I can correctly setup up a windows hook, but I get confused by the line in MSDN that says ‘Calling the CallNextHookEx function to chain to the next hook procedure is optional, but it is highly recommended; otherwise, other applications that have installed hooks will not receive hook notifications and may behave incorrectly as a result. You should call CallNextHookEx unless you absolutely need to prevent the notification from being seen by other applications.’.

I want to be a good programming citizen and call the next hook. But, my hook procedure looks like this:

LRESULT CALLBACK CBTProc(int code, WPARAM wp, LPARAM lp) {     if (code != HCBT_CREATEWND)         {                 // What do I do here? It's not the event I requested so how do I pass it on?         return 0;     }      // It's the code we want (create window)         CallNextHookEx(...);         ... } 

So, what happens in the hook procedure if the code isn’t the one I’m interested in? How do I call the next hook?

Edit: The main problem is that a HHOOK is returned from the SetWindowsHookEx, and that needs to be passed to the CallNextHookEx function.

Update: It seems the hook parameter is ignored on the NT platforms:
http://msdn.microsoft.com/en-us/library/ms644974.aspx
http://www.klenotic.com/pl/null_hhook/

  • 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. 2026-05-10T19:06:36+00:00Added an answer on May 10, 2026 at 7:06 pm

    According to the docs, the proper thing to do is pass the arguments you received directly to CallNextHookEx, exactly as you received them. You should also call CallNextHookEx regardless of whether you decided to handle the hook message.

    According to MSDN, the first parameter to CallNextHookEx is ignored on on NT/XP/2003, and for older Win95-based operating systems it should be the HHOOK you received when you registered your hook with SetWindowsHookEx. The docs don’t specify a value for Windows 2000, but since it’s part of the NT family, a reasonable guess is that it’s ignored there as well.

    Given all that, a good way to code the method for NT-family operating systems might be this:

    LRESULT CALLBACK CBTProc( int code, WPARAM wp, LPARAM lp ) {     if( code == HCBT_CREATEWND )         ProcessCreateWnd( wp, lp );     return CallNextHookEx( 0, code, wp, lp ); }  void ProcessCreateWnd( WPARAM wp, LPARAM lp ) {     // my code here } 

    This makes sure that you always call the hook at the end of your processing, and makes it hard to accidentally add a return that will bypass CallNextHookEx.

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

Sidebar

Ask A Question

Stats

  • Questions 100k
  • Answers 101k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In addition to features you are already familiar with, I… May 11, 2026 at 8:00 pm
  • Editorial Team
    Editorial Team added an answer If you check that Programming Restrictions section of the EJB… May 11, 2026 at 8:00 pm
  • Editorial Team
    Editorial Team added an answer You can also use: sed -e 's!<html>!<html><link rel="stylesheet" type="text/css" href="LivingInStyle.css">!'… May 11, 2026 at 8:00 pm

Related Questions

I have a scenario setup where I need to test to see if the
I have successfully set up a WPF Datagrid with the March 2009 WPF Toolkit
My C# application crashes under some circumstances when run with a non-admin user. I'm
We've just set up a new remote access solution using Microsoft's TS Gateway, which

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.