简体   繁体   中英

pinvoke c function - System.BadImageFormatException

Im trying to call a C function from C# but im getting a BadImageFormatException.

Here is by C function header:

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

Here is how im calling it from 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. You might have not updated the .def file of the DLL project.

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

 project/properties/build/Platform target

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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