add.c
Code:
#include "add.h"
int ADDCALL Add(int a, int b)
{
return (a + b);
}
add.h
Code:
#ifdef ADD_EXPORTS
#define ADDAPI __declspec(dllexport)
#else
#define ADDAPI __declspec(dllimport)
#endif
/* Define calling convention in one place, for convenience. */
#define ADDCALL __cdecl
Command first
gcc -c -DBUILDING_EXAMPLE_DLL add.c -D ADD_EXPORTS
Command second
gcc -shared -o add.dll add.o -Wl,--out-implib,libadd.dll
Then, in C# caller
Code:
[DllImport("libadd.dll")]
publicstaticexternintAdd (inta, intb);
I've got an exception BadImageFormat when I'm trying to execute intsum=Add(1,2);
What's going wrong?