I have made a very simple Dll like this:
extern \"C\"
{
__declspec(dllexport) int Try(int v)
{
return 10 + v;
}
}
Then I want to use
The default calling convention in C and C++ is __cdecl
; the default calling convention used by .NET P/Invoke is __stdcall
-- you need to reconcile these two.
Either make your native function __stdcall
, as Hans suggested:
__declspec(dllexport) int __stdcall Try(int v)
Or make your managed P/Invoke signature use __cdecl
:
[DllImport("TestLib.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int Try(int v);