[ bit_fucker @ 07.09.2003. 20:12 ] @
Pozdrav, Pocetnik sam u C++ -u, pa me zanima kako da napravim jednostavni programcic iz kojeg ce se startovati druge aplikacije. Svaka pomoc je dobrodosla. Hvala |
[ bit_fucker @ 07.09.2003. 20:12 ] @
[ t3chX @ 08.09.2003. 00:05 ] @
% man exec
za windows MSDN pa blago meni system() ili sl. [ idb @ 08.09.2003. 09:06 ] @
Ako je u pitanju Windows onda....
ShellExecute()-Izvod iz Helpa: ============================== The ShellExecute function opens or prints a specified file. The file can be an executable file or a document file. .... HINSTANCE ShellExecute( HWND hwnd, // handle to parent window LPCTSTR lpOperation, // pointer to string that specifies operation to perform LPCTSTR lpFile, // pointer to filename or folder name string LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters LPCTSTR lpDirectory, // pointer to string that specifies default directory INT nShowCmd // whether file is shown when opened ); Evo ti par primera kako ih ja koristim (mozda ima i bolji nacin): 1. OTRVARANJE neke Help fajle sa InternetExplorerom: //.... char HelpFile[MAX_PATH]; // pa negde u programu imas na primer: strcpy(HelpFile,"c:\\My_dir\\My_Help.HTML"); //.... ShellExecute(NULL, "open", "IEXPLORE.EXE", HelpFile,NULL,SW_SHOWNORMAL); 2. Ili ako ces pozvati neki svoj program bez prosledjivanja parametara: //.... char My_prog_exe[MAX_PATH]; // pa negde u programu imas na primer: strcpy(My_prog_exe,"c:\\My_dir_exe\\My_prog_x.exe"); //.... ShellExecute(hwnd,NULL, My_prog_exe, NULL, NULL, SW_SHOWNORMAL); [ t3chX @ 08.09.2003. 11:28 ] @
Code: #include <iostream> using namespace std; int main() { char putanja[50]; strcpy(putanja,"c:\\avipreview.exe"); system(putanja); return 0; } Sasvim lepo radi. [ leka @ 08.09.2003. 12:41 ] @
ShellExecute() se preporucuje. System() ne radi sve sto treba da radi na Win*owsu... Naravno tu je i exec*() kompanija za ljude kojima treba neki drugi nacin.
[ boccio @ 08.09.2003. 14:48 ] @
ruku na srce meni i CreateProcess() jako lepo radi...cak ga i vise koristim nego ShellExec...a sto se tice exec-a (WinExec i ostalo) to se cisto koristi zarad kompatibilnosti sa 16-bitnim windozom... U principu za startovanje procesa najcesce se koriste ShellExecuteEx() i CreateProcess() jer pruzaju maximalnu kontrolu aplikacije koju zelis da pozoves...
[ t3chX @ 08.09.2003. 14:55 ] @
Hm .. mislim da je leka mislio na neku drugu familiju exec* poziva :]]
[ leka @ 08.09.2003. 16:19 ] @
Da, mislio sam na familiju exec*() sistemskih poziva, koji su tu, bice tu i ostace tu ako Microsoft zeli da prati standard(e) (jer se exec*() nalaze u vise standarda).
[ Voodoo @ 08.09.2003. 17:22 ] @
e ako je sad taj dechko neshto razumeo, blago njemu... :)))
i shta se shirite sa MSDN-om, u srbiji ga imaju obojica poshto ostalih 99% ljudi ima onu piratsku verziju na jednom disku... ja sam obishao sve zhive cd klubove dok su radili i niko nije imao... [ t3chX @ 09.09.2003. 21:55 ] @
Usput jedno pitanje vezano za ovu temu:
Leka rece da system() ne radi sve kako treba. Da li je system() na Windowsu ekvivalent UNIX-ovom pozivu system(), tj. da li i on poziva CreateProcess() (posto UNIX-ov system() poziva fork() pa execv()) izvrsavajuci program iz zadate putanje ili je nesto drugo u pitanju ? Ako je to slucaj, onda ne vidim neopravdanost pozivanja system-a umesto CreateShell-a. Zahvaljujem [ Dragi Tata @ 09.09.2003. 22:18 ] @
Microsoftov system.c:
Code: /*** *system.c - pass a command line to the shell * * Copyright (c) Microsoft Corporation. All rights reserved. * *Purpose: * defines system() - passes a command to the shell * *******************************************************************************/ #include <cruntime.h> #include <process.h> #include <io.h> #include <stdlib.h> #include <errno.h> #include <tchar.h> #include <dbgint.h> /*** *int system(command) - send the command line to a shell * *Purpose: * Executes a shell and passes the command line to it. * If command is NULL, determine if a command processor exists. * The command processor is described by the environment variable * COMSPEC. If that environment variable does not exist, try the * name "cmd.exe" for Windows NT and "command.com" for Windows '95. * *Entry: * char *command - command to pass to the shell (if NULL, just determine * if command processor exists) * *Exit: * if command != NULL returns status of the shell * if command == NULL returns non-zero if CP exists, zero if CP doesn't exist * *Exceptions: * *******************************************************************************/ int __cdecl _tsystem ( const _TSCHAR *command ) { int catch; _TSCHAR *argv[4]; argv[0] = _tgetenv(_T("COMSPEC")); /* * If command == NULL, return true IFF %COMSPEC% * is set AND the file it points to exists. */ if (command == NULL) { return argv[0] == NULL ? 0 : (!_taccess(argv[0],0)); } _ASSERTE(*command != _T('\0')); argv[1] = _T("/c"); argv[2] = (_TSCHAR *) command; argv[3] = NULL; /* If there is a COMSPEC defined, try spawning the shell */ if (argv[0]) /* Do not try to spawn the null string */ if ((catch = (int)_tspawnve(_P_WAIT,argv[0],argv,NULL)) != -1 || (errno != ENOENT && errno != EACCES)) return(catch); /* No COMSPEC so set argv[0] to what COMSPEC should be. */ argv[0] = ( _osver & 0x8000 ) ? _T("command.com") : _T("cmd.exe"); /* Let the _spawnvpe routine do the path search and spawn. */ return((int)_tspawnvpe(_P_WAIT,argv[0],argv,NULL)); } [ t3chX @ 09.09.2003. 22:37 ] @
Znači nešto je takvo u pitanju, jer je CreateProcess() odradjen u cmd.exe.
Čini mi se da je ovo dupli posao. Ipak je bolje direktno pozivati gorenavedenu funkciju :] Copyright (C) 2001-2025 by www.elitesecurity.org. All rights reserved.
|