Skip to main content
gamedev.net
🔒 Locked

How to develop a software using multiple programming languages?

Started by EngineV May 5, 2005 at 9:22 PM 1 replies 750+ views
Original Post
EngineV
EngineV
Maybe a simple question. i heard that with .NET, we can develop a software using multiple programming languages(i.e. Visual Basic & C#). For me, i've never tried that, i have only developed several small program using only one progarmming language. I know that every language supporting .NET will be interpreted into the CLR(common language runtime), that's the foundation of develop one software with multiple languages. What i do not know is how did .NET do it, what in detail should we developers do? For an example, a friend & i r developing a software together, my friend developed one part of the software using C++, and i developed the other part using C#. how do i "combine" them? Thx!
Everything is meaningless
turnpast
turnpast
Quote:
Original post by EngineVFor an example, a friend & i r developing a software together, my friend developed one part of the software using C++, and i developed the other part using C#. how do i "combine" them? Thx!


Well that depends. Did your friend write his portion in managed C++? If he did than the interop should be fairly standard: you can load his assemblies and call into them or he can load yours. If he did not: the interop problem is a little more complicated. You can use P/Invoke from a managed language to access legacy code in a dll, but it can be a lot of work if the api you are accessing complex. Pinvoke also can introduce quite a bit of overhead. As for unmanaged C++ accessing managed code: I have not heard of any way to do this reliably.

It is also important to note that managed languages (like C#) can contain features that are not CLR compliant and this can complicate the interop process. Some examples are unsigned integer types and generics in C#.
Lenolian
Lenolian
If your friend is using managed C++, he will create a dll assembly (lets call it friendAssembly.dll). In your C# project, add a reference to this dll, and thats all. You can now work with what he did.

If he has written it in native C++, its a bit more complicated. Either you use PInvoke(DllImport) in C# to get access to his functions, but this is slow and not always doable. The other way is to make a managed wrapper to the native C++ code. Lets say your friend have made a class, like this :

class A{  public:      A() {};      ~A() {};  public:      bool DoStuff(void);};


To port it into managed world, you wrap a pointer to this class, and you can use it like the first way i mentionned above :

public ref class ManagedA{  private:     A* m_NestedPtr;  public:     ManagedA() { m_NestedPtr = new A(); }     ~ManagedA() { delete m_ NestedPtr; }  public:     bool DoStuff(void) { return m_NestedPtr->DoStuff(); }};


Well you will have a lot more work if you use virtual functions and such but its doable.

Quote:

It is also important to note that managed languages (like C#) can contain features that are not CLR compliant and this can complicate the interop process. Some examples are unsigned integer types and generics in C#.


You can use generic in C++/CLI too, so its not a problem.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.