Como abrir una aplicacion desde C++.

Diego
02 de Marzo del 2002
Me gustaría saber como abrir el Winamp desde C++ Builder.
Tambien querría saber como introducir un retardo en el programa de unos 3 segundos.
Gracias.

jrmullor
02 de Marzo del 2002
_execv, _wexecv
Load and execute new child processes.

int _execv( const char *cmdname, const char *const *argv );

int _wexecv( const wchar_t *cmdname, const wchar_t *const *argv );

Function Required Header Optional Headers Compatibility
_execv <process.h> <errno.h> Win 95, Win NT
_wexecv <process.h> or <wchar.h> <errno.h> Win NT

cmdname

Path of file to execute

argv

Array of pointers to parameters

Remarks

Each of these functions loads and executes a new process, passing an array of pointers to command-line arguments.

Example

/* EXEC.C illustrates the different versions of exec including:
* _execl _execle _execlp _execlpe
* _execv _execve _execvp _execvpe
*
* Although EXEC.C can exec any program, you can verify how
* different versions handle arguments and environment by
* compiling and specifying the sample program ARGS.C. See
* SPAWN.C for examples of the similar spawn functions.
*/

#include <stdio.h>
#include <conio.h>
#include <process.h>

char *my_env[] = /* Environment for exec?e */
{
"THIS=environment will be",
"PASSED=to new process by",
"the EXEC=functions",
NULL
};

void main()
{
char *args[4], prog[80];
int ch;

printf( "Enter name of program to exec: " );
gets( prog );
printf( " 1. _execl 2. _execle 3. _execlp 4. _execlpen" );
printf( " 5. _execv 6. _execve 7. _execvp 8. _execvpen" );
printf( "Type a number from 1 to 8 (or 0 to quit): " );
ch = _getche();
if( (ch < '1') || (ch > '8') )
exit( 1 );
printf( "nn" );

/* Arguments for _execv? */
args[0] = prog;
args[1] = "exec??";
args[2] = "two";
args[3] = NULL;

switch( ch )
{
case '1':
_execl( prog, prog, "_execl", "two", NULL );
break;
case '2':
_execle( prog, prog, "_execle", "two", NULL, my_env );
break;
case '3':
_execlp( prog, prog, "_execlp", "two", NULL );
break;
case '4':
_execlpe( prog, prog, "_execlpe", "two", NULL, my_env );
break;
case '5':
_execv( prog, args );
break;
case '6':
_execve( prog, args, my_env );
break;
case '7':
_execvp( prog, args );
break;
case '8':
_execvpe( prog, args, my_env );
break;
default:
break;
}

/* This point is reached only if exec fails. */
printf( "nProcess was not execed." );
exit( 0 );
}


Espero que esto te sirva para solventar tu problema.