Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

JonW

DLL Shared Memory

This topic is 5840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!