解决:在另一个64位应用程序中使用一个64位dll的bool地址作为指针? - 堆栈腐败? [英] Solved: Use a 64 bit dll's address of a bool as a pointer in another 64bit application? - stack corruption?

查看:45
本文介绍了解决:在另一个64位应用程序中使用一个64位dll的bool地址作为指针? - 堆栈腐败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。



我正在使用低级鼠标钩来抓住鼠标事件。在那里,我滚动我自己的双击检测并在本地静态bool MouseDoubleClick中设置。



为了速度我觉得发送bool的地址很好MouseDouble点击我的应用程序(一个dll插件),需要通过将接收到的地址转换为指向bool的指针来知道这一点,并使用指向dll插件中的bool值的指针来进行逻辑确定。



这适用于32位低级别挂钩和插件dll的32位实例。



但是使用64位低级别挂钩(与32位相同的代码,只需重新编译)和插件dll的64位实例(也与32位相同的代码,只需重新编译)发生了一些奇怪的事情。



过来的MouseDoubleClick的64位值确实是64位值,也是正确的。我把它投射到一个指针然后我们走了,除了下游,在一个不相关的函数结束时,它在这个下游函数的右大括号崩溃,声称有一个致命的异常读取0xffffffffffffffff。



我猜测这是堆栈的返回地址,显然是错误的。



如果我在DEF中注释掉导出的函数mousehook调用的文件(我在bool MouseDoubleClick的地址上调用)除了指向bool的指针为0并且检查跳过并且不使用它因为它是null之外,一切都运行顺畅。



我不知道我做错了什么,但一定有什么不妥。

提前谢谢。



这是相关代码





//低级鼠标钩子小袋

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

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);  









//插件DLL MouseDoubleClick指针接收函数。







// Plugin DLL MouseDoubleClick pointer receiver function.

bool *pMDC = NULL; // global declaration

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

}





//哦,DEF文件!





// Ooh, the DEF File!

EXPORTS 
	
     SetMouseDoubleClick

推荐答案

也许这些链接可以提供帮助。



64位:使用指针的规则 [ ^ ]



32位世界中的32位指针 [ ^ ]
Maybe these links can be of help.

64 bit: Rules for Using Pointers[^]

32-bit pointers in a 64-bit world[^]


我修复了它不是异步接收MouseDoubleClick地址,而是可以中断正在发生的事情,我试着要求鼠标挂钩dll获取M的地址安装鼠标挂钩后,在插件dll初始化的受控环境下ouseDoubleClick。



这样可行,我们又是黄金。
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.


这篇关于解决:在另一个64位应用程序中使用一个64位dll的bool地址作为指针? - 堆栈腐败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