Jump to content
  • Advertisement


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


DLL Shared Memory

This topic is 6012 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);

	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

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!