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. A simple hooking problem

A simple hooking problem

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
5 Posts 3 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.
  • G Offline
    G Offline
    generic_user_id
    wrote on last edited by
    #1

    I'm trying to hook up to another program, using SetWindowsHookEx. I need to hook to a specific application (ie: calc.exe) so a global hook shouldn't be neccecary.

    HHOOK hook = SetWindowsHookEx(WH_MOUSE,
    (HOOKPROC) MouseHookProc,
    AfxGetInstanceHandle(),
    tID // Thread ID of Calc.exe
    );

    SetWindowsHookEx returns 0, the hook is set succesfully. Yet, when I move with my mouse over the calc dialog, the calculator crashes. I think I need to use the Process instance of calc.exe instead of the instance of the program that hooks to it. If that is the case, how can I get the HINSTANCE of a process? If that's not the case, what am I doing wrong? Thanks in advance and kind regards, Griffith


    Everything you say will be misquoted, ripped out of context and used against you.

    S J 2 Replies Last reply
    0
    • G generic_user_id

      I'm trying to hook up to another program, using SetWindowsHookEx. I need to hook to a specific application (ie: calc.exe) so a global hook shouldn't be neccecary.

      HHOOK hook = SetWindowsHookEx(WH_MOUSE,
      (HOOKPROC) MouseHookProc,
      AfxGetInstanceHandle(),
      tID // Thread ID of Calc.exe
      );

      SetWindowsHookEx returns 0, the hook is set succesfully. Yet, when I move with my mouse over the calc dialog, the calculator crashes. I think I need to use the Process instance of calc.exe instead of the instance of the program that hooks to it. If that is the case, how can I get the HINSTANCE of a process? If that's not the case, what am I doing wrong? Thanks in advance and kind regards, Griffith


      Everything you say will be misquoted, ripped out of context and used against you.

      S Offline
      S Offline
      Scott H Settlemier
      wrote on last edited by
      #2

      You gotta put the hook procedure in a dll that can be loaded by Calc.exe's process. Then pass SetWindowsHookEx the HINSTANCE for that dll as loaded into your process. (as well as the pointer to the hook procedure)

      G 1 Reply Last reply
      0
      • S Scott H Settlemier

        You gotta put the hook procedure in a dll that can be loaded by Calc.exe's process. Then pass SetWindowsHookEx the HINSTANCE for that dll as loaded into your process. (as well as the pointer to the hook procedure)

        G Offline
        G Offline
        generic_user_id
        wrote on last edited by
        #3

        Okay, thanks I'll try that then. Cheers Griffith


        Everything you say will be misquoted, ripped out of context and used against you.

        1 Reply Last reply
        0
        • G generic_user_id

          I'm trying to hook up to another program, using SetWindowsHookEx. I need to hook to a specific application (ie: calc.exe) so a global hook shouldn't be neccecary.

          HHOOK hook = SetWindowsHookEx(WH_MOUSE,
          (HOOKPROC) MouseHookProc,
          AfxGetInstanceHandle(),
          tID // Thread ID of Calc.exe
          );

          SetWindowsHookEx returns 0, the hook is set succesfully. Yet, when I move with my mouse over the calc dialog, the calculator crashes. I think I need to use the Process instance of calc.exe instead of the instance of the program that hooks to it. If that is the case, how can I get the HINSTANCE of a process? If that's not the case, what am I doing wrong? Thanks in advance and kind regards, Griffith


          Everything you say will be misquoted, ripped out of context and used against you.

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

          A return of 0 means it didn't work. NULL = 0. Check the docs. As previously mentioned, the actual procedure needs to be in a dll. Joel Lucsy (jjlucsy@concentric.net)

          G 1 Reply Last reply
          0
          • J Joel Lucsy

            A return of 0 means it didn't work. NULL = 0. Check the docs. As previously mentioned, the actual procedure needs to be in a dll. Joel Lucsy (jjlucsy@concentric.net)

            G Offline
            G Offline
            generic_user_id
            wrote on last edited by
            #5

            My mistake, I meant to say that GetLastError() returned 0, just after I attempted to create the hook. I thought I had to place the procedure in a DLL only for system-wide hooks, but it appears it's in order for all hooks outside of the calling process. Griffith


            Everything you say will be misquoted, ripped out of context and used against you.

            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