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 631235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:56:34+00:00 2026-05-13T19:56:34+00:00

I am trying to learn the Windows API. Currently I am having a lot

  • 0

I am trying to learn the Windows API. Currently I am having a lot of trouble trying to get hooks to work. I have some sample code I have been messing around with for a few days – it has a GUI written in C# or something, and a dll in C++. The dll has this function externalized:

bool __declspec(dllexport) InstallHook(){
    g_hHook      = SetWindowsHookEx(WH_CBT, (HOOKPROC) CBTProc, g_hInstance, 0);
    return g_hHook != NULL;
}

CBT Proc is this, also in the dll:

LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam){
    if (nCode < 0)
        return CallNextHookEx(g_hHook, nCode, wParam, lParam);
    /* Something should go here to do stuff when certain nCodes are recieved.*/
    return 0;
}

When I run this guys code, everything works fine. He has a call to InstallHook() buried somewhere in his C# GUI, and if I put a breakpoint in the CBTProc function, I can see that it is called over and over by the system. As I don’t really understand C#, I am trying to cut it out with the following (tiny) console application:

int _tmain(int argc, _TCHAR* argv[]){
    bool bbbb = InstallHook();
    Sleep(2000);
    return 0;
}

My problem is that if I do this, the hook no longer works. With the debugger I can see that InstallHook() is called correctly, and that g_hHook in that function is not null, but the CBTProc function is not called at all – its as if the system forgets about the hook as soon as it leave the InstallHook() function.

Can anyone shine light on this issue? I’ve been pulling my hair out for days trying to get it to work, but I have had no luck.

  • 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-05-13T19:56:35+00:00Added an answer on May 13, 2026 at 7:56 pm

    I suspect this is because you have console application and system does not send notifications about activating, creating, moving, etc. of console windows. Try to make it normal windows application.

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

Sidebar

Related Questions

Currently I'm trying to learn what is node.js. I have installed node.exe in windows,
Im trying to learn a bit about c++ and have run in to some
I'm currently trying to learn regular expressions with some simple "real world" examples. Take
I am trying to learn Windows.Forms, and while I have Visual Studio (edit, my
i am currently trying to learn about clean urls. i was using windows once.
I am trying to learn some Assembler code; specifically how to use the stack
I am trying to learn Rails on my own and have been having difficulty
I'm working on Windows, and I'm trying to learn pipes, and how they work.
I am trying to learn WPF.. Although, Im having trouble with the layouts and
I am new to C# and trying to learn how to create windows form

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.