A simple hooking problem
-
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.
-
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.
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)
-
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)
Okay, thanks I'll try that then. Cheers Griffith
Everything you say will be misquoted, ripped out of context and used against you.
-
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.
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)
-
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)
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.