Can you import them both and make the decision about which one to call via . NET instead?
Can you import them both and make the decision about which one to call via . NET instead? For example: DllImport("32bit.
Dll", CharSet = CharSet. Unicode, EntryPoint="CallMe") public static extern int CallMe32 (IntPtr hWnd, String text, String caption, uint type); DllImport("64bit. Dll", CharSet = CharSet.
Unicode, EntryPoint="CallMe") public static extern int CallMe64 (IntPtr hWnd, String text, String caption, uint type).
That is actually my "go to" solution if I cant find a cleaner way to do it. – Mike_G Apr 7 '10 at 15:56.
You could take advantage of the SetDllDirectory API function, it alters the search path for unmanaged assemblies. Store your 32-bit DLLs in the x86 subdirectory of the app install directory, the 64-bit DLLs in the x64 subdirectory. Run this code at app startup before you do any P/Invoke: using System.IO; using System.
Reflection; using System.Runtime. InteropServices; ... public static void SetUnmanagedDllDirectory() { string path = Path. GetDirectoryName(Assembly.
GetEntryAssembly(). Location); path = Path. Combine(path, IntPtr.
Size == 8? "x64 " : "x86"); if (!SetDllDirectory(path)) throw new System.ComponentModel. Win32Exception(); } DllImport("kernel32.
Dll", CharSet = CharSet. Auto, SetLastError = true) private static extern bool SetDllDirectory(string path).
That's a cool solution. – Kieron Apr 7 '10 at 16:43.
You should make two different private extern methods, and make an internal method that checks IntPtr. Size and calls the correct version.
My solution is to create a single abstract class, with a concrete version which loads and wraps my 32bit DLL, and a separate implementation that loads and wraps the 64bit DLL. A single factory method in the base class can be used to instantiate the appropriate implementation based on the IntPtr.Size. The nice thing about this approach is that the rest of your code is completely isolated from the platform - it just constructs an object using your base class factory method, and works with it.It is also very easy to call into multiple methods within the DLLs in question, in a uniform manner, and all of your "native" code can easily be pushed into a private implementation.
...or you can use Marshal. GetDelegateForFunctionPointer() to do dynamic P/Invoke. ...or call LoadLibrary() with a fully qualified path before the CLR tries to load it for you.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.