adding a different references depending on the system.(32 bit or 64 bit)
-
i have project that need to reference a mathlab dll, but this dll is wroking only on 64 bit systems, because i build the dll in my 64 bit pc, when i try to run this project in 32 bit pc i get an error, but when i run the project with the dll which is built in 32 pc it works fine. so my problem is how can i add the reference at run time depending on the system(32/64), so then i don't want to keep two separate projects. and is there any way that i can add the reference that can be selected at runtime, but the doubt i'm having is i need a reference (one of them 32 dll or 64 dll) to build the project. appreciate your ideas. thanx in advance.
-
i have project that need to reference a mathlab dll, but this dll is wroking only on 64 bit systems, because i build the dll in my 64 bit pc, when i try to run this project in 32 bit pc i get an error, but when i run the project with the dll which is built in 32 pc it works fine. so my problem is how can i add the reference at run time depending on the system(32/64), so then i don't want to keep two separate projects. and is there any way that i can add the reference that can be selected at runtime, but the doubt i'm having is i need a reference (one of them 32 dll or 64 dll) to build the project. appreciate your ideas. thanx in advance.
Assuming you have two native code DLLs, one with 32-bit code, the other 64-bit code, there are basically two ways AFAIK: 1. force your app to always run in 32-bit mode using shortcut properties. Or build your managed app for "x86"; it will always require the 32-bit DLL. 2. build your managed app for "Any CPU". It will get launched as 64-bit whenever possible, and then it will need all-64-bit DLLs. As you normally don't explicitly load native DLLs from managed code, the best way to cope would be to have two prototypes and a stub for every native method, like so (note different DLL names!):
static class mathlabStub {
private static bool use64bit;[DllImport("mathlab32.dll", EntryPoint=someFunction)] public static extern int someFunction32(...);
[DllImport("mathlab64.dll", EntryPoint=someFunction)] public static extern int someFunction64(...);public static int someFunction(...) {
if (use64bit) return someFunction64(...);
return someFunction32(...);
}and then you have to set
use64bit
once, maybe like so:use64bit=sizeof(IntPtr)==8;
use64bit=Marshal.SizeOf(typeof(IntPtr))==8;
:)Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Sunday, April 17, 2011 11:51 AM