.net - 我可以将 32 位 DLL 加载到 Windows 上的 64 位进程中吗?

标签 .net windows 64-bit x86-64

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

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

最佳答案

不,你不能。

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.

...

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.

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

关于.net - 我可以将 32 位 DLL 加载到 Windows 上的 64 位进程中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/225151/

相关文章:

c# - Umbraco 自定义部分中的多级树

c++ - Sleep() 是一个糟糕的设计,但似乎是我唯一的选择

c++ - 在带符号的 64 位表示中找到数字 n 的第 b 位

c - GetVolumeInformation 返回的 FileSystemName 字符串的可能值是什么?

windows - 我无法使用python播放音频

oracle - 在 CentOS 5 64 位上安装 Oracle 10.2 64 位

windows - 签署 Windows x64 驱动程序以在未启用测试模式的情况下工作

c# - BitArray 可以是动态的吗?还是 List<bool> 是唯一的方法?

C# - DateTime.FromFileTimeUtc 到 DateTime.FromFileTime

c# - DebuggerStepThrough 属性等效于属性?