Jump to content
  • Advertisement
Sign in to follow this  

mixing programming languages

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

Im just wondering what exactly is possible in mixing and what is commonly done. Im asking because I have a game engine finished in c++ using(supporting)DirectX/OpenGL/Win32/SDL(the engine consists of multiple dll's). Now Im wondering wether it would make any sense to convert it to say C# in order to make a c# game, or is there absolutely no issue in writing a c# dll that is loaded by the c++ engine?? What about Longhorn, will my current dll's still hold as good? -CProgrammer

Share this post


Link to post
Share on other sites
Advertisement
There probably are major issues calling C# DLLs from C++ and vice-versa. but I'm sure there is documentation on how to do it somewhere. If you have nowhere to turn, take a look at this site: The Code Project. It is similar to GameDev.net but is oriented towards Windows apps, MFC, .NET, and C#.

Share this post


Link to post
Share on other sites
Microsoft's newer compilers have a good deal of cross-compatibility between mutliple languages, allowing you to freely intermix C++, C#, Visual Basic, etcetera.

For the rest of us Microsoft haters/open source junkies/broke students, the options are more limited. Open source CLI compilers/libraries are still comming into maturity.

Even further back than common bytecode targets, however, there has been some compatable languages. There's the obvious C and C++ - C++ can call functions from a C API (and vicea versa, assuming the C++ function isn't mangled (read: extern "C") and takes only builtin types/pointers as arguments).

I've heard combining C++ and Python is also somewhat common - considering there's support for it in the boost library I'm inclined to suspect that whoever/wherever I heard that from was/is correct.

However, these interminglings require a more "hands on" approach. To spit out the quick start example:

Hello World

Following C/C++ tradition, let's start with the "hello, world". A C++ Function:

char const* greet()
{
return "hello, world";
}

can be exposed to Python by writing a Boost.Python wrapper:

#include <boost/python.hpp>
using namespace boost::python;

BOOST_PYTHON_MODULE(hello)
{
def("greet", greet);
}

That's it. We're done. We can now build this as a shared library. The resulting DLL is now visible to Python. Here's a sample Python session:

>>> import hello
>>> print hello.greet()
hello, world

Share this post


Link to post
Share on other sites
It's perfectly possible.

In my previous game, we had our engine written in C++, sitting upon COM, and all the editors written in C#.

However, what really makes me angry is not mixed-language environment, but a lack of standard for object-format for C++ compilers (ie I can't use a DLL compiled with Visual C++ in Borland C++Builder, unless that DLL contains C-functions only, which is really annoying!)

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!