Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29389 Discussions

Can a 64-bit executable call a 32-bit dll?

qolin
Novice
2,011 Views

Hi all

We are getting some pressure from systems guys to produce a 64-bit executable to run under Windows. Reason cited is to allow interop with other 64-bit exes, particularly with MPI for inter-process comms.

The application has been ported to linux and already compiles 32-bit and 64-bit so I don't anticipate any problems with 64-bit code under windows. However, in windows we can call 3rdparty DLLs, and these are all 32-bit. None the dll suppliers are interested in creating 64-bit versions, to them its a solution to a problem no-one has got.

So is there a way to call them from a 64-bit exe?

0 Kudos
1 Reply
jimdempseyatthecove
Honored Contributor III
2,011 Views

Someone else with more experence on this may pipe-up with a more definitive answer. If not, then here are my comments.

First off the register calling conventions are different between 32-bit and 64-bit functions.

Second, and more obvious, is that your 64-bit app will reside in a 64-bit Virtual Address space while the DLL will reside in a 32-bit Virtual Address space. The arguments can be passed between the different address spaces by a technique called Thunking. Think ofThunking as a MPI-like interface between the two address spaces. i.e. instead of passing pointers to arguments, apacket of the contents of the arguments are passed between the different virtual address spaces.

Thunkingcan beprovided with a shell library e.g. your 64-bit app calls a 64-bit shell library function which collects the data into a packet then Thunks the data to a 32-bit shell application which then calls the 32-bit DLL. If there is return data then a data packet is prepaired and Thunked back to the 64-bit shell library function.

There are several ways to perform the Thunking. If you can use Microsoft's MSDN site search for "Mixed (Native and Managed) Assemblies" in Visual C++. This will give you a good starting point.

Alternate methods would beto roll your own interface using:

a) MPI between a 64-bit app and 32-bit app
b) use a named pipe between a 64-bit app and 32-bit app
c) use a memory mapped filebetween a 64-bit app and 32-bit app

Continued use of a 32-bit DLL may have some disadvantages if the 32-bit DLL is performing a computational function on large data blocks in your applicaition. Not only is there a performance issue of passing the data back and forth but eventually you will run into a data size issue when the data block exceeds 2GB. In this case I would suggest you look for a 64-bit library that performs the same functions.

Jim Dempsey

0 Kudos
Reply