Jump to content
  • Advertisement
Sign in to follow this  
visla

C++ classes in C# (Help)

This topic is 4617 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

Ok I want someone to help me by writing small peace of code. I have this problem. I made a class in C++. And this class is stored in .dll compiled. now I wish to inherit this class in C#, but have no idea how to do so. And also how am i supposed to call callbacks in this situation from c++. Main engine is written in C++ fully, and I want to use C# to make editors (it is much faster than in C++).

Share this post


Link to post
Share on other sites
Advertisement
You can't just derive a class in C# from a C++ class. That is, unless you wrote it in managed C++. If that's what you've done, simply reference the assembly and derive from the class as usual.

Share this post


Link to post
Share on other sites
Quote:
Original post by visla
Ok I want someone to help me by writing small peace of code.
I have this problem. I made a class in C++. And this class is stored in .dll compiled. now I wish to inherit this class in C#, but have no idea how to do so.

And also how am i supposed to call callbacks in this situation from c++.

Main engine is written in C++ fully, and I want to use C# to make editors (it is much faster than in C++).

Importing all that unmanaged code into a managed application space is going to seriously impact the benefits you get from running managed code (namely, garbage collection and the penalty for extra levels of method indirection). If you're still determined to do it this way, see this article and this one for how to get started.

Share this post


Link to post
Share on other sites
Sounds like a job for COM ;)

To my knowledge, the only way you're going to be able to write a class in C# and have it inherit from a C++ class is to write the C++ class as a COM component, and unless you have read about 500 MSDN articles on COM, its not going to be easy. But ask yourself, does it make sense to hava a C# inherit from a C++ class? What I would do, short of going the COM route, is look at the articles kSquared posted, start learning how to call functions in DLL's, and write a C# wrapper class for the exported functions you need.

That still might get you only have of the way though, and you're most likely going to have to rely on unsafe code in C# to help you through, so again, is it really faster to write it in C#? ;)

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!