如何从C++ DLL调用函数?C#接口C++ DLL?
的C++ DLL包含功能是这样的:
__declspec(dllexport) bool Setup() { return simulation.Setup(); }
的C#程序执行此:
[DllImport("mydll.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Setup();
的C#程序崩溃并显示以下消息,当它试图加载DLL(?) :
An unhandled exception of type 'System.BadImageFormatException' occurred in TestFrame.exe
Additional information: There was an attempt to load a file with a wrong format (exception from HRESULT: 0x8007000B)
The C++ DLL is a standard DLL (no MFC, no ATL).
64位.NET程序集尝试加载32位本机.dll?反之亦然? – 2010-09-29 20:40:29
谷歌翻译为'尝试加载格式不正确的程序。 (来自HRESULT的异常:0x8007000B)' – SLaks 2010-09-29 20:40:40
这是在64位操作系统上吗?如果.NET应用程序编译为AnyCPU并且C++ dll为32位,则dll将不会加载。 – 2010-09-29 20:41:19