问题
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:
- 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.
In terms of 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.
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