我最近升级了一个 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/