BelledonneCommunications / linphone-xamarin

Linphone.org mirror for linphone-xamarin (git://git.linphone.org/linphone-xamarin.git)
https://www.linphone.org/
GNU General Public License v3.0
26 stars 21 forks source link

Explicitly set CallingConvention to CDecl in DllImport:s #11

Closed anders9ustafsson closed 6 years ago

anders9ustafsson commented 6 years ago

When including the C# wrapper in a .NET Framework library a runtime error PInvokeStackImbalance occurs whenever a P/Invoke call is being made.

The error is apparently due to improper P/Invoke calling conventions, where for .NET Framework the convention defaults to WinApi/StdCall instead of the correct CDecl convention (see this StackOverflow answer).

To circumvent this problem, for any platform regardless of calling convention default, my suggestion is to explicitly set the calling convention in all [DllImport] decorations, e.g. like this:

[DllImport(LinphoneWrapper.LIB_NAME, CallingConvention = CallingConvention.Cdecl)]
Viish commented 6 years ago

commit 7229c77fb422b385995cdbe65e40fd1c59541a8e Author: Sylvain Berfini sylvain.berfini@belledonne-communications.com Date: Mon Jul 23 10:48:06 2018 +0200

Merged pull request #80 from github