C++/VB - CallNextHookEx/AfxCbtFilterHook => stack overflow
Asked By Bill Davy
08-Sep-08 04:47 AM
Stack overflowed in call of CallNextHookEx() after label (!) in
AfxCbtFilterHook(int code=69762, unsigned int wParam=134, long lParam=0).
Nothing that looked interesting on the stack (and none of my functions
either).
I've a feeling/hunch/guess this is down to leaving my program running (with
a progress bar being updated) when I lock this computer.
It was worse on VS.2003 and better under VS.2005 (and do not have anything
later to try).
Any suggestions?
TIA
Bill
CallNextHookEx
(1)
AfxCbtFilterHook
(1)
SetWindowsHookEx
(1)
MFC
(1)
DavidRe
(1)
MSFTNGP
(1)
BillRe
(1)
HookFinder
(1)
David Ching replied...
More info please. What are you doing that is causing MFC to use a CBT
filter hook?
-- David
Bill Davy replied...
Not explicitly using hooks at all (what are they?). What might cause MFC to
use one?
Does CBT = "cognitive behavioral therapy"?
If there is a next time, I'll gather the call stack in csae that contains
something revealing.
Rgds,
Bill
David Ching replied...
LOL, no, it stands for "Computer based training". I think MFC uses this
hook to get notified of when a window is created so that it can, e.g. center
a modal window over its parent. (Yes, I was amazed it took something as low
level as a hook to perform this function.) But I don't see why this code
should fail in your case.
One thing is that hooks are sensitive to other apps that have installed the
same hook. In fact, you say the crash occurs when CallNextHookEx() is
running, and that is what causes the next app to have registered for the
hook notification to be called. So it might have something to do with
another app in your system that is misbehaving.
-- David
Bill Davy replied...
That seems reasonable. I suppose the hook list is global. Is there an easy
way to see when and who has registered? It might help me point the finger,
otherwise it is left pointing at me. This is a corporate machine and there
are things going on of which I know not. The problem is not thought to
happen when disconnected from the network (a perception on which I lean
heavily).
TIA,
Bill
David Ching replied...
There are some anti-malware packages that intercept SetWindowsHookEx() and
display a big message saying "app so and so just tried to install a hook, do
you want to let it?" (of course they use vaguer terminology). Maybe you
could run one of those. But it needs to run early on, before the other
apps.
You can search for this; I found HookFinder article at
http://www.cylab.cmu.edu/files/cmucylab07015.pdf which mentions some.
-- David
Bill Davy replied...
Many thanks. Now I know what I am looking for, I will follow it up from
here.
Rgds,
Bill

SetWindowsHookEx and WH_MOUSE C++ / VB Hello, Newsgroupians! I've a question regarding SetWindowsHookEx with WH_MOUSE. I have created a DLL that sets a hook, which captures the WM_LBUTTONDOWN if ((nCode = = HC_ACTION) && (wParam = = WM_LBUTTONDON)) { g_pt = ((MOUSEHOOKSTRUCT *)lParam)-> pt; SetEvent(g_hEvent); return 1; } else { return CallNextHookEx(g_hHook, nCode, wParam, lParam); } BOOL WINAPI UnhookWindow() { return UnhookWindowsHookEx(g_hHook); } POINT WINAPI HookWindow(HWND hWndToHook) { g_hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); g_hHook = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)MouseProc, g_hInstance, GetWindowThreadProcessId(hWndToHook, NULL)); WaitForSingleObject(g_hEvent, INFINITE); MessageBox(NULL, "Point acquired!", "Acquired to solve this problem soon. Thank you once again. Trecius VC Language Discussions DLL (1) SetWindowsHookEx (1) HINSTANCE (1) WPARAM (1) G_hEvent (1) G_hHook (1) LPARAM (1) WH_MOUSE (1) You appear would like to ask WHAT is being injected into the other process when I call SetWindowsHookEx(). SetWindowsHookEx has the following arguments. . . SetWindowsHookEx(idHook, lpfn, hMod, dwThreadId) So when I call SetWindowsHookEx(. . .), am I injecting ONLY the lpfn
SetWindowsHookEx making all console apps come to a crawl. C++ / VB I have a case where my Windows process uses SetWindowsHookEx to inject a WH_KEYBOARD hook in all processes of the desktop. Everything works as expected event. This is the case even if I have my KeyboardProc does nothing except call CallNextHookEx. All Windows processes are unaffected; it's only console apps. I debugged cmd and found Any information is much appreciated. Thank you, Chris Win32 UI Discussions LPARAM (1) WPARAM (1) SetWindowsHookEx (1) CallNextHookEx (1) KeyboardProc (1) NCode (1) DLL (1) G_hHook (1) I haven't this problem and g_hWndNotify = NULL; LRESULT CALLBACK KeyboardProc(INT nCode, WPARAM wParam, LPARAM lParam) { if (nCode < 0) return(CallNextHookEx(g_hHook, nCode, wParam, lParam)); / / to test each key PostMessage (g_hWndNotify, WM_HOOK_KEYBOARD, wParam, lParam); if (wParam = = VK_F9 && !(lParam & (1<<31))) { Beep(1000, 100); } return(CallNextHookEx(g_hHook, nCode, wParam, lParam)); } Thank you for the information. My hook proc is simply as follows: LRESULT CALLBACK KeyboardProc( int code, WPARAM wParam, LPARAM lParam) { return CallNextHookEx(NULL, code, wParam, lParam); } While my process that initiated the SetWindowsHookEx is running, all console
SetWindowsHookEx - CBTProc C++ / VB I've been "playing" with SetWindowsHookEx for the past several days trying to accomplish something. I'm not sure what I a child of my window. I was going to do this by trapping HCBT_CREATWND using SetWindowsHookEx and change CREATESTRUCT::hwndParent to my window. Does this sound plausible? I'd like to then. . . / / this called within a function called SetHook() in my dll / / by my exe hHook = SetWindowsHookEx(WH_CBT, CBTProc, GetModuleHandle(NULL) , GetCurrentThreadId()); / / from exe / / Create app here / / called from within a dll lpcs; / / see if its the right class and name, if so / / change the parent } return CallNextHookEx(hHook, nCode, wParam, lParam); } Thanks for any help, I've been spinning my wheels on now. Steven VC Language Discussions PowerPoint (1) Office (1) Word (1) UnhookWindowsHookEx (1) GetCurrentThreadId (1) SetWindowsHookEx (1) CallNextHookEx (1) CBTProc (1) You don't need hook. Just embed it with COM or other does anyone know how to change the parent of an application as it launches with SetWindowsHookEx? Here's the OCX you can buy: http: / / www.ocxt.com / archives / category / office-automation