Click here to Skip to main content
15,891,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

I am using a low level mouse hook to grab mouse events. In there, I roll my own double click detection and set that in local static bool MouseDoubleClick.

For the sake of speed I thought it good to send the address of bool MouseDoubleClick over to the my application (a dll plugin) that needs to know about this by casting the received address to a pointer to a bool, and using the pointer to the bool value over in the dll plugin to make logic determinations.

This works great with a 32 bit low level hook and a 32 bit instance of the plugin dll.

However with a 64 bit low level hook (same code as 32 bit, just recompiled) and a 64 bit instance of the plugin dll (Also same code as 32 bit, just recompiled)something weird is happening.

The 64 bit value of MouseDoubleClick that comes over is indeed a 64bit value and also correct. I cast that to a pointer and away we go except down stream, at the end of an unrelated function it crashes at the closing brace of this downstream function, claiming there was a fatal exception reading 0xffffffffffffffff.

I have surmised that this is the return address off the stack and is obviously wrong.

If I comment out the exported function in the DEF file that is called by the mousehook (where I sen over the address of bool MouseDoubleClick) everything runs smooth except the pointer to that bool is 0 and checks for that skip over and don't use it because it's null.

I have no idea what I am doing wrong, but there must be something amiss.
Thanks in advance.

Here is the "relevant" code


// Low Level Mouse Hook Sniplet
C++
typedef void (LPFNDLLFUNC1)(bool*);	
static bool MouseDoubleClick = false;
			
HINSTANCE hDLL = LoadLibrary("<Path to the plugin DLL x64 version>");
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL, "SetMouseDoubleClick");

// here we send the 64 bit address of MouseDoubleClick over to the plugin DLL

lpfnDllFunc1(&MouseDoubleClick);  




// Plugin DLL MouseDoubleClick pointer receiver function.

C++
bool *pMDC = NULL; // global declaration

void SetMouseDoubleClick(INT_PTR HooksMDC)
{
	pMDC = (bool*) HooksMDC;

}


// Ooh, the DEF File!

C++
EXPORTS 
	
     SetMouseDoubleClick
Posted
Updated 21-Jan-15 18:04pm
v4

 
Share this answer
 
I fixed it by instead of receiving the MouseDoubleClick address asynchronously where it could interrupt things going on, I tried instead to ask the mouse hook dll for the address of MouseDoubleClick under the controlled environment of plug in dll initialization just after installing the mouse hook.

That works and we're golden again.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900