I have asked this questions today, but it was falsely closed and I have no option to re-open it. Therefore, I have to ask it again.
I have a class that has a long list of definitions like these:
[DllImport(NativeLibraryName, EntryPoint = "FunctionName", CallingConvention = CallingConvention.Cdecl)]
public static extern void FunctionName();
The parameter "NativeLibraryName" is set by a compiler switch. However, I would like to set this parameter at run-time. My problem is that there are two different DLLs I need to consider: one is for 32-bit systems and one is for 64-bit systems and they are different in name. What I would like to achieve is to determine whether the application is run with 64- or 32-bit and use the proper DLL. I need to load the correct DLL or otherwise I run into BadImageFormatExceptions.
Switching to Delegates
I could use Reflection to generate a file that does the same as the file that is given using delegates like this. Here, I could provide the path to the correct DLL at run-time.
Renaming DLLs
I could also rename the two DLLs and have them the same name, but put them in different directories. I could then select the folder I want to load the DLL from.
Both options would work fine, but the project I am working on is a fork of an existing project and I want to change as little as possible so that I can easily merge updates from the original project into mine.
I am glad for any of your ideas.
This thread was falsely suggested as solution to my problem and the original thread was closed after that. This thread talks about a similar problem, but it does not provide a solution that is applicable to my problem. In fact, presents actually one of the solutions I came up with myself, but I am looking for better ways to do it.