04-21-2012, 11:20 PM
put the code for example in a button
on
C#
add first
using System.Diagnostics;
....
// Starting the programm
private void start_Click(object sender, EventArgs e)
{
//Starting the exe
if (File.Exists("Bin\\Nksp.exe"))
{
Process Nksp = new Process();
Nksp.StartInfo.FileName = "Bin\\Nksp.exe";
Nksp.StartInfo.Arguments = "4022";
Nksp.Start();
this.close();
}
}
C++
void RunApplication(LPCTSTR FileName, LPCTSTR FileParam)
{
int ret = (int) ShellExecute(NULL, "open", FileName, FileParam, NULL, SW_SHOWNORMAL);
if (ret <= 32)
{
AnsiString msg;
switch(ret)
{
case ERROR_FILE_NOT_FOUND, SE_ERR_FNF :
msg = "File " + AnsiString(FileName) + " not found!";
break;
case ERROR_PATH_NOT_FOUND, SE_ERR_PNF :
msg = "Directory " + AnsiString(FileName) + " not found!";
break;
case ERROR_BAD_FORMAT :
msg = "The application is broken or cant run!";
break;
case SE_ERR_ACCESSDENIED, SE_ERR_SHARE :
msg = "Der Zugriff auf die Datei " + AnsiString(FileName) + " wurde vom Betriebssystem verweigert!";
break;
case SE_ERR_ASSOCINCOMPLETE, SE_ERR_NOASSOC :
msg = "Der angegebene Dateityp ist auf Ihrem Computer keiner Anwendung zugeordnet!";
break;
case 0, SE_ERR_OOM :
msg = "To run this Application u have not enough memory space!";
break;
default : msg = "Data " + AnsiString(FileName) + " could not opened!";
}
Application->MessageBox(msg.c_str(), "ERROR", MB_OK + MB_ICONERROR);
}
}
// Here is the button
void __fastcall TForm1::Button_StartClick(TObject *Sender)
{
AnsiString FileName = "Bin\\Nksp.exe";
AnsiString Parameter = "4022";
RunApplication(FileName.c_str(), Parameter.c_str());
// Close the Application
this->Close();
}

