如何從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