lechoo
April 19th, 2008, 04:55 AM
Hi,
I created simple DLL in VS2005.
TEST_API int InstallHook(void)
{
hHooks = SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC) GetMsgProc, (HINSTANCE) hInstance, 0);
return (int)hHooks;
}
TEST_API int UnInstallHook(void)
{
return UnhookWindowsHookEx(hHooks);
}
LRESULT CALLBACK GetMsgProc (int code, WPARAM wParam, LPARAM lParam )
{
if (code < 0) return CallNextHookEx(hHooks, code, wParam, lParam);
MSG *lpMsg;
lpMsg = (MSG *) lParam;
//do something with msg
return CallNextHookEx(hHooks, code, wParam, lParam);
}
I want to use this dll with BCC to capture messages system wide. In my BCB application I call InstallHook from dll and hook installs fine. I've debugged the dll. It also uninstalls fine. Problem is GetMsgProc gets messages only from BCB application window. Last parameter in SetWindowsHookEx is 0 so hook should be systemwide. Why isn't this working like this?
I found sample VB application which I modified to load this dll and from there it works for all applications. VB application was compiled in vc2005. Does it mean my problems are caused by BCC itself?
I created simple DLL in VS2005.
TEST_API int InstallHook(void)
{
hHooks = SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC) GetMsgProc, (HINSTANCE) hInstance, 0);
return (int)hHooks;
}
TEST_API int UnInstallHook(void)
{
return UnhookWindowsHookEx(hHooks);
}
LRESULT CALLBACK GetMsgProc (int code, WPARAM wParam, LPARAM lParam )
{
if (code < 0) return CallNextHookEx(hHooks, code, wParam, lParam);
MSG *lpMsg;
lpMsg = (MSG *) lParam;
//do something with msg
return CallNextHookEx(hHooks, code, wParam, lParam);
}
I want to use this dll with BCC to capture messages system wide. In my BCB application I call InstallHook from dll and hook installs fine. I've debugged the dll. It also uninstalls fine. Problem is GetMsgProc gets messages only from BCB application window. Last parameter in SetWindowsHookEx is 0 so hook should be systemwide. Why isn't this working like this?
I found sample VB application which I modified to load this dll and from there it works for all applications. VB application was compiled in vc2005. Does it mean my problems are caused by BCC itself?