Combining C# with C++ in a single project [closed] - c#

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I am assigned a project in which there are two parts :
Database Programming
Game Programming
I am incharge of Database programming and my partner the later. But I am friendly with C-sharp Database programming as it is very efficient using Visual Studio. But he has a Game experience in C++.
Our target system is Windows 7,database will be Sql Server Database, and game can be in C or C++.
We will have a link in Windows forms that starts the Game.
How do we solve this problem without changing our partners?

From a technical point of view it is possible to write a project in multiple languages. From a practical standpoint it is not a good idea.
If this is a small project that will not be enhanced and will be write once and forget then it is fine, otherwise not.
You don't necessarily need to change partners, one of you just needs to step up and say they will jump the learning curve. As a programmer you need to be able to work in whatever language is required.
There are many factors that decide which language/library to use. Write them down with the pros and cons and decide which makes the most sense for your application. Agree that once this is settled then the topic will not come back up. Maybe find an neutral arbitrator that you can both elect to decide for you.
A partner is more than their ability to write code in a given language. The coding part is a small part of the project.

I suggest looking at Managed c++ and the /clr compilation switch for c++. Using managed c++ you can expose what you need to the .net world using .net objects where appropriate, but use native c/c++ code internally.
Managed c++ also have alot of ways to integrate efficiently with .net, such as object pinning (no relocation by the gc)
c++ compiled with /clr can be consumed from any .net language like a regular .net assembly. c++ code compiled this way can also consume any .net assembly much like the other .net languages do.

You haven't provided much details about this game but can't you Process.Start the Game from your WinForms application and passing it the necessary parameters that you fetched from the database?

Another option would be to wrap the database in a COM object developed in .NET that the game, if written in C++ can consume.

I am working on a project right now (and recently completed a similar one) that combined C#, and C++ libraries using C++/CLI. The data collection and signal processing were all written in C++ (your game piece) and the forms, xml and plotting was all done in C# (your db piece). C++/CLI handled the impedance mismatch between the two languages. I actually ended up writing little more than a mediator class in C++/CLI (I find it much more pleasant to write in C#). I think this would work for you too. The only issue is that C++/CLI is not C++. In fact I would suggest that the C# programmer learn C++/CLI rather than the C++ programmer. My reasoning is that syntactical differences between the languages are rather trivial and the C# programmer can probably learn those faster than the the C++ programmer coming to grips to what managed code and .NET is all about. That said, if you both took responsibility for the C++/CLI piece you would have all the skill sets needed to tackle it with the minimum amount of pain.

Related

Unmanaged C# versus C++ [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am a wanna-be Games Developer and I prefer using C#. When I asked what the disadvantages of writing real-time applications in C# were I got 1 significant point back: Garbage Collection and the unpredictable impact it can have on performance.
My counter question is, what about Unmanaged C#? How does it compare (performance-wise) to C++? Is it a valid option for developing software?
I don't hear much about unmanaged c# and all the "unmanaged c# versus C++" questions I saw were unanswered or answered inaccurately. These questions were not on stack overflow.
EDIT:
I believe umanaged C# is "Unsafe Code".
Unsafe code in C# is not for developing separate applications. You can use unsafe code for some kind of time-critical operations, but generally it's not the most effective and the most convenient way of doing this. IMHO, it is primarily designed to give C# an opportunity to integrate with unmanaged dynamic link libraries and unmanaged code, so from my point of view the primary reason is INTEGRATION.
I can see 3 common ways of managed and unmanaged code integration:
Unsafe code in C# and P/Invoke. Build C# wrappers over compiled unmanaged DLLs.
Managed C++. Build managed assemblies over existing C/C++ code.
COM interoperation. Call Runtime Callable Wrapper from .NET client or call COM Callable Wrapper from COM client.
On the other hand, it's your architectural and conceptual decision: if you need a full memory and performance control, you develop in C++ or even pure C. If you need advantages and simplicity of modern language and modern technologies, you develop in .NET C#. Or you can use both, and how to integrate them is described above.
You can use C# to build games. The question is what exactly are you intending to do? What platforms do you intend to target, and how polished do you intend the finished product to be?
Others have mentioned Unity, which uses C# and provides a ready-made game engine and development suite. The only downside is that the free version has limitations.
If you want to build your own engine for the sake of understanding, look into XNA. Or you can use a wrapper around OpenGL like SharpGL. Or maybe you can find the long-dead Managed DirectX floating around somewhere. Or if you are really brave, you can use unsafe code and wrap GDI calls so that you don't have to deal with the horribly slow GDI+ implementation. The last two really aren't recommended, and only XNA is going to provide you more than a way to draw things on the screen. There are sure to be countless other possibilities, especially considering what becomes available to C# developers with Mono.
Whatever you decide, the garbage collector isn't going to get in your way, and unsafe code wouldn't be a solution if it did.
Edit:
As mentioned by cdoubleplusgood, XNA is no longer in active development. Look into Monogame and consider the wonders of cross-platform development a bonus.
For general purpose applications C# (managed) is a very suitable language with great performance. Unless you have extremely high demands you can certainly use it for games. Have a look at Unity:
Unity
Nevertheless, most AAA game studios use C++ as their main programming language. That being said, if you want a career in such studios you are better off investing some effort in C++.

