Yeb
June 30th, 1999, 02:10 AM
I have a system wide Keyboard Hook located in a DLL that is called by another application. The Hook is set and removed by two functions inside the DLL.
The first time I set the hook, it works great. If I remove the hook and then restart it (from the calling application) it only works if the calling application has the input focus or until I close the application and restart it.
I am using Visual C++ 6 on Windows 95.
If anyone has any advice I would appreciate it.
Thanks
Yaakov
Below is a snipit of the code from the DLL.
[ccode]
#pragma data_seg(".THOOKS")
HHOOK hKBHook = NULL;
HWND hHookUpWnd = NULL;
HINSTANCE hInstance = NULL;
#pragma data_seg()
BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpReseved)
{
hInstance = hinstDll;
return (TRUE);
}
__declspec(dllexport) void HookUp(HWND hWnd)
{
if( !hKBHook) {
MessageBeep(-1);
hHookUpWnd = hWnd;
hKBHook = SetWindowsHookEx( WH_KEYBOARD, KeyboardFunc, hInstance, (DWORD) NULL);
assert( hKBHook != NULL);
}
}
__declspec(dllexport) void UnHookUp()
{
if( hKBHook) {
UnhookWindowsHookEx( hKBHook);
hKBHook = NULL;
hHookUpWnd = NULL;
MessageBeep(-1);
}
}
LRESULT CALLBACK KeyboardFunc (int nCode, WPARAM wParam, LPARAM lParam )
{
MessageBeep(-1);
MessageBeep(-1);
MessageBeep(-1);
return 1;
}
[ccode]
The first time I set the hook, it works great. If I remove the hook and then restart it (from the calling application) it only works if the calling application has the input focus or until I close the application and restart it.
I am using Visual C++ 6 on Windows 95.
If anyone has any advice I would appreciate it.
Thanks
Yaakov
Below is a snipit of the code from the DLL.
[ccode]
#pragma data_seg(".THOOKS")
HHOOK hKBHook = NULL;
HWND hHookUpWnd = NULL;
HINSTANCE hInstance = NULL;
#pragma data_seg()
BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpReseved)
{
hInstance = hinstDll;
return (TRUE);
}
__declspec(dllexport) void HookUp(HWND hWnd)
{
if( !hKBHook) {
MessageBeep(-1);
hHookUpWnd = hWnd;
hKBHook = SetWindowsHookEx( WH_KEYBOARD, KeyboardFunc, hInstance, (DWORD) NULL);
assert( hKBHook != NULL);
}
}
__declspec(dllexport) void UnHookUp()
{
if( hKBHook) {
UnhookWindowsHookEx( hKBHook);
hKBHook = NULL;
hHookUpWnd = NULL;
MessageBeep(-1);
}
}
LRESULT CALLBACK KeyboardFunc (int nCode, WPARAM wParam, LPARAM lParam )
{
MessageBeep(-1);
MessageBeep(-1);
MessageBeep(-1);
return 1;
}
[ccode]