Skip to main content
GameDev.net gamedev.net
🔒 Locked

DLL Shared Memory

Started by JonW May 31, 2002 at 6:44 PM 0 replies 450+ views
Original Post
JonW
JonW
I have a shared memory block in my DLL that looks like this:
  
// Shared data among all DLL instances

#pragma data_seg(".HOOKDATA")
HHOOK hKeyHook = NULL;
#pragma data_seg()

// Linker directive

#pragma comment(linker, "/SECTION:.HOOKDATA,RWS")
  
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:
  
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;
}
  
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.