Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   Detecting WM_CREATE and hooking into window (http://www.go4expert.com/forums/detecting-wmcreate-hooking-window-t4019/)

flynny1st 25Apr2007 20:48

Detecting WM_CREATE and hooking into window

In my program i've created a system wide hook that will sit there polling until it detects WM_CREATE (this is so i can be sure the program im trying to hook into exists.) I then want to hook into this window, remove the system wide hook and add a hook into this window.

MY systemwide hook is working ok and i can hook detect the WM_CREATE no problem.

however where do i go from there? i've tried doing a FindWindow(NULL, "NAME"); and then testing if a hook is returned if it is remove the hook and hook into the findwindow one. However this crashes my system for some reason.

Is there any reason for this. My program is a console application which is using a DLL i created holding all the callback functions, etc.

Heres the code


        //hook into all events
        HOOKPROC hkprcSysMsg;
        static HINSTANCE hinstDLL;
        static HHOOK hhookSysMsg;
        hinstDLL = LoadLibrary((LPCTSTR) ".\\LaunchDLL.dll");
        hkprcSysMsg = (HOOKPROC)GetProcAddress(hinstDLL, "?LauncherEventsHook@@YGJHHJ@Z");               
        hhookSysMsg = SetWindowsHookEx(WH_CALLWNDPROC,hkprcSysMsg,hinstDLL,0);

        char buf[128];
        sprintf(buf, "hinstDLL %d, hhookSysMsg %d, hkprcSysMsg %d", hinstDLL, hkprcSysMsg, hkprcSysMsg);
        MessageBox(NULL, buf, NULL, 0);

the DLL code for LauncherEventsHook is this


LRESULT CALLBACK LauncherEventsHook (int nCode, int wParam, long lParam)
        LRESULT Result = CallNextHookEx(Hook, nCode, wParam, lParam);

        if(nCode == HC_ACTION)       

                tagCWPSTRUCT* eStruct = (tagCWPSTRUCT*) lParam;

                //check if window is being activated and check if can hook into relevent window
                if(eStruct->message == WM_CREATE)

                        foundHWnd = FindWindow(NULL, "Calculator");

                        if(foundHWnd > 0)
                                char buf[128];
                                sprintf(buf, "IN HERE SO CREATE NEW HOOK");
                                MessageBox(NULL, buf, NULL, 0);
        return Result;

thanks, matt.

All times are GMT +5.5. The time now is 20:45.