?
Solved

WinExec does not start application

Posted on 1999-11-22
4
Medium Priority
?
5,613 Views
Last Modified: 2013-12-26
I am using BC452 and wrote some code that should start GNUPlot with a plot file. I give the full path for the program and the full path for the plot file. When I start to run this the first time GNUPlot does not start. After I execute a FileOpenSelectBox to choose a plot file it works fine. It seems like it needs some directory information that is not initialy there. How can I get this to work?
0
Comment
Question by:amau
  • 3
4 Comments
 

Author Comment

by:amau
ID: 2227286
here the code I use for the select box and the aplication to run.

//
// Execute *.plt files
//
void TFEMWorkMDIClient::CmExecutePlt()
{
      FileData.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|
                    OFN_SHAREAWARE;
   FileData.SetFilter("GNUPlot Files (*.plt)|*.plt|All Files (*.*)|*.*|");
   FileData.InitialDir = (char *)Settings.DataPath.c_str();

   int but = TFileOpenDialog(GetApplication()->MainWindow, FileData).Execute();
   if(but==IDOK)
   {
      string cmdLine;
      string msgBoxTitle;
      string msgBoxText;

      // cmdLine = "C:\\Progra~1\\Gnuplot\\WGnuplot.exe ";
      cmdLine = Settings.PlotPath + Settings.PlotApp;
      cmdLine += " "; // separator
      cmdLine += FileData.FileName;

      int   result = WinExec(cmdLine.c_str(), SW_SHOWNORMAL);
      if((result>=0)&&(result<=32))
      {
         switch (result)
         {
            case 0:  msgBoxTitle = "ERROR: Out of memory"; break;
            case 2:  msgBoxTitle = "ERROR: File not found"; break;
            case 3:  msgBoxTitle = "ERROR: Path not found"; break;
            default: msgBoxTitle = "ERROR: Error in WinExec"; break;
         }
         msgBoxText = "Command line:\n";
         msgBoxText += cmdLine;
         ::MessageBox(GetActiveWindow(), msgBoxText.c_str(), msgBoxTitle.c_str(), MB_OK);
      }
   }
}

//
// Run the GNU Plot for Profile
//
void TFEMWorkMDIClient::CmAnimProfTemp()
{
   int   but=::MessageBox(GetActiveWindow(),
                          "Animate Temperature Profile?",
                          "Run GNUPlot", MB_OKCANCEL);

   if(but==IDOK)
   {
      string cmdLine;
      string msgBoxTitle;
      string msgBoxText;

      // cmdLine = "C:\\Progra~1\\Gnuplot\\WGnuplot.exe data\\TempSimu.plt";
      cmdLine = Settings.PlotPath + Settings.PlotApp;
      cmdLine += " "; // separator
      cmdLine += Settings.MeshPltPath + "TempSimu.plt";

      int   result = WinExec(cmdLine.c_str(), SW_SHOWNORMAL);
      if((result>=0)&&(result<=32))
      {
         switch (result)
         {
            case 0:  msgBoxTitle = "ERROR: Out of memory"; break;
            case 2:  msgBoxTitle = "ERROR: File not found"; break;
            case 3:  msgBoxTitle = "ERROR: Path not found"; break;
            default: msgBoxTitle = "ERROR: Error in WinExec"; break;
         }
         msgBoxText = "Command line:\n";
         msgBoxText += cmdLine;
         ::MessageBox(GetActiveWindow(), msgBoxText.c_str(), msgBoxTitle.c_str(), MB_OK);
      }
   }
}
0
 
LVL 4

Accepted Solution

by:
Oliver_Dornauf earned 20 total points
ID: 2234197
Use ShellExecute

0
 

Author Comment

by:amau
ID: 2236635
Obviously I tried this one already, but I get the same problem using ShellExecute(). The path names are definitely correct, since it works once the OpenSelectBox was called once. Otehr tahn this it would be nice if I could see a working ShellExecute() sample. The one in the online help is not quite understandable.
0
 

Author Comment

by:amau
ID: 2242603
Hello, I tried it again with ShellExecute(). Now it worked just fine. So thanks anyways.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

592 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question