且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为 64 位系统上的 32 位系统崩溃而编译的 C# 程序和 C++ DLL

更新时间:2022-11-27 14:50:25

当与非托管代码互操作时,您需要确保您的 .Net 应用程序在同一子系统(32 位或 64 位)上运行.正如您所说,您正在加载的 DLL 适用于 x86,强制 .Net 仅针对 x86 平台构建.此设置位于项目的属性中,位于构建选项卡上.默认为任何 CPU,将设置更改为 x86 以匹配您的非托管 DLL,无论您是在 64 位还是 32 位操作系统上运行,您都应该没问题.

When interoping with unmanaged code, you need to ensure your .Net app runs on the same subsystem (32-bit or 64-bit). As you've stated the DLL you're loading is for x86, force the .Net to build for only the x86 platform. This setting is found in your project's properties, on the build tab. The default is any CPU, change the setting to x86 to match your unmanaged DLL and you should be fine regardless if you run on a 64-bit or 32-bit OS.