13

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.

4 Answers4

13

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

Jonathan C Dickinson
  • 7,181
  • 4
  • 35
  • 46
  • It's possible using a thunking layer and some clever code. Some compilers support thunking and will do all the hard work for you. I've done this under OS/2 before. i.e. loaded and used a 16bit DLL from a 32-bit process and also a 32bit DLL from a 16 bit process. But it is not possible to run 64-bit code natively on a 32-bit machine. – hookenz Dec 08 '09 at 20:53
  • Thank you! My app failed on an Windows x64 installation - it seems the 3rd party DLL was compiled as x86. Setting my app to x86 has fixed it. – mbmcavoy Feb 04 '10 at 22:24
3

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.

Dmitry Ornatsky
  • 2,237
  • 2
  • 18
  • 25
1

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

user287107
  • 9,286
  • 1
  • 31
  • 47
0

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?

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454