Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Run external program in my program

Posted on 1997-12-13
2
Medium Priority
?
233 Views
Last Modified: 2010-04-10
Dear
      I want to run an external program in my window
      program, for example Mshearts.exe.      
      Using WinExec, I don't know the parameter
      Would you give me the answer or coding?


void CDeliverDlg::OnScheduleButton()
{
      // TODO: Add your control notification handler code here
      WinExec("Mshearts.exe",??);
}
0
Comment
Question by:logout
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 100 total points
ID: 1176208
Use the parameter you would use for ShowWindow: i.e. SW_SHOWNORMAL.

0
 

Expert Comment

by:dlong121497
ID: 1176209
Heres a way to start a program and either wait for to complete or continuing with the main process:

/************************************************************/
/* Execute a (DOS) command string or start a windows module */
/* The flag 'waitforit' causes the parent program to wait   */
/* until execution of the child completes if it is true.    */
/* otherwise the child is started and run concurrently.     */
/* The funtion returns the instance handle of the child.    */
/************************************************************/

HINSTANCE Cexecute_command(int waitforit,char *s)
   {
   unsigned int retval;
   int          r,inlist;
   LPSTR        com_str[256];
   char         ts[256];
   FILE         *ff;

#ifdef __WIN32__

   PROCESS_INFORMATION pi;
   STARTUPINFO         si;
   DWORD               exitcode;

#else

   TASKENTRY    lpte;
   HINSTANCE    task_instance;

#endif

   lstrcpy(com_str,s);

#ifndef __WIN32__

   task_instance=WinExec(com_str,SW_SHOWNORMAL);

   if(!waitforit)
      {
      return(task_instance);
      }

   /* Wait until the task has disappeared from the task list */

   lpte.dwSize=sizeof(TASKENTRY);
   while(TRUE)
      {
      inlist=FALSE;
      retval=TaskFirst(&lpte);
      if(!retval) break;                         /* If no first task, something is wrong */
      if(lpte.hInst==task_instance) inlist=TRUE;
      while((lpte.hNext)&&(!inlist))             /* Already found or still looking */
         {
         retval=TaskNext(&lpte);
         if(!retval) break;
         if(lpte.hInst==task_instance)
            {
            inlist=TRUE;
            break;
            }
         }
      if(!inlist) break;
      }
   return(task_instance);

#else

   /* Initialise the 'startup info' structure */

   si.cb=sizeof(si);
   si.lpReserved=NULL;
   si.lpDesktop=NULL;
   si.lpTitle=NULL;
   si.dwX=0;
   si.dwY=0;
   si.dwXSize=0;
   si.dwYSize=0;
   si.dwXCountChars=0;
   si.dwYCountChars=0;
   si.dwFillAttribute=0;
   si.dwFlags=0;
   si.wShowWindow=0;
   si.cbReserved2=0;
   si.lpReserved2=NULL;
   si.hStdInput=0;
   si.hStdOutput=0;
   si.hStdError=0;

   r=CreateProcess(NULL,
                   com_str,
                   NULL,
                   NULL,
                   FALSE,
                   (DWORD)NULL,
                   NULL,
                   NULL,
                   &si,            // Startup info
                   &pi);

   if(waitforit)
      {
      while(TRUE)
         {
         GetExitCodeProcess(pi.hProcess,&exitcode);
         if(exitcode != STILL_ACTIVE) break;
         }
      }
   return((HINSTANCE)0);
#endif
   }

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

636 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