• Martes 7 de Mayo de 2024, 20:27

Autor Tema:  Llamar A Un Programa Ejecutable En Windows  (Leído 1102 veces)

pacogonzalez61

  • Nuevo Miembro
  • *
  • Mensajes: 2
    • Ver Perfil
Llamar A Un Programa Ejecutable En Windows
« en: Domingo 22 de Febrero de 2004, 12:45 »
0
Como desde un programa en  o C++ en Windows puedo llamar a otro programa
ejecutable tambien de Windows . Por ejemplo en MSDOS cuando quiero llamar a
un progrma ejecutables escribo la función system "PROGRAMA.EXE".
Como soy nuevo en c** en Winddow. como puedo hacerlo.
Gracias.

Ruben3d

  • Miembro HIPER activo
  • ****
  • Mensajes: 710
  • Nacionalidad: es
    • Ver Perfil
    • Web personal
Re: Llamar A Un Programa Ejecutable En Windows
« Respuesta #1 en: Domingo 22 de Febrero de 2004, 13:56 »
0
Hola.

Lo que pides puedes hacerlo de dos formas: mediante CreateProcess o mediante spawn. Aqui te dejo un ejemplo de cada uno, sacado de MSDN:

Creating a process in Windows using CreateProcess
Código: Text
  1.  
  2. #include <windows.h>
  3. #include <process.h>
  4. #include <stdio.h>
  5.  
  6. void main()
  7. {
  8.     STARTUPINFO    si;
  9.     PROCESS_INFORMATION  pi;
  10.  
  11.     GetStartupInfo(&si);
  12.  
  13.     printf("Running Notepad with CreateProcess\n");
  14.     CreateProcess(NULL, "notepad",  // Name of app to launch
  15.   NULL,      // Default process security attributes
  16.   NULL,      // Default thread security attributes
  17.   FALSE,      // Don't inherit handles from the parent
  18.   0,      // Normal priority
  19.   NULL,      // Use the same environment as the parent
  20.   NULL,      // Launch in the current directory
  21.   &si,      // Startup Information
  22.   &pi);      // Process information stored upon return
  23.  
  24.     printf("Done.\n");
  25.     exit(0);
  26. }
  27.  
  28.  

Creating a process in Windows using spawn
Código: Text
  1.  
  2. #include <windows.h>
  3. #include <process.h>
  4. #include <stdio.h>
  5.  
  6. void main()
  7. {
  8.     printf("Running Notepad with spawnlp\n");
  9.     _spawnlp( _P_NOWAIT, "notepad", "notepad", NULL );
  10.  
  11.     printf("Done.\n");
  12.     exit(0);
  13. }
  14.  
  15.  

Espero que te sirva.

Un saludo.

Ruben3d