简体   繁体   中英

Using c# code from a native c++ application

I am working on a basic 2D C++ Game engine but i want to be able to use C# to make games with it like unity does but I'm not sure how to do it. I've seen people saying about CLI but not sure exactly how that works. I want to be able to access functions on the engine in C# and be able to have the engine run the C# code.

Thanks for any help with this.

Right now you have two big ways of doing this:

  1. Make your C# application generate COM objects which you can consume from C++. Performance is a bit iffy, but doable and very simple.

  2. Use reverse PInvoke, where you export functions from your C++ application with in function pointers that you fill in from the C# side with delegates to the functions that drive your code.

In.Net 5, there's a third way: you can directly export C# functions from your assemblies to be consumed in a platform-independent way, like in C++ (ie, .dll or.so exports).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM