Convert 32 bit dll to 64 bit dll

泪湿孤枕 提交于 2020-01-14 07:12:09

问题


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.

Please help me out with this.


回答1:


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).

You are not entirely clear on when it works and when it doesn't. Here are the explanations:

  1. x86 - 32bit - Can not be loaded into a 64bit process.
  2. x64 - 64bit - Can not be executed on a 32bit machine.
  3. AnyCPU - dual - Can be loaded and executed in both environments.

In terms of AnyCPU:

  1. 64bit process on 64bit machine - DLL is loaded as 64bit.
  2. 32bit process on 32bit machine - DLL is loaded as 32bit.
  3. 32bit process on 64bit machine - DLL is loaded as 32bit.

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).




回答2:


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.




回答3:


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.

I'm not 100% sure that's what you're asking though. If it's not can you clarify your question?




回答4:


you can take a look at http://msdn.microsoft.com/en-us/library/ms164699%28VS.80%29.aspx



来源:https://stackoverflow.com/questions/944962/convert-32-bit-dll-to-64-bit-dll

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!