سؤال

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.

هل كانت مفيدة؟

المحلول

When calling native methods, you should compile your c# code to 64 or 32 bit explicitely.

 project/properties/build/Platform target

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top