Changing a C# delegate's calling convention to CDECL

Solution 1:

By default the p/invoke system wraps your delegate in a stdcall function. You can change the generated wrapper's calling convention by using the UnmanagedFunctionPointer attribute:

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void MyDelegate();