Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Jednostavni program !

[es] :: C programiranje :: Jednostavni program !

[ Pregleda: 2259 | Odgovora: 11 ]

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

bit_fucker
Planeta Zemlja ;)

Član broj: 12601
Poruke: 30
*.zre.sezampro.yu



Profil

icon Jednostavni program !07.09.2003. u 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
07.09.2003. u 20:12 

t3chX
Srđan Rajčević
Thessaloniki

Član broj: 2509
Poruke: 101
*.otenet.gr

Jabber: techx@elitesecurity.org


Profil

icon Re: Jednostavni program !08.09.2003. u 00:05
% man exec

za windows

MSDN pa blago meni system() ili sl.
If you want to get anywhere in your life, don't break the rules - make them !
08.09.2003. u 00:05 

idb
Ivan Bulic
Beograd

Član broj: 4436
Poruke: 380
*.hidmet.sr.gov.yu.

Sajt: www.hidmet.sr.gov.yu/lati..


Profil

icon Re: Jednostavni program !08.09.2003. u 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);

08.09.2003. u 09:06 

t3chX
Srđan Rajčević
Thessaloniki

Član broj: 2509
Poruke: 101
*.salonica.access.acn.gr

Jabber: techx@elitesecurity.org


Profil

icon Re: Jednostavni program !08.09.2003. u 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.
If you want to get anywhere in your life, don't break the rules - make them !
08.09.2003. u 11:28 

leka
Dejan Lekić
senior software engineer, 3Developers Ltd.
London, UK

Član broj: 234
Poruke: 2530
*.racasse.se

Sajt: dejan.lekic.org


Profil

icon Re: Jednostavni program !08.09.2003. u 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.
Dejan Lekic
software engineer, MySQL/PgSQL DBA, sysadmin
08.09.2003. u 12:41 

boccio
Boris Krstović
Spoonlabs.com
nbgd

Član broj: 7594
Poruke: 2425
*.vdial.verat.net

Sajt: boccio.me


Profil

icon Re: Jednostavni program !08.09.2003. u 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...
08.09.2003. u 14:48 

t3chX
Srđan Rajčević
Thessaloniki

Član broj: 2509
Poruke: 101
*.salonica.access.acn.gr

Jabber: techx@elitesecurity.org


Profil

icon Re: Jednostavni program !08.09.2003. u 14:55
Hm .. mislim da je leka mislio na neku drugu familiju exec* poziva :]]
If you want to get anywhere in your life, don't break the rules - make them !
08.09.2003. u 14:55 

leka
Dejan Lekić
senior software engineer, 3Developers Ltd.
London, UK

Član broj: 234
Poruke: 2530
*.racasse.se

Sajt: dejan.lekic.org


Profil

icon Re: Jednostavni program !08.09.2003. u 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).
Dejan Lekic
software engineer, MySQL/PgSQL DBA, sysadmin
08.09.2003. u 16:19 

Voodoo
Novi Beograd

Član broj: 3508
Poruke: 488
*.sr.gov.yu



Profil

icon Re: Jednostavni program !08.09.2003. u 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...
08.09.2003. u 17:22 

t3chX
Srđan Rajčević
Thessaloniki

Član broj: 2509
Poruke: 101
*.salonica.access.acn.gr

Jabber: techx@elitesecurity.org


Profil

icon Re: Jednostavni program !09.09.2003. u 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
If you want to get anywhere in your life, don't break the rules - make them !
09.09.2003. u 21:55 

Dragi Tata

Član broj: 1958
Poruke: 3899
199.171.112.*

Sajt: www.novetehnologije.com


Profil

icon Re: Jednostavni program !09.09.2003. u 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));
}


09.09.2003. u 22:18 

t3chX
Srđan Rajčević
Thessaloniki

Član broj: 2509
Poruke: 101
*.salonica.access.acn.gr

Jabber: techx@elitesecurity.org


Profil

icon Re: Jednostavni program !09.09.2003. u 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 :]
If you want to get anywhere in your life, don't break the rules - make them !
09.09.2003. u 22:37 

[es] :: C programiranje :: Jednostavni program !

[ Pregleda: 2259 | Odgovora: 11 ]

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.