WinExec does not start application

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?
amauAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

amauAuthor Commented:
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
Oliver_DornaufCommented:
Use ShellExecute

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
amauAuthor Commented:
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
amauAuthor Commented:
Hello, I tried it again with ShellExecute(). Now it worked just fine. So thanks anyways.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.