c# - Target 32 Bit or 64 Bit native DLL depending on environment -
I have a native DLL that comes in both 32-bit and 64-bit versions (x86). I want to create a cover that works on both architecture (any CPU) and loads the correct version of DLL based on the current environment (32 bit or 64 bit at runtime). This process should be done automatically so that my DLL users do not need to target a specific architecture.
Is there any best practice to do this? Any example that can guide me?
I have found a possible solution that uses a managed proxy for each architecture and then uses the Is there any other solution? Here's a solution I used on many projects: Here I declare P / invention methods: / P> And here is the same 'MyTest' function which I will always use (others here are just for right biting). It has the same signature as compared to other P / Inocoids: The advantages are: There are inconveniences: Assembly.Resolve event to load the correct code. However, for this I need 3 managed assemblies in addition to 2 unmanaged libraries, which seems a bit more.
[DllImport ("MyAssembly.Native.x86.dll", entrypoint = "MyTest")] Personal static extension zero MyTest86 (MyType myArg); [DllImport ("MyAssembly.Native.x64.dll", EntryPoint = "MyTest")] Private static extension Zero MyTest 64 (MyType MyRG);
Public Static Zero MyType myArg {if (IntPtr.Size == 8} {MyTest64 (myArg); Return; } MyTest86 (myArg); }
Comments
Post a Comment