32 bit dll importing in 64 bit .Net application

As I understand things, you have no way of using a 32-bit DLL from a 64-bit application. That said, you may compile your application for X86 only.

The solution you found may be about how to use a DLL that exists for both 32- and 64-bit versions in an "Any CPU"-compiled project depending on whether the application is running in a 32- or 64-bit environment.

To do that, you could write two wrapper DLLs in C#, one for 64-bit and one for 32-bit and use the respective wrapper depending on whether you're running on a 64-bit or 32-bit OS.

However, this does not work when all you have is a 32-bit DLL. 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.


A general idea could be to wrap your (unmanaged) 32-bit DLL with a managed 32-bit wrapper dll and make it COM visible. This allows calls to your wrapper DLL via its COM interface.

You can than use a COM surrogate to make your COM dll appear as an out of process COM server. Take a look at this SO question for some further information on this topic: Access x86 COM from x64 .NET.


What you have to do is write a wrapper application that hosts the 32-bit DLL file, in a 32-bit process.

Your 64-bit application then has to talk to this 32-bit process, through network means, or by making the DLL functions available through a COM object, or similar.

You can not run a 32-bit DLL inside a 64-bit process, no matter how hard you try, so you need to run it in a 32-bit process.

If compiling your application for 32-bit only is not an option, you have no choice but to create a host application.