Do you want to write ANSI C++? Or are you willing to use the Microsoft variant of C++ for managed code called C++/CLI? (CLI stands for Common Language Interface, not what most *nix folks assume to stand for Command Line Interface.)
Alternatively, you have your C++ code expose a COM object, and the C# code can interact with the COM object.
And yet another alternative is to compile your C++ code as DLL and expose entry points into the DLL which can be called by P/Invoke (Platform Invoke).
The way you wrote your post, it sounds like you want to display c++ source code in a window when a button is clicked. Is that what you mean?
Process.Start()
to run your HelloWorld.exe.Stop and think about the UI impedance mismatch of your planned C# form, and your hypothetical console C++ code. Do you intend the button to open up a console window and have the "Hello, World" show up in the console window? If some, then just compile the C++ "Hello World" console program as a .EXE as you normally would, and then have your C# form button handler useProcess.Start()
to run your HelloWorld.exe.
I want to write ANSI C++
Hmm. So, you want to make a reference to the C++ exe and call its functions directly, like invoking unmanaged Windows functions (Platform Invoke (P/Invoke)) from managed (.net) code (which SD already covered)..
I noted you said this:
Why do you want this hybrid approach? You’re writing some C++ code so you can call it from C#, which you’re also writing? What is the purpose of splitting it up? Why not write all in one or all in the other language?
In general, you can write ANSI C++ code, and compile it into an assembly taking advantage of Microsoft's IJW (It Just Works). My understanding is that Microsoft does this itself in various of is products where they don't want to completely rewrite larger swathes of its code base. You will still have deal with the places where the C# and the C++ code will talk to each other, but say least that narrows down the amount of specialized code you would need to write.
I know that I can do all of these stuffs with C# easily
Hello,
Thank you again for your reply.
Excuse me, can you teach me this with a simple "Hello World!"? If possible, an article, a video or...
Excuse me, can you teach me this with a simple "Hello World!"? If possible, an article, a video or...
This is a C# forum. It's not for us to teach you how to write C++ code. If you have working C++ code, we can help you invoke it from C# code. To actually learn how to write C++, there are places dedicated to that on the web.