9 Replies - 2677 Views - Last Post: 10 June 2009 - 07:16 PM

#1 chris772   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 190
  • Joined: 13-March 09

Using multiple languages for one program

Posted 09 June 2009 - 05:38 PM

I have googled this topic before, but I haven't come up with many answers on if using multiple languages will slow a program or have any effect. My question is simply if a single program could utilize different languages.

For example (odd, but someone could have a need to), use assembly to test hardware, C# for sockets, and C++ for GUI.

Would you have to make a smaller program as a launcher for the satellite programs, or could they just be linked together somehow?

Is This A Good Question/Topic? 0
  • +

Replies To: Using multiple languages for one program

#2 AdaHacker   User is offline

  • Resident Curmudgeon

Reputation: 463
  • View blog
  • Posts: 820
  • Joined: 17-June 08

Re: Using multiple languages for one program

Posted 09 June 2009 - 06:45 PM

View Postchris772, on 9 Jun, 2009 - 06:38 PM, said:

For example (odd, but someone could have a need to), use assembly to test hardware, C# for sockets, and C++ for GUI.

You could do that, but why would you want to?

It depends on what you mean, but in general, yes, it's possible to mix languages within a single program. In fact, if you count using a library written in one language from another, then the vast majority of programs actually do this. It's also possible to embed interpreters for other languages, run separate executables written in another language, and various other things. It all depends on the languages and environment you're talking about.
Was This Post Helpful? 0
  • +
  • -

#3 chris772   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 190
  • Joined: 13-March 09

Re: Using multiple languages for one program

Posted 09 June 2009 - 08:25 PM

Because I can work with sockets in C#, but I am still getting the hang of them in C at the moment. How would I bring those C# libraries into C++?

For example, System.Text and System.Net.Sockets are not in C++.

I am using VC++ 2008 Express by the way (on Windows of course).
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6747
  • View blog
  • Posts: 31,231
  • Joined: 10-May 07

Re: Using multiple languages for one program

Posted 09 June 2009 - 08:27 PM

My experience with multiple languages would be to write a function or functionality in the language that you know best, compile it as a DLL, & it is now distributable & able to be used with whatever language you want to write the Front End in.

This was usually the case when a buddy of mine, & me would collaborate on projects. I would write functionality in C or ASM & compile it as a DLL, & then he would work on the front end in VB6 (it was years ago) & we'd be up & running in half the time.
Was This Post Helpful? 0
  • +
  • -

#5 Core   User is offline

  • using System.Linq;
  • member icon

Reputation: 784
  • View blog
  • Posts: 5,101
  • Joined: 08-December 08

Re: Using multiple languages for one program

Posted 09 June 2009 - 08:35 PM

Quote

For example, System.Text and System.Net.Sockets are not in C++.


Those are available in Visual C++, as it uses the same .NET classes. Make sure you declare them this way:

	using namespace System::Text;
	using namespace System::Net::Sockets;



Also, make sure you have the needed references. Just right click the project and select References.

And by the way, language interoperability is one of the core concepts of the .NET platform.
Was This Post Helpful? 0
  • +
  • -

#6 RudiVisser   User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,566
  • Joined: 05-June 09

Re: Using multiple languages for one program

Posted 10 June 2009 - 06:28 AM

I've developed several applications that use multiple languages.

A good example would be my DLL injector, it had a native injection DLL written in C++ that my C# GUI would utilise. Worked great and really simple to use, saves having to find a way to inject DLLs with C# :)
Was This Post Helpful? 0
  • +
  • -

#7 sbromley   User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 127
  • Joined: 20-May 09

Re: Using multiple languages for one program

Posted 10 June 2009 - 07:40 AM

I remember as a project for school we had to put java swing gui's on our C routines. I can't for the life of me remember what the java library was called that linked the C routines to the Java code though.
Was This Post Helpful? 0
  • +
  • -

#8 chris772   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 190
  • Joined: 13-March 09

Re: Using multiple languages for one program

Posted 10 June 2009 - 03:30 PM

Well it seems very feasible to me now, but how did all of you link the libraries together? I know now that C# just uses .NET, but what about other languages?
Was This Post Helpful? 0
  • +
  • -

#9 RudiVisser   User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,566
  • Joined: 05-June 09

Re: Using multiple languages for one program

Posted 10 June 2009 - 03:57 PM

View Postchris772, on 10 Jun, 2009 - 02:30 PM, said:

Well it seems very feasible to me now, but how did all of you link the libraries together? I know now that C# just uses .NET, but what about other languages?

If you're writing something native such as C/C++ then you can just "extern" the methods and import them like any other native call from C#, DllImport.
Was This Post Helpful? 0
  • +
  • -

#10 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Using multiple languages for one program

Posted 10 June 2009 - 07:16 PM

Using functionality written in different languages is quite common and happens all the time. When I was a kid I programmed in QBasic and then used assembly to extend -- later I used C to help build a graphics library for it.

I have written several Java extension in C++ and just for fun I have called java functions from C (IMO that is a strange way to go... but it works).

Generally one builds up to an application so writing assembly, and C/C++ routines for C# is a natural progression.

You CAN use C# functions form C++ (esp. VC++) but like calling java functions from C its just a little odd...

Point is -- Yes you can write heterogeneous applications and in point of fact it is done very often.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1