C++ DllImport in Xamarin.Forms

How can I import my C++ DLLs [DllImport] into a Xamarin.Forms such that the common methods can be pinvoke from iOS and Android apps.

Answers

  • adamkempadamkemp USInsider, Developer Group Leader mod

    In general, calling C++ code directly from C# (or really just about any other language) is impractical because the symbols are mangled in order to avoid ambiguous symbols (imagine two methods in two classes with the same name or just two overloads with different arguments). The basic approach to overcoming this is to create wrapper functions in C (using extern "C") and P/Invoke into the C wrappers. There are also utilities like SWIG that can automate much of that process for you, and I know that some people here on the forums have had success using that approach.

Sign In or Register to comment.