Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can windows distinguish 32-bit and 64-bit DLLs?

Should Windows applications generally be able to distinguish between two DLLs with the same name, one being 32-bit and one being 64-bit, if they're in two separate paths in the system PATH variable?

Specifically right now, I have 32-bit and 64-bit DLLs for FreeImage, and they're in two separate folders, free_image_path\dist32 and free_image_path\dist64, both of which I've added to the system PATH. However, application built to use them can't find either and I'm wondering if this is because there's two DLLs with the same name and they can't distinguish them.

I also tried putting the 32-bit and 64-bit DLLs in the windows\system and windows\SySWoW64 folders respectively, and that worked for the 32-bit app but not the 64-bit.

Thanks.

like image 702
SSilk Avatar asked Jun 09 '11 19:06

SSilk


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?

Solution 2 If possible create a separate 32 bits application that uses the 32 bit dll and call that using Process. Start()[^] from your 64 bits application. There are other ways like using named pipes for inter-process communincation, but they are quite complex to implement.

How do I determine 32 or 64-bit Windows 10?

It's easy enough to check. In Windows 10, go to Settings > System > About or type About in the Windows 10 search box. Under the Device specifications heading, you'll see it at System type: "64-bit operating system, x64-based processor" means you're covered.


2 Answers

Windows can tell whether a given DLL is compiled for 32 bit or 64 bit platforms, but that won't help in the situation you describe. The DLL loader for your app process will stop looking as soon as it finds a DLL in the system path that fits the file name requirements for the DLL import. There are no other qualifications for matching code DLLs. (as noted in the comments, non-code resource DLLs are a different story. I suspect resource DLLs are not loaded by the core program loader but by a resource manager with different rules and objectives.)

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.

like image 176
dthorpe Avatar answered Oct 14 '22 06:10

dthorpe


As an alternative to putting the 64-bit dll in \windows\system32 and the 32-bit one in \windows\syswow64, I have found that it also works if you put the 32-bit one in a subdirectory of \Program Files (x86) and the 64-bit one in the corresponding subdirectory of \Program Files, with both of those subdirectories included in PATH.

like image 23
dc42 Avatar answered Oct 14 '22 08:10

dc42