Original Post
I have a shared memory block in my DLL that looks like this:
What I want to do is create hKeyHook if it is not NULL. This function checks to see if it should be created or not, and is called by all the applications that use the DLL:
This seems to work fine... the hook is created on the first run of the application, and if you try to run it again it says the keyhook is already created. But if I try to run it a third time it is created again! Does anyone see how this could be happening?
Jon Woyame
Programmer & Cheeto Consumer
http://www.moonthrone.com
// Shared data among all DLL instances
#pragma data_seg(".HOOKDATA")
HHOOK hKeyHook = NULL;
#pragma data_seg()
// Linker directive
#pragma comment(linker, "/SECTION:.HOOKDATA,RWS")
KEYHOOK_API BOOL HookKeyboard (void)
{
if (hKeyHook == NULL)
{
hKeyHook = SetWindowsHookEx (WH_KEYBOARD, KeyboardProc, g_hInstance, NULL);
if (!hKeyHook)
MessageBox (NULL, "Unable to install hook", "Error!", MB_OK);
}
else
{
MessageBox (NULL, "Keyhook already created!", "Error!", MB_OK);
return FALSE;
}
return TRUE;
}