views:

4549

answers:

4

Hi Everyone,

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.

Thanks in Advance, Gan

+1  A: 

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
+5  A: 

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
Not just Windows, all OS's!
Paul Betts
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.
Matt H
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
A: 

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
A: 

Yes, I am having the same kind of issue,I have the source code for this dll so I can able to recompile. The entire code is written in native C and I am compiling the project using VS2008. when I tried to change the platform to 'x64', that option to change x64 is not available under vc++ project. So could you please help me out with this.

Ganesh Astroved
Did you install x64 C++ support when you installed VS2008? I don't think it is part of the default install.
dmo
Ya great, you are correct I have Installed the x64 compiler tools and now I can get that option, but still my application fails to load that dll. Both the dll are in x64 I checked using Dependency walker. Could any one help me with this.
Ganesh Astroved