String^ help

Hi im learning c++ and i want to create a windows form application that basically you can type in the file name then click a button that runs the file. Everything will be in the same directory. I was wondering if you guys could get me started. =)
Last edited on
So you want to write a command line?

1
2
3
4
5
6
7
8
#include <string>
#include <iostream>

int main(){
   std::string input;
   std::getline(std::cin, input);
   system(input.c_str());
}

(silly and not tested)
Last edited on
Basically i want to create a program the can run other programs through it.
Say you want to be able to start ventrilo.
You would then type ventrilo.exe into the text field, then click a button to launch the program.
I think this is possible im just not sure how to code it.
I also dont want to use the "system" code as it hangs up the program until cancelled.

This is what i have but i dont want to use this anymore, the button runs the program directly rather then typing the name into the text field, not exact either but you get the point.

1
2
3
4
5
6
#include <process.h>
#include "resource.h"

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			 system("ventrilo.exe");
}
Last edited on
Well, you could use CreateProcess: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
I don't know anything about C++/CLI, so I can't help much. If you have a textbox, you should be able to extract a string from it whenever the button is pressed.
Ok so i figured out how to CreateProcess.. now i need help stringing textbox text to the button.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
                               //Need textBox1 to require user input and string contents to szExe[] ? Not sure
                               		 }
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                              
                                STARTUPINFO          si = { sizeof(si) };
				PROCESS_INFORMATION  pi;
				char                 szExe[] = "textBox1->text"; // uhmm lol ?? Need help

				if(CreateProcess(0, szExe, 0, 0, FALSE, 0, 0, 0, &si, &pi))
                {
				 CloseHandle(pi.hProcess);

				 CloseHandle(pi.hThread);
		 }
}


I need to figure out how to string textbox into this.I'm stuck here if any can help.
Last edited on
Well, textBox1.Text() should return a System::String of the text, I think. You want a char* here. I think it might be better not to mix .NET and WinAPI libraries. Try replacing CreateProcess with http://msdn.microsoft.com/en-us/library/53ezey2s.aspx
For a reference, search msdn. For more basic questions, find yourself a C++ CLI tutorial.
Ok, I still need help with this String^ code.

1
2
3
4
5
6
7
private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
                    //
		 }
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
	String^ myTextBox = // Need help figuring out how to string from textBox1 to here
        Process::Start( myTextBox );
Last edited on
Did you try textBox1.Text()? Or maybe ->? I knot know C++ CLI.
Ok Hamsterman!! You are my savior! This works now thank you very much sir!

1
2
3
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
		    String^ myTextBox = textBox1->Text;
                    Process::Start( myTextBox );


Last edited on
Topic archived. No new replies allowed.