C# 将 32 位 dll 转换为 64 位 dll
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/944962/
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
Convert 32 bit dll to 64 bit dll
提问by
I have the 32 bit compiled dll when I try to use it in 64 bit application it fails to load, So I would like to convert the dll to 64 bit. Its working fine when the platform of the application changed from "Any CPU" or "x64" to "x86". But I want to use it under 64 bit, Since I am going to call the dll from ASP pages.
当我尝试在无法加载的 64 位应用程序中使用它时,我有 32 位编译的 dll,所以我想将 dll 转换为 64 位。当应用程序的平台从“任何 CPU”或“x64”更改为“x86”时,它工作正常。但我想在 64 位下使用它,因为我要从 ASP 页面调用 dll。
Please help me out with this.
这个你能帮我吗。
回答by JaredPar
If you want to load a pure C# DLL in both a 32 and 64 bit process, then the correct choice is AnyCPU. This will compile it the DLL as CPU agnostic and it will be loadable into either type of process.
如果要在 32 位和 64 位进程中加载纯 C# DLL,那么正确的选择是 AnyCPU。这会将它编译为与 CPU 无关的 DLL,并且它可以加载到任一类型的进程中。
I'm not 100% sure that's what you're asking though. If it's not can you clarify your question?
我不是 100% 确定这就是你要问的。如果不是,你能澄清你的问题吗?
回答by Jonathan C Dickinson
Windows CAN NOT load a 32bit dll into a 64bit process - this is a limitation that you can not circumvent. This means that if your 32bit DLL does any P/Invokes to other 32bit DLLS (or uses any 32bit .Net DLLS) you will be entirely out of luck (you will need to run the entire website in 32bit).
Windows 无法将 32 位 dll 加载到 64 位进程中 - 这是您无法规避的限制。这意味着,如果您的 32 位 DLL 对其他 32 位 DLLS(或使用任何 32 位 .Net DLLS)执行任何 P/Invokes,您将完全不走运(您将需要以 32 位运行整个网站)。
You are not entirely clear on when it works and when it doesn't. Here are the explanations:
你并不完全清楚它什么时候起作用,什么时候不起作用。以下是解释:
- x86 - 32bit - Can not be loaded into a 64bit process.
- x64 - 64bit - Can not be executed on a 32bit machine.
- AnyCPU - dual - Can be loaded and executed in both environments.
- x86 - 32 位 - 无法加载到 64 位进程中。
- x64 - 64 位 - 不能在 32 位机器上执行。
- AnyCPU - 双 - 可以在两种环境中加载和执行。
In terms of AnyCPU:
在 AnyCPU 方面:
- 64bit process on 64bit machine - DLL is loaded as 64bit.
- 32bit process on 32bit machine - DLL is loaded as 32bit.
- 32bit process on 64bit machine - DLL is loaded as 32bit.
- 64 位机器上的 64 位进程 - DLL 加载为 64 位。
- 32 位机器上的 32 位进程 - DLL 加载为 32 位。
- 64 位机器上的 32 位进程 - DLL 加载为 32 位。
In most cases it's fine to leave it as AnyCPU. However, as I said, if you are using any native or .Net 32bit DLLs you will need to make your entire application 32bit (and there is nothing you can, or Microsoft could, do about this).
在大多数情况下,将其保留为 AnyCPU 就可以了。但是,正如我所说,如果您使用任何本机或 .Net 32 位 DLL,您将需要将整个应用程序设为 32 位(并且您无法或 Microsoft 对此无能为力)。
回答by Dmitry Ornatsky
x86 flag is usually set for a reason, so it may be bad idea to change it. But if you are absolutely sure, there's an utility, corflags.exe. I have it under C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin. Of course it will help with .net assemblies only.
x86 标志的设置通常是有原因的,因此更改它可能是个坏主意。但是,如果您绝对确定,还有一个实用程序 corflags.exe。我在 C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin 下有它。当然,它只会对 .net 程序集有所帮助。