我可以将 32 位 DLL 加载到 Windows 上的 64 位进程中吗? [英] Can I load a 32 bit DLL into a 64 bit process on Windows?

查看:18
本文介绍了我可以将 32 位 DLL 加载到 Windows 上的 64 位进程中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近升级了一个 c# windows 服务以作为 64 位 .net 进程运行.通常,这很简单,但系统使用了用 C++ 编写的 32 位 DLL.无法将此 DLL 转换为 64 位,因此我将 DLL 包装在单独的 32 位 .net 进程中,并通过远程处理公开了 .net 接口.

I recently upgraded a c# windows service to run as a 64 bit .net process. Normally, this would be trivial, but the system makes use of a 32-bit DLL written in C++. It is not an option to convert this DLL to 64 bit, so I wrapped the DLL in a separate 32 bit .net process and exposed a .net interface via remoting.

这是一个非常可靠的解决方案,但我更愿意将系统作为单个进程运行.有什么办法可以将我的 32 位 DLL 加载到 64 位进程中并直接访问它(也许通过某种 thunking 层)?

This is quite a reliable solution, but I would prefer to run the system as a single process. Is there any way I can load my 32 bit DLL into a 64 bit process and access it directly (perhaps through some sort of thunking layer)?

推荐答案

不,你不能.

16 位和 32 位 Windows 都生活在 32 位线性地址空间中.术语 16 和 32 指的是相对于选择器的偏移量的大小.

Both 16-bit and 32-bit Windows lived in a 32-bit linear address space. The terms 16 and 32 refer to the size of the offset relative to the selector.

...

首先,请注意全尺寸 16 位指针和 32 位平面指针的大小相同.值 0x0123:0x467 需要 32 位,哇,32 位指针也是如此.这意味着包含指针的数据结构在 16 位和 32 位对应物之间不会改变大小.一个非常方便的巧合.

First, notice that a full-sized 16-bit pointer and a 32-bit flat pointer are the same size. The value 0x0123:0x467 requires 32 bits, and wow, so too does a 32-bit pointer. This means that data structures containing pointers do not change size between their 16-bit and 32-bit counterparts. A very handy coincidence.

这两个观察结果都不适用于 32 位到 64 位转换.指针的大小发生了变化,这意味着将32位结构转换为64位结构,反之亦然会改变结构的大小.并且 64 位地址空间比 32 位地址空间大 40 亿倍.如果 64 位地址空间中偏移量 0x000006fb`01234567 处有一些内存,32 位代码将无法访问它.这不像你可以建立一个临时地址窗口,因为 32 位平面代码不知道这些临时地址窗口;他们放弃了选择器,记得吗?

Neither of these two observations holds true for 32-bit to 64-bit thunking. The size of the pointer has changed, which means that converting a 32-bit structure to a 64-bit structure and vice versa changes the size of the structure. And the 64-bit address space is four billion times larger than the 32-bit address space. If there is some memory in the 64-bit address space at offset 0x000006fb`01234567, 32-bit code will be unable to access it. It's not like you can build a temporary address window, because 32-bit flat code doesn't know about these temporary address windows; they abandoned selectors, remember?

http://blogs.msdn.com/oldnewthing/archive/2008/10/20/9006720.aspx

这篇关于我可以将 32 位 DLL 加载到 Windows 上的 64 位进程中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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