How to make communicate Xamarin app with my engine written in C++ with cocos2d-x

JulienGomesJulienGomes FRDeveloper Group Leader

Hi everyone,

I have an app, written in Objective-C, that communicates with an engine written in c++ with cocos2d-x. It works well, even if I had to made some tricks to send message to the engine to the native app, and to send messages from the engine to the native app.
I want now to port this app to Xamarin, and I'm wondering if it's possible to make an app written with Xamarin communicate (back and forth) with my engine written in C++ ?

Thanks !



  • adamkempadamkemp USInsider, Developer Group Leader mod

    To call C code from C# you use P/Invoke. For calling C++ you should make a C wrapper for your API and then call the C wrapper. That's because C++ is much more complicated to call, and there are too many different incompatible implementations (i.e., different C++ compilers can't even necessarily call code that the others compiled).

    For calling back into C# you can decorate callback functions as described in this post.

    Our VirtualBench app has a C++ driver layer that is written in C++, and these are the techniques we used for communicating between C# and C++.

  • SKallSKall USMember ✭✭✭✭

    If C wrapper isn't feasible then you could use Swig:

  • JulienGomesJulienGomes FRDeveloper Group Leader

    Thanks for your answers, you didn't mention cocos2d-x so I think it wont be an issue. I will test it and keep you updated then.

    Thank you.

Sign In or Register to comment.