![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Professional Programmer
|
C++ to C# vice versa
I don't know if this is supposed to be in the C# forum or C++ because its a question for both, but C++ seems to get more attention so i'll post here.
Lets say i have a program coded in C#. The program consists of a gui, with a single button with the name hello. Now over here, i have a C++ program, it is written as a console app though, with a command that displays the word "hello" on your desktop, in a window. What i want to do is "combine" the C# gui program's button with the C++ console app's hello command so that when you click on the "hello" button in the C# program, the C++ program will run, and execute the hello command, If the C++ program is already running though, i don't want it to run another instance, just execute the command on the C++ app thats already running. Thanks. p.s might as well include in here, if anyone knows where a good tutorial for running console programs in the backround or maybe if theres just a simple code needed, that would be appreciated.. i will look around though.
__________________
▄▄▄▄ Quote:
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it. Download Code::Blocks now! ▄▄▄▄ |
|
|
|
|
|
|
#2 |
|
Programmer
|
In C#, use the Process to launch that app.
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace WindowsApplication1 { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Diagnostics.Process HelloProc = new System.Diagnostics.Process(); private System.Windows.Forms.Button button1; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); HelloProc.StartInfo.FileName = "hello.exe"; } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(192, 104); this.button1.Name = "button1"; this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void button1_Click(object sender, System.EventArgs e) { bool RunIt = true; try { RunIt = HelloProc.HasExited; } catch{} if(RunIt) { try { HelloProc.Start(); } catch{} } } } } Chi |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Please see the forum rules regarding the use of code tags.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 |
|
Programmer
|
Please could you post a link to them (forum rules...I don't see a link on the home page for them)? I didn't realize I had to do something special in order to post here. Also...why can't I edit that post?
Found em:http://www.programmingforums.org/for...#faq_faq_rules These should really be accessible from the homepage.... |
|
|
|
|
|
#5 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5
![]() |
There is also a sticky post "How to post a question" at the top of the C++ forum, which discusses how to ask a question to increase your chances of getting a useful answer. Th fact you didn't use code tags suggests you didn't bother to read that either.
In any event, the question (and answer given) are really C# specific. The mechanisms by which a C# program will execute another program are C# specific. |
|
|
|
|
|
#6 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
as to editing, you only have a certain amount of time after you've posted to edit. this is for correcting minor errors or adding a stement or so. it prevents totally recanting and/or invalidating all subsequent posts.
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
#7 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5
![]() |
Quote:
Occasionally, after looking through a thread, I pick up minor errors in my past posts (eg in a code example, setting a flag to true when it should be set to false) that have not been picked up and discussed to death in subsequent posts by others. It would be nice to be able to fix those even if I pick them up a month after the original post. Tough balance, I know. Distinguishing between minor corrections and complete recanting of previous information, a month after the fact, would be difficult for even a human moderator to pick up. |
|
|
|
|
|
|
#8 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|