flynny1st
April 26th, 2007, 08:29 AM
Hi,
I've created a system wide hook which i want to sit there until another program i want is opened. When this happens i want to hook into it. Is this possible? As at the moment my code doesnt seem to be working and the second hook is not being created.
The first system wide hook is working ok and getting called however, the second hook keeps returning zero. Heres the Callback method for the system wide hook.
LRESULT CALLBACK LauncherEventsHook (int nCode, int wParam, long lParam)
{
if ( nCode == HC_ACTION )
{
LPCWPSTRUCT pCwp = (LPCWPSTRUCT) lParam;
if(pCwp->message == WM_CREATE)
{
fHWnd = FindWindow(NULL, "Calculator");
if(fHWnd > 0 && found == false)
{
if( fHHook == NULL) //if hook not created then remove system wide hook and hook into window
{
fHInst = FindWindowHInstance(fHWnd);
fProcID = FindWindowProcess(fHWnd);
HOOKPROC fhkprc;
static HINSTANCE hinstDLL;
hinstDLL = LoadLibrary((LPCTSTR) ".\\LaunchDLL.dll");
fhkprc = (HOOKPROC)GetProcAddress(hinstDLL, "?FoundWndHookProc@@YGJHHJ@Z");
fHHook = (HHOOK)SetWindowsHookEx(WH_CALLWNDPROC, fhkprc, fHInst, fProcID);
//char buf[128];
//sprintf(buf, "CREATE NEW HOOK %d, fHwnd %d, fHInst %d, fProcID %d, hinstDLL %d, fhkprc %d", fHHook, fHWnd, fHInst, fProcID, hinstDLL, fhkprc);
//MessageBox(NULL, buf, NULL, 0);
}
found = true;
}
}
}
return CallNextHookEx( SysHook, nCode, wParam, lParam );
}
any ideas?
Matt.
I've created a system wide hook which i want to sit there until another program i want is opened. When this happens i want to hook into it. Is this possible? As at the moment my code doesnt seem to be working and the second hook is not being created.
The first system wide hook is working ok and getting called however, the second hook keeps returning zero. Heres the Callback method for the system wide hook.
LRESULT CALLBACK LauncherEventsHook (int nCode, int wParam, long lParam)
{
if ( nCode == HC_ACTION )
{
LPCWPSTRUCT pCwp = (LPCWPSTRUCT) lParam;
if(pCwp->message == WM_CREATE)
{
fHWnd = FindWindow(NULL, "Calculator");
if(fHWnd > 0 && found == false)
{
if( fHHook == NULL) //if hook not created then remove system wide hook and hook into window
{
fHInst = FindWindowHInstance(fHWnd);
fProcID = FindWindowProcess(fHWnd);
HOOKPROC fhkprc;
static HINSTANCE hinstDLL;
hinstDLL = LoadLibrary((LPCTSTR) ".\\LaunchDLL.dll");
fhkprc = (HOOKPROC)GetProcAddress(hinstDLL, "?FoundWndHookProc@@YGJHHJ@Z");
fHHook = (HHOOK)SetWindowsHookEx(WH_CALLWNDPROC, fhkprc, fHInst, fProcID);
//char buf[128];
//sprintf(buf, "CREATE NEW HOOK %d, fHwnd %d, fHInst %d, fProcID %d, hinstDLL %d, fhkprc %d", fHHook, fHWnd, fHInst, fProcID, hinstDLL, fhkprc);
//MessageBox(NULL, buf, NULL, 0);
}
found = true;
}
}
}
return CallNextHookEx( SysHook, nCode, wParam, lParam );
}
any ideas?
Matt.