I am currently looking into an interop related issue and have written a small test program in order to help me figure out what is going on (the issue in question involves a call
You need to specify a correct calling convention. Default calling convention for C/C++ programs is cdecl, but default calling convention when importing through the PInvoke is StdCall. So you either need to specify the Cdecl
convention when importing or __stdcall
when exporting. For example:
[DllImport("Interop.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void Foo( int i );
private void Test()
{
Foo( 1 );
}