简体   繁体   English

pinvoke c函数-System.BadImageFormatException

[英]pinvoke c function - System.BadImageFormatException

Im trying to call a C function from C# but im getting a BadImageFormatException. 我试图从C#调用C函数,但是却收到BadImageFormatException。

Here is by C function header: 这是通过C函数头:

extern "C"
{
    __declspec(dllexport) bool validate(char key[]);
}

Here is how im calling it from C# 这是即时通讯从C#调用的方式

[DllImport("MyDll.dll")]
static extern bool validate(char[] key);

Whats wrong here. 怎么了

Use Dependency Walker to check if 'validate' function is correctly exported from DLL. 使用Dependency Walker检查'validate'函数是否从DLL中正确导出。 You might have not updated the .def file of the DLL project. 您可能尚未更新DLL项目的.def文件。

调用本地方法时,应将c#代码显式编译为64或32位。

 project/properties/build/Platform target

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM