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.
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);
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.
Potpis
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...
Potpis
Jeff, one day you’ll understand that it’s harder to be kind than clever.
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).
Potpis
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...
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
Potpis
If you want to get anywhere in your life, don't break the rules - make them !
/***
*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
*
*******************************************************************************/
/***
*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 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. */
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 :]
Potpis
If you want to get anywhere in your life, don't break the rules - make them !