Converting a C# engine into C++ for speed [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
So this is the situation right now:
I have a C# GUI project combined with a C# Engine project in the same solution. The GUI allows interaction with the user, some high level stuff etc. The functionality of the Engine is to communicate with another third-party application. The Engine has sockets that connect to the third-party application as well has methods to convert a message into an object, send it to the third-party application, and listen for a response from the third-party application and react accordingly. Data to be communicated between the Engine and the Third-party application are packaged into objects.
The problem with the C# engine is that it's too slow. So the idea is to convert the engine to unmanaged C++ for speed.
This is my plan of attack:
Translate the entire C# engine by hand into C++ (which is already pretty daunting because the C# engine includes threads and hashtables)
Have the following to substitute for constructors, accessors, and mutators in C++:
void* CreateInstance()
{
MyClass* p = new MyClass();
return p;
}
void ReleaseInstance(void* pInstance)
{
MyClass* p = (MyClass*)pInstance;
delete p;
}
int GetData(void* pInstance)
{
MyClass* p = (MyClass*)pInstance;
return p->GetData();
}
void SetData(void* pInstance, value)
{
MyClass* p = (MyClass*)pInstance;
p->SetData(value);
}
(The reason why I can't use real classes in C++ is because you can't instantiate C++ objects in C#)
Then build a C++ unmanaged DLL, use P/Invoke within the C# GUI project ([DllImport etc.]) to access all the C++ methods, and use that to replace the C# engine. Objects will be simulated using methods and passed back and forth between the C# GUI and C++ Engine.
Before I embark on this time-consuming task, is there any C# code that would be impossible to translate into C++ and then re-imported back into the C# GUI through this method?
There's not going to be any C# code that's impossible to translate into C++. You might want to look into if there are any library functions in .NET that aren't covered by the C++ libraries you'll be working with, though. Make sure you aren't getting stuck with any wheels to reinvent.
That said, in my practical experience real-world C++ code is not naturally faster than real-world C# code. It's true that a C++ programmer has more available tricks that can allow them to get better performance, but the effort involved in getting to that point can often be quite formidable. Consider the famous case of the competition between Rico Mariani and Raymond Chen. The advantage Chen's final version enjoyed over Rico's was ultimately down to just the time the .NET run-time needed to bootstrap itself. That's a bit of overhead that's negligible for a longer-running process.
So I would strongly encourage you to try spending some time with a performance profiler to see why the C# code is slow first, and what you can do to speed it up. It may very well be that by going that route you can get the code running fast enough for your needs with a fraction of the effort. It's amazing how impressive you can look just selecting better data structures.

Will a .cs file work in a .java software? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
So I'm thinking about making a GUI. My friend told me he knew how to do it in C#, so I went that method in setting the GUI up. Is there anyway to get a C# made GUI usable in java?
Yes you can. You absolutely should not.
I once wrote a perl application that used a VB GUI that i made, they communicated via OLE.
This is probably the worst construct you could ever do so don't :)
Not practically. You can't just give the C# compiler a Java file, or vice versa.
If you're really determined though, you can use IKVM to expose Windows Forms to Java.
There's also J# but it's not being actively developed anymore.
I think you should learn how to make a GUI in Java if you are coding in Java. However if you want both of C# and Java to interoperate, then you need a new layer which acts like a bridge between a C# program runs on CLR and Java program runs on JVM. The following link has a good explanation about how to call Java routines directly from a C# program over runtime bridges:
http://www.devx.com/interop/Article/19945/1954
You need to bind something on GUI with an appropriate logic. Such as File>New menu selection might exist for creating a new file. Therefore this menu command needs to be bound to a logic. You can not run away without writing these logic, the event handlers or without defining some other functionalities inside of GUI classes. Strictly speaking, you always need to write a lot of code on presentation layer which consists of GUI classes. So that, your friend does also need to build up the presentation layer itself. Because a useless user interface is called a prototype not a program. And also do not forget about that runtime bridges significantly decrease the performance. Eventually, I suggest you to go and learn how to make GUI in Java.
No! It would not work. Java's GUI classes are different, so even if you renamed your .cs files to .java files and made slight modifications, the code would not work.
No. It won't work. You can't compile Java and C# into a single executable package.
No. The way Java and .NET interact with the GUI is totally different.

What are some advantages to the different programming languages? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have always had an interest in coding, and a while back a started to learn C#. Since I only do this as a hobby, i have been learning it very slowly and don't know too much yet, but when I started to read about C++ and how it runs closer to the OS, I started to wonder if I should start learning C++ instead. I know html and JavaScript pretty well and to me C# seemed to be somewhat similar to js, so it wasn't to hard. I just downloaded C++ Express and noticed it is in a very different style than what I'm used to. I'm wondering if I should stick with c# or try c++ (especially if I want to start playing with Arduino sometime in the future). What are some advantages/ disadvantages to both?
As a person who has done all of these languages professionally, I would say that C# is probably the easiest to learn while still being very powerful. There is a lot of help for the .NET platform both from the libraries standpoint and from the community as well. Unless you really want to get down and dirty with a language, stick with C#.
The bigger answer, however, is "it depends". If you are looking to learn a language for the sake of learning one, C# is the way to go. However, if you are thinking about possibly using this new skill in a job setting, look for what type of job you want and decide from there. If you are looking to build applications for yourself and your friends, stick with C#. You can build a Winforms app in about five minutes and you can scale to larger and more professional apps easily from there. C++ will be much more difficult to do the same with.
Coming from Javascript, I would probably recommend staying with C# if you don't want to get down and dirty with details. It will take care of memory management and several other low-level concerns that C++ makes you deal with manually, so it's a little less of a shock to go from an interpreted scripting language like Javascript or Python or Ruby to C#. It's kinda half-way between them and C++.
That said, if you want to learn more of how programming languages and computers in general work, go for C++. It's more complicated than C#, but learning C++ very well makes any language you learn after that easy. Plus with C++, there's virtually no limit to what you can do (C# imposes a few limits), and you pretty much have the entire computer with all its speed and resources at your disposal.
That said, C++ usually takes longer to do the same thing in. For instance, creating a Windows application with a GUI and everything would take a considerable amount of time in C++, but in C# it's trivial. It's a tradeoff you have to deal with, but like I said, if you learn C++ first, C# is cake. The converse is not necessarily true though.
If you want to work with Arduino, go for C++ (never worked with Arduino but the code snippets looked like C so..). C++ is very similar to C, and most C will compile as C++ with very little modification.

CAD/CAM without C++ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Is it possible to do CAD/CAM software without having to use C++? My company developed their software with c/C++ but that was more than 10 years ago. Today,there is a lot of legacy code that switching would force us to get rid of but i was wondering what the actual risks are. We have a lot of mathematical algorithms for toolpath calculations, feature recognition and simulation and 3D Rendering and i was wondering if C# can handles all of that without great performance loss.
Is it a utopia to rewrite such algorithms in c# or should that language only deal with UI.
We are not talking about game development here (Halo 3 or Call Of Duty) so how much processing does CAD/CAM really need?
Can anybody enlighten me on this matter? Most of my colleagues are hardcore C++ programmers and although i program in c++ i love .NET but i am having a hard time selling .NET to them other than basic UI. Does it make sense to consider switching to .NET in such a field, or is it just not a wise idea?
Thank you
If you have a lot of legacy code that would need to be rewritten, I don't see it making business sense to switch to a different language. Even if there were gains to be had from using a different language (which is questionable), the cost of testing and debugging the new code would more than overcome them. You also have a development team that are experts in C++. There would be a big productivity drop while they came up to speed on the new language.
C# Can interop with C++ code. You can start writing new code in C# and have it call existing c++ code when needed. It wouldn't have to be just for UI. Look into C++/CLI and the C# Interop methods for information on how to use existing c++ code with new C# code.
Also, I asked a similar question here:
C# Performance For Proxy Server (vs C++)
CAD/CAM applications are fairly calculation intensive, and speed will definitely be one of the criteria for selecting a package, so I would be wary of moving to a slower language.
You need to think very carefully about the reasons for switching language. Is it because you don't like C++, or because C# will bring real benefits. It is quite likely to slow your application down. Check out the C++ C# speed comparisons.
Computer Language Benchmarks Game C++ vs C#
In my humble opinion, you'd be better off keeping all of the toolpath calculations in C++, and if you really must move any code over to another language, move it over to a scripting language which the user can easily edit, without re-compiling.
I use CAD/CAM applications every day at work, and there are a number of things in the UI which get on my nerves. They would be simple fixes if only I could get at the source.
If your company makes a CAD/CAM application which has a UI written in a scripting language which I can tweak (Lua, Python etc), I'll buy a copy.
Hugo
Have a look at pythonocc. Its provides you with a python module that wraps the OpenCASCADE CAD kernel. OpenCASCADE is the sole industry strength open source kernel I'm aware of. Nice features are STEP and IGES support and the ability to generate FEM meshes from BRep data.
Another thing you need to consider is platform independence - if there is a possibility that you/you company need to migrate your CAD software to Linux/Unix (Of course, for bussiness decision), it will be quite painful. Currently, even C++ with MFC/Win32 calls gave us many headache...
The Open Design Alliance library is cross-platform. They have recently introduced a beta of the .NET version of their library. See my answer to Open source cad drawing (dwg) library in C# for more details.
Having said that I concur with the other answers here - if it ain't broken, don't fix it, both the code and the coders. MSFT still use C++, as does the ODA - their codebase originates in C++ & is wrapped for .NET.

Categories