Solved

Run external program in my program

Posted on 1997-12-13
2
228 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 50 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

717 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