Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. windows api: system wide keyboard hook problem

windows api: system wide keyboard hook problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpcomjsontutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    INA_ctive
    wrote on last edited by
    #1

    Im trying to make a program that does system wide keyboard hook. This program consist of two parts, and those are: 1. a DLL which consist of three functions: InstallHook, HookProc (the hook procedure), and RemoveHook. 2. an EXE which will load the DLL and uses/calls all the functions what the program does is, everytime there's an input from the keyobard it will pop up a messagebox saying "whoa!". the problem is that this program only monitors keystrokes on it's own thread. when the program loses focus, it will not be able to detect keystrokes and output the "whoa!" message anymore. just my thought, i think the problem lies within my installhook function within the DLL, because im not really sure how to fill the third and fourth parameters (msdn kinda confuses me) [code] SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) HookProc, GetModuleHandle(NULL), 0); [/code] this is the full source code of the program. DLL source : http://pastebin.com/468968 Exe Source : http://pastebin.com/468969 This problem really confuses me since there are no error displayed on the compiler, and the program just looks fine without crash or anything. Thank you very much for your time and help. - Ganeshwara -- modified at 3:40 Monday 19th December, 2005

    J 1 Reply Last reply
    0
    • I INA_ctive

      Im trying to make a program that does system wide keyboard hook. This program consist of two parts, and those are: 1. a DLL which consist of three functions: InstallHook, HookProc (the hook procedure), and RemoveHook. 2. an EXE which will load the DLL and uses/calls all the functions what the program does is, everytime there's an input from the keyobard it will pop up a messagebox saying "whoa!". the problem is that this program only monitors keystrokes on it's own thread. when the program loses focus, it will not be able to detect keystrokes and output the "whoa!" message anymore. just my thought, i think the problem lies within my installhook function within the DLL, because im not really sure how to fill the third and fourth parameters (msdn kinda confuses me) [code] SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) HookProc, GetModuleHandle(NULL), 0); [/code] this is the full source code of the program. DLL source : http://pastebin.com/468968 Exe Source : http://pastebin.com/468969 This problem really confuses me since there are no error displayed on the compiler, and the program just looks fine without crash or anything. Thank you very much for your time and help. - Ganeshwara -- modified at 3:40 Monday 19th December, 2005

      J Offline
      J Offline
      Joel Lucsy
      wrote on last edited by
      #2

      I believe you need to pass the HMODULE for the dll, not the exe, which is what GetModuleHandle(NULL) returns. Use something like GetModuleHandle("nameofdll.dll").

      I 1 Reply Last reply
      0
      • J Joel Lucsy

        I believe you need to pass the HMODULE for the dll, not the exe, which is what GetModuleHandle(NULL) returns. Use something like GetModuleHandle("nameofdll.dll").

        I Offline
        I Offline
        INA_ctive
        wrote on last edited by
        #3

        yes, thank you very much it has resolved! i thought since the function resides inside dll it will get the handle of the dll. i spent a few days troubleshooting this problem, thank you very much!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups