Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a 32 bit dll on a 64 bit machine

I have an old project which uses a 32 bit dll. This works fine on 32 bit processor, however when I install the same project on a 64 bit OS it does not work.

Is there any way to convert 32 bit dll to 64 bit? Is there an alternative solution solution to make my 32 bit dll work in a 64 bit OS?

like image 758
Nhuren Avatar asked Apr 19 '11 04:04

Nhuren


People also ask

Can I run a 32-bit DLL on a 64-bit machine?

On 64-bit Windows, a 64-bit process cannot load a 32-bit dynamic-link library (DLL). Additionally, a 32-bit process cannot load a 64-bit DLL. However, 64-bit Windows supports remote procedure calls (RPC) between 64-bit and 32-bit processes (both on the same computer and across computers).

How do I change a 32-bit DLL to 64-bit?

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

Can we use 32-bit DLL in 64-bit application C#?

A 64-bit application can not use 32-bit DLLs, as well as a 32-bit application can not use 64-bit DLLs. So you either need to compile your application for 32-bit, or you have to create a 64-bit version of your DLL.

What is the difference between 32-bit and 64-bit DLL?

If the first DLL in the path is 32 bit and your app is 32 bit, then the DLL load will work. If the app is 64 bit, it will fail to load the DLL and the process will abort. If you want two DLLs to coexist on the system path, you need to give them unique file names.


1 Answers

Your 32 bit dll should work just fine on a 64 bit machine as long as it is loaded into a 32 bit process - attempting to load a 32 bit dll into a 64 bit process will fail.

If your project is a .Net (e.g. C#) application then you should be able to target your assembly at x86 in order to get your 32 bit dll working correclty:

  • Right click on your project in Visual Studio and select Properties
  • On the Build project properties tab ensure that the Platform target drop down reads "x86" instead of "Any CPU"

If you platform target is "Any CPU" then your project will normally be targeted at whatever platform is available, i.e. x64 on a 64 bit OS - this will prevent your 32 bit dll from being loaded.

If your project is not a .Net assembly then the equivalent steps needed to do the above will be different.

Alternatively you can attempt to obtain a 64 bit version of your dll - if it is a dll that you have produced then you will need to migrate it to 64 bit yourself. If not then you are dependent on the original suppliers providing a 64 bit compatible version.

like image 108
Justin Avatar answered Oct 23 '22 22:10

Justin