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