Jump to content
  • Advertisement
Sign in to follow this  
ehmdjii

C# Interface, C++ Engine

This topic is 4813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, lately I often hear that the interface of an application is written using C# while the background graphics part is done with C++. Now I wonder, how can you combine these two languages? How do they communicate? What setup will I have to choose in VS? thanks!

Share this post


Link to post
Share on other sites
Advertisement
I've done this sort of stuff before using SDL before I found SDL.NET

How I get them to communicate is through using DLL's. C# can read and manipulate C++ DLL files similar to how C++ does so this might be a good place to start.

Share this post


Link to post
Share on other sites
Not fully true.
There are three ways to make use of "native" code

1) Use C DLLs ( .NET can call exported DLL functions that adhere to the C Naming conventions directly )
2) Use COM Interop ( one can consume COM objects and .NET generates a wrapper for you to call it )

3) MANAGED C++. You can write a Managed C++ DLL that calls unmanaged C++ classes pretty easily... so you can write a wrapper for your C++ code quite easily.. This is the most flexible approach but also requires the most work. I used that in several projects ant it works very nicely.... you would setup your project something like this:

C++ Library ( DLL or Static ) -> Your Native code
Managed C++ DLL Links to C++ Library and provides wrapper classes to call the unmanaged ones..

C# Project -> References Managed C++ DLL and calls the wrapper classes..

One can alos include unmanaged/native code directly in your Managed C++ DLL with the #pragma unmanaged directive... But i would only use that for short code parts, the three tier system is cleaner IMHO..

Hope that helps.

Share this post


Link to post
Share on other sites
thank you!

so if i choose the DLL version i basically have two seperate projects in VS? the background engine as C++ project compiled into a DLL and the frontend as C# project that makes calls of this DLL. right?

thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!