C#: Access 32-bit/64-bit DLL depending on platform

后端 未结 4 1921
自闭症患者
自闭症患者 2021-02-09 23:48

we use a self-written 32bit C++ DLL from our C# applications. Now we\'ve noticed that when the C# applications are run on a 64bit system, the 64bit runtime is automatically used

4条回答
  •  清歌不尽
    2021-02-10 00:14

    You need to make sure that you're only using P/Invoke calls against a 64bit DLL when compiling in 64bit.

    One option is to move all of your "methods" into a standard interface (or abstract base class), and provide 2 implementations, one 32bit and one 64bit. You can have a factory method construct the appropriate instance of the class depending on the size of IntPtr.

    This allows an "AnyCPU" app to correctly, at runtime, determine which DLL to P/Invoke into, and does work.

提交回复
热议问题