.net 从 64 位进程调用 32 位代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/128445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 10:04:27  来源:igfitidea点击:

Calling 32bit Code from 64bit Process

.netmigrationx8664-bitfortran

提问by David J. Sokol

I have an application that we're trying to migrate to 64bit from 32bit. It's .NET, compiled using the x64 flags. However, we have a large number of DLLs written in FORTRAN 90 compiled for 32bit. The functions in the FORTRAN DLLs are fairly simple: you put data in, you pull data out; no state of any sort. We also don't spend a lot of time there, a total of maybe 3%, but the calculation logic it performs is invaluable.

我有一个应用程序,我们正尝试从 32 位迁移到 64 位。它是 .NET,使用 x64 标志编译。但是,我们有大量用 FORTRAN 90 编写的 DLL 编译为 32 位。FORTRAN DLL 中的函数相当简单:您放入数据,取出数据;没有任何状态。我们也没有在那里花很多时间,总共可能有 3%,但它执行的计算逻辑是无价的。

Can I somehow call the 32bit DLLs from 64bit code? MSDN suggests that I can't, period. I've done some simple hacking and verified this. Everything throws an invalid entry point exception. The only possible solution i've found so far is to create COM+ wrappers for all of the 32bit DLL functions and invoke COM from the 64bit process. This seems like quite a headache. We can also run the process in WoW emulation, but then the memory ceiling wouldn't be increased, capping at around 1.6gb.

我可以以某种方式从 64 位代码调用 32 位 DLL 吗?MSDN 建议我不能,期间。我做了一些简单的黑客攻击并验证了这一点。一切都会抛出一个无效的入口点异常。到目前为止,我找到的唯一可能的解决方案是为所有 32 位 DLL 函数创建 COM+ 包装器并从 64 位进程调用 COM。这看起来很头疼。我们也可以在 WoW 仿真中运行该过程,但是内存上限不会增加,上限约为 1.6GB。

Is there any other way to call the 32bit DLLs from a 64bit CLR process?

有没有其他方法可以从 64 位 CLR 进程调用 32 位 DLL?

采纳答案by John Sibly

You'll need to have the 32-bit dll loaded into a separate 32-bit process, and have your 64 bit process communicate with it via interprocess communication. I don't think there is any way a 32-bit dll can be loaded into a 64 bit process otherwise.

您需要将 32 位 dll 加载到单独的 32 位进程中,并让您的 64 位进程通过进程间通信与其进行通信。我不认为有任何方法可以将 32 位 dll 加载到 64 位进程中。

There is a pretty good article here:

这里有一篇很好的文章:

Accessing 32-bit DLLs from 64-bit code

从 64 位代码访问 32 位 DLL

回答by Orion Adrian

You need to write your executable processes as 32-bit processes (versus Any CPU or x64) so that they'll be loaded with WoW32 for Vista. This will load them in the 32-bit emulation mode and you won't have the entry point problem. You can leave you libraries in AnyCPU mode, but your executables have to be compiled as x86.

您需要将可执行进程编写为 32 位进程(相对于任何 CPU 或 x64),以便它们可以通过 WoW32 for Vista 加载。这将在 32 位仿真模式下加载它们,并且您不会遇到入口点问题。您可以将库保留在 AnyCPU 模式下,但您的可执行文件必须编译为 x86。

回答by Rob Hunter

John's answer is correct if you don't want to recompile your existing dlls; however that might be an option for you as well.

如果您不想重新编译现有的 dll,John 的回答是正确的;但是,这也可能是您的选择。

Our team is currently migrating our x86 FORTRAN code to x64 to increase the memory ceiling.

我们的团队目前正在将我们的 x86 FORTRAN 代码迁移到 x64 以增加内存上限。