Sockets and GUIs and forms, oh my
So i've been thrown in the deep end this year with regards to what i'm expected to be able to program, and have come up against a rather large brick wall. I have some data being gathered by a C++ program, and I need to display this information in the form of a simple GUI. To be specific, the C++ program is taking the raw MIDI data from a MIDI drum and presenting it in a form that doesn't hurt my head, i.e, "this pitch was played with this velocity".
I have next to no experience with C#, although I had heard that with a decent knowledge of C++ it isn't too hard to migrate to (not that i'd call my knowledge of C++ decent myself but meh), but one thing it DOES do really well is forms. I was able to assemble a nice GUI in C# in literally under a minute.
The problem, if you haven't already spotted it, is that I need to get the information from one to the other, from the C++ program to the GUI. I can see a couple of ways of going about this:
1. Use the C# GUI and find out how to use sockets to transfer the data.
2. Screw C# and learn how to make a GUI in C++
In other words, I need to know which is going to be less taxing on a woefully underprepared 3rd year student brain; learning to program a GUI in C++, or learning to use sockets in both C++ and C#. I'm leaning towards 1, as i'm probably going to have to interface the original C++ program with something else eventually anyway.
I have no clue how to actually use sockets besides the fact that i'll need the windows SDK (which I now have) and that it involves something called Winsocks. I also wouldn't object if anyone just happens to have a link to a very nice tutorial on either of these subjects somewhere written in nice noob-friendly language, but just knowing which solution is more practical would be a start. What would YOU do?
You guys rule, as always.
Nil
I have next to no experience with C#, although I had heard that with a decent knowledge of C++ it isn't too hard to migrate to (not that i'd call my knowledge of C++ decent myself but meh), but one thing it DOES do really well is forms. I was able to assemble a nice GUI in C# in literally under a minute.
The problem, if you haven't already spotted it, is that I need to get the information from one to the other, from the C++ program to the GUI. I can see a couple of ways of going about this:
1. Use the C# GUI and find out how to use sockets to transfer the data.
2. Screw C# and learn how to make a GUI in C++
In other words, I need to know which is going to be less taxing on a woefully underprepared 3rd year student brain; learning to program a GUI in C++, or learning to use sockets in both C++ and C#. I'm leaning towards 1, as i'm probably going to have to interface the original C++ program with something else eventually anyway.
I have no clue how to actually use sockets besides the fact that i'll need the windows SDK (which I now have) and that it involves something called Winsocks. I also wouldn't object if anyone just happens to have a link to a very nice tutorial on either of these subjects somewhere written in nice noob-friendly language, but just knowing which solution is more practical would be a start. What would YOU do?
You guys rule, as always.
Nil
Comments
Were I in your situation, I would look into a c++ GUI library like <a href="http://www.codeproject.com/cpp/winevent.asp" target="_blank">this</a>. I have no idea as to its relative quality, but something similar to that.
however, <a href="http://www.devarticles.com/c/a/C-Sharp/Socket-Programming-in-C-Part-I/" target="_blank">Here</a> is a section on socket programming in c# should you go the opposite route.
<a href="http://www.eggheadcafe.com/articles/20020323.asp" target="_blank">Here's what I used</a>. I'm using VB, so this is a VB tutorial, but it's not at all difficult to adapt it to C#. The syntax is similar. <a href="http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx" target="_blank">Here's</a> something that converts VB to C#, too.
But if I'm not mistaken, you can use Visual Studio for C++, can't you? That should include a GUI builder similar to C#.
Anyway, you could also write the sockets part in C++ and compile it to a COM DLL, then use PInvoke in C# to call the DLL's functions to pass data back and forth.
[EDIT:] By the way, you should consider moving to C# or VB entirely. It's way better than C++, unless you need absolutely the best performance out of your program (like for a video game), or you're deploying to people who can't install the .NET Framework on their computer. Or if you need portability. Mono isn't quite perfect yet.
But if I'm not mistaken, you can use Visual Studio for C++, can't you? That should include a GUI builder similar to C#.
<!--QuoteEnd--></div><!--QuoteEEnd-->
Yes, you're right, and i'm an idiot for not noticing that before. This will save me quite a lot of time, thanks!
*edit* Except now I have to figure out how to pass values between two projects in the same solution... any ideas?
You should be able to pretty easily recompile your existing code as managed C++ and then build your GUI in the same project. Managed C++ definitely has its issues though. For example debugging is incredibly slow (although this may be improved in Visual Studio 2005).
There are other ways of having pieces of code talk together other than using sockets. The nicest in this case is probably to recompile your C++ application as a DLL and then you communicate between them using function calls. Even with C# it shouldn't be very hard to get this to work as long as your DLL API only includes simple types that don't require your to mess with the garbage collector.
Another way to have two separate programs communicate is using pipes. These may be a bit easier than trying to use sockets since you don't have as much setup to do. If you search for "interprocess communication" you should find more information on this.
Max
<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt__pipe.asp" target="_blank">C++ pipes</a> (basic documentation, this won't help all that much)
It's been a long time since I worked with pipes so... I'll just stop there.
I made a video example for you in VB. I doubt it works exactly this way in pure C++, but it should be the same thing in managed C++. This takes the more object-oriented approach to it. The video uses XviD, and it looks a little funky because I had to resize it. It's 4.92 MB, and you can get it <a href="http://www.brainferrets.com/other/DLLCommunicationExample.avi" target="_blank">here</a>.
Basically, you add two projects to the solution. One regular EXE, and one class library. You do whatever you need to do in the class library, using public functions and methods for data exchange and such (You can overload the New sub to have it start working as soon as you create the object). Then you add a reference to the class library in the EXE's properties, and create the object you made in the class library. Then you just call the functions and methods from that as you need to.
It sounds pretty complicated, but it's probably easier than learning how to use pipes.