Background
We have a .NET library that is referencing one of our unmanaged dlls, lets say:
- DotNet.dll
- Unmanaged.dll
Thus far, Unmanaged.dll is only 32-bit, so the DotNet.dll is marked with 32-bit CPU type.
64-bit support needs to be added. How to organize the dlls? IL code of DotNet.dll will be the same for both 32-bit and 64-bit versions.
Option 1
- 32Bit Libraries Folder
- DotNet.dll, CPU type of 32-bit
- Unmanaged.dll, compiled as 32-bit
- 64Bit Libraries Folder
- DotNet.dll, CPU type of 64-bit
- Unamanged.dll, compiled as 64-bit
In this case a developer using these libraries is forced to make 2 applications: a 32-bit one and a 64-bit one. But in this case the know exactly what is happening.
Option 2
This is the same as Option 1 except DotNet.dll has CPU Type of AnyCPU.
- 32Bit Libraries Folder
- DotNet.dll, CPU type of AnyCPU
- Unmanaged.dll, compiled as 32-bit
- 64Bit Libraries Folder
- DotNet.dll, CPU type of AnyCPU
- Unamanged.dll, compiled as 64-bit
I do not like this one because a developer using these libraries, when redistributing their application cannot do a good job of making their application not crash without setting the CPU type on their application:
- If they use 32Bit Libraries Folder, on a 64-bit OS their process will crash
- If they use 64Bit Libraries Folder, on a 32-bit OS their process will crash
This makes Option 1 superior to Option 2.
Option 3
- Unmanaged_x32.dll, compiled as 32-bit
- Unmanaged_x64.dll, compiled as 64-bit
- DotNet.dll, CPU type of AnyCPU
DotNet.dll at runtime would determine what bitness it is being run under, then PInvoke the correct Unmanaged.dll.
Question(s)
- As a developer of these libraries, what option makes most sense?
- As a developer using the DotNet.dll library, what option makes most sense?
- For Option 3, if you are using the DotNet.dll, would you want to know that the library at runtime determines what Unmanaged.dll to use?
- What about redistribution of your application with these libraries?
- Is some option missing?