[英]Can I load a 32 bit DLL into a 64 bit process on Windows?
I recently upgraded ac# windows service to run as a 64 bit .net process. 我最近升级了ac #windows服务,以64位.net进程运行。 Normally, this would be trivial, but the system makes use of a 32-bit DLL written in C++.
通常,这将是微不足道的,但系统使用了用C ++编写的32位DLL。 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.
它不能将此DLL转换为64位,因此我将DLL封装在一个单独的32位.net进程中,并通过远程处理暴露了.net接口。
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)?
有没有什么办法可以将我的32位DLL加载到64位进程并直接访问它(可能通过某种thunking层)?
No, you can't. 不,你不能。
Both 16-bit and 32-bit Windows lived in a 32-bit linear address space.
16位和32位Windows都存在于32位线性地址空间中。 The terms 16 and 32 refer to the size of the offset relative to the selector.
术语16和32指的是相对于选择器的偏移的大小。
...
...
First, notice that a full-sized 16-bit pointer and a 32-bit flat pointer are the same size.
首先,请注意,全尺寸的16位指针和32位平面指针的大小相同。 The value 0x0123:0x467 requires 32 bits, and wow, so too does a 32-bit pointer.
值0x0123:0x467需要32位,哇,32位指针也是如此。 This means that data structures containing pointers do not change size between their 16-bit and 32-bit counterparts.
这意味着包含指针的数据结构不会改变它们的16位和32位对应的大小。 A very handy coincidence.
一个非常方便的巧合。
Neither of these two observations holds true for 32-bit to 64-bit thunking.
对于32位到64位的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 .
指针的大小已更改,这意味着将32位结构转换为64位结构(反之亦然)会更改结构的大小 。 And the 64-bit address space is four billion times larger than the 32-bit address space.
64位地址空间比32位地址空间大40亿倍。 If there is some memory in the 64-bit address space at offset 0x000006fb`01234567, 32-bit code will be unable to access it.
如果64位地址空间中的某些内存偏移量为0x000006fb`01234567,则32位代码将无法访问它。 It's not like you can build a temporary address window, because 32-bit flat code doesn't know about these temporary address windows;
这不像你可以建立一个临时地址窗口,因为32位平面代码不知道这些临时地址窗口; they abandoned selectors, remember?
他们放弃了选择者,还记得吗?
http://blogs.msdn.com/oldnewthing/archive/2008/10/20/9006720.aspx http://blogs.msdn.com/oldnewthing/archive/2008/10/20/9006720.aspx
If your .NET application is a website running in IIS you can circumvent it. 如果您的.NET应用程序是在IIS中运行的网站,您可以绕过它。
An ASP.NET webpage running on IIS on a 64-bit machine will be hosted by a 64-bit version of the w3wp.exe process, and if your webpage uses 32-bit dlls your site will fail. 在64位计算机上的IIS上运行的ASP.NET网页将由64位版本的w3wp.exe进程托管,如果您的网页使用32位dll,则您的站点将失败。
However in IIS you can go into the Advanced Settings of the Application Pool running the site, and change "Enable 32-bit applications" to true. 但是,在IIS中,您可以进入运行该站点的应用程序池的“高级设置”,并将“启用32位应用程序”更改为true。
So it's still not able to run 32-bit dll inside 64-bit process, but rather it is running w3wp.exe as a 32-bit process instead. 所以它仍然无法在64位进程内运行32位dll,而是将w3wp.exe作为32位进程运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.