begin process at 2008 08 08 21:40:21
1 223 607 membres
365 nouveaux aujourd'hui
14 230 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

GESTION DES SERVICES WINDOWS PAR LES API DANS UNE CLASSE


Information sur la source

Catégorie :API Classé sous : process, service, api Niveau : Initié Date de création : 02/06/2006 Date de mise à jour : 02/06/2006 22:14:29 Vu : 4 343

Note :
Aucune note

Commentaire sur cette source (4)
Ajouter un commentaire et/ou une note

Description

Pour les amateurs de programmations systèmes;
voici un code source intéressant (du moin pour moi)pour contrôler le fonctionnement d'un service ou process
sur pc local ou distant:
-Apprentissage d'insertion de variable environnement (getenv)dans le code (Nom du pc local dans le constructeur par défaut).
-Service STOP-START-RESTART (distant-local).
-Exemple d'un lancement d'une commande système par le biais de son programme (system).
-Lancement d'une commande d'un process de sont programme 'pskill'.
Rem:par le biais d'un prog externe (psexec.exe) il y a moyen de lancer des commandes système sur d'autres pc.

NB:Ce code n'est qu'a titre d'exemple pour donner des idées à la programmation C/C++
pas pour dire cela est le meilleur code - à bonne entendeur salut!
j'accepte toutes les remarques valables au niveau programmation pour l'évolution.
Ceci à été placé dans une classe pour démonstartion d'un code autre que procédurale.
Code à la fin pour tester la classe (reamon est un process d'antivirus n'oublié pas de le changer
pour vos tests).
A+

Source

  • #include <windows>
  • #include <stdlib>
  • #include <iostream.h>
  • //--------------------------------------------------------
  • // DEBUT CLASSE SERVICE
  • //--------------------------------------------------------
  • class Cl_SVR {
  • protected:
  • string service;
  • string nompc;
  • int status;
  • SC_HANDLE hSCManager;
  • SC_HANDLE hService;
  • BOOL bServiceStatus;
  • BOOL bControlService;
  • BOOL bStartServices;
  • SERVICE_STATUS ServiceStatus;
  • void Status();
  • string getStatusString(int);
  • public: // Les données et les méthodes publiques.
  • Cl_SVR();
  • Cl_SVR(const char *,const char *);
  • ~Cl_SVR();
  • string StatusSVR();
  • void ChangeService(const char *);
  • void ChangePc(const char *);
  • string NomPc()const;
  • string Service()const;
  • void Stop();
  • void Start();
  • void ReStart();
  • void PsKill(const char *);
  • };
  • //--------------------------------------------------------
  • // FIN CLASSE SERVICE
  • //--------------------------------------------------------
  • //------------------------------------------------------------------------------
  • // FONCTION : Constructeur
  • // DESCRIPTION : Initialisation par défaut
  • //-------------------------------------------------------------------------------
  • Cl_SVR::Cl_SVR(): service("inort"), nompc("\\\\"){
  • nompc+=getenv("COMPUTERNAME");
  • Status();
  • }//end procedure
  • //------------------------------------------------------------------------------
  • // FONCTION : Constructeur
  • // DESCRIPTION : Initialisation par défaut
  • //-------------------------------------------------------------------------------
  • Cl_SVR::Cl_SVR(const char * s,const char * pc): service(s), nompc("\\\\"){
  • nompc+=pc;
  • Status();
  • }//end procedure
  • //------------------------------------------------------------------------------
  • // FONCTION : Destructeur
  • // DESCRIPTION : Destruction de l'objet
  • //-------------------------------------------------------------------------------
  • Cl_SVR::~Cl_SVR(){
  • }//end procedure
  • //------------------------------------------------------------------------------
  • // FONCTION : Service_Status
  • // DESCRIPTION : Permet de savoir le status de fonctionnement du service
  • // RUNNING,STOOPED,PAUSE,PENDING,etc....
  • //-------------------------------------------------------------------------------
  • void Cl_SVR::Status(){
  • //Fait la liaison avec le process manager des services
  • hSCManager = OpenSCManager(nompc.c_str(),NULL,SC_MANAGER_ALL_ACCESS);
  • if (hSCManager !=0){
  • hService = OpenService(hSCManager,service.c_str(),SERVICE_ALL_ACCESS);
  • //Connection avec le service
  • if (hService !=0){
  • //Demande le status du service
  • bServiceStatus = QueryServiceStatus(hService,&ServiceStatus);
  • switch(ServiceStatus.dwCurrentState){
  • case SERVICE_STOPPED:
  • status=0;
  • break;
  • case SERVICE_START_PENDING:
  • status=1;
  • break;
  • case SERVICE_STOP_PENDING:
  • status=2;
  • break;
  • case SERVICE_RUNNING:
  • status=3;
  • break;
  • case SERVICE_CONTINUE_PENDING:
  • status=4;
  • break;
  • case SERVICE_PAUSE_PENDING:
  • status=5;
  • break;
  • case SERVICE_PAUSED:
  • status=6;
  • break;
  • }//end switch
  • }else
  • status=7;
  • //end if
  • CloseServiceHandle(hService);
  • }//end if
  • CloseServiceHandle(hSCManager);
  • }//end process
  • //------------------------------------------------------------------------------
  • // FONCTION : Status
  • // DESCRIPTION : Renvoie le status de fonctionnement du service
  • //-------------------------------------------------------------------------------
  • string Cl_SVR::StatusSVR(){
  • return getStatusString(status);
  • }//end function
  • //------------------------------------------------------------------------------
  • // FONCTION : ChangeService
  • // DESCRIPTION : Change le nom du service
  • //-------------------------------------------------------------------------------
  • void Cl_SVR::ChangeService(const char *s){
  • service=s;
  • }//end function
  • //------------------------------------------------------------------------------
  • // FONCTION : ChangePc
  • // DESCRIPTION : Change le nom du pc
  • //-------------------------------------------------------------------------------
  • void Cl_SVR::ChangePc(const char * pc){
  • nompc=pc;
  • }//end function
  • //------------------------------------------------------------------------------
  • // FONCTION : NomPc
  • // DESCRIPTION : Renvoie le nom du pc
  • //-------------------------------------------------------------------------------
  • string Cl_SVR::NomPc()const{
  • return nompc;
  • }//end function
  • //------------------------------------------------------------------------------
  • // FONCTION : Service
  • // DESCRIPTION : Renvoie le nom du Service
  • //-------------------------------------------------------------------------------
  • string Cl_SVR::Service()const{
  • return service;
  • }//end function
  • //------------------------------------------------------------------------------
  • // FONCTION : Service_Stop
  • // DESCRIPTION : Permet d'arreter le fonctionnement d'un service.
  • //-------------------------------------------------------------------------------
  • void Cl_SVR::Stop(){
  • //Fait la liaison avec le process manager des services
  • hSCManager = OpenSCManager(nompc.c_str(),NULL,SC_MANAGER_ALL_ACCESS);
  • if (hSCManager !=0){
  • //Connection avec le service
  • hService = OpenService(hSCManager,service.c_str(),SERVICE_ALL_ACCESS);
  • if (hService !=0){
  • bControlService = ControlService(hService,SERVICE_CONTROL_STOP,&ServiceStatus);
  • if (bControlService != 0)
  • status=0;
  • //end if
  • CloseServiceHandle(hService);
  • }//End If
  • CloseServiceHandle(hSCManager);
  • }//End If
  • }//end function
  • //------------------------------------------------------------------------------
  • // FONCTION : Service_Start
  • // DESCRIPTION : Permet de demarrer un service.
  • //-------------------------------------------------------------------------------
  • void Cl_SVR::Start(){
  • //Fait la liaison avec le process manager des services
  • hSCManager = OpenSCManager(nompc.c_str(),NULL,SC_MANAGER_ALL_ACCESS);
  • if (hSCManager !=0){
  • //Connection avec le service
  • hService = OpenService(hSCManager,service.c_str(),SERVICE_ALL_ACCESS);
  • if (hService !=0){
  • bStartServices = StartService(hService,0,0);
  • if (bStartServices != 0)
  • status=3;
  • //end if
  • CloseServiceHandle(hService);
  • }//End If
  • CloseServiceHandle(hSCManager);
  • }//End If
  • }//end function
  • //------------------------------------------------------------------------------
  • // FONCTION : ReStart
  • // DESCRIPTION : Permet de restarter un service
  • //-------------------------------------------------------------------------------
  • void Cl_SVR::ReStart(){
  • //Fait la liaison avec le process manager des services
  • hSCManager = OpenSCManager(nompc.c_str(),NULL,SC_MANAGER_ALL_ACCESS);
  • if (hSCManager !=0){
  • //Connection avec le service
  • hService = OpenService(hSCManager,service.c_str(),SERVICE_ALL_ACCESS);
  • if (hService !=0){
  • //stop du service
  • bControlService = ControlService(hService,SERVICE_CONTROL_STOP,&ServiceStatus);
  • //Boucle d'attente de l'arret
  • do{
  • bServiceStatus = QueryServiceStatus(hService,&ServiceStatus);
  • }while(ServiceStatus.dwCurrentState != SERVICE_STOPPED);
  • //end do
  • status=0;
  • cout << "Service '" << service << "' est en état " << StatusSVR() << endl;
  • //start du service
  • bStartServices = StartService(hService,0,0);
  • //Boucle d'attente de demarrage
  • do{
  • bServiceStatus = QueryServiceStatus(hService,&ServiceStatus);
  • }while(ServiceStatus.dwCurrentState != SERVICE_RUNNING);
  • //end do
  • status=3;
  • cout << "Service '" << service << "' est en état " << StatusSVR() << endl;
  • CloseServiceHandle(hService);
  • }//End If
  • CloseServiceHandle(hSCManager);
  • }//End If
  • }//end function
  • //------------------------------------------------------------------------------
  • // FONCTION : PsKill
  • // DESCRIPTION : Renvoie le nom du Service
  • //-------------------------------------------------------------------------------
  • void Cl_SVR::PsKill(const char * proc){
  • string cmd;
  • cmd = "pskill -t " + nompc + " " + proc + " >log.txt";
  • system(cmd.c_str());
  • }//end function
  • //------------------------------------------------------------------------------
  • // FONCTION : PsKill
  • // DESCRIPTION : Renvoie le nom du Service
  • //-------------------------------------------------------------------------------
  • string Cl_SVR::getStatusString(int nStatus){
  • switch (nStatus){
  • case 0: return "Stopped";
  • case 1: return "Pending Start";
  • case 2: return "Pending Stop";
  • case 3: return "Running";
  • case 4: return "Pending Continu";
  • case 5: return "Pending Pause";
  • case 6: return "Paused";
  • default: break;
  • }//end switch
  • return "N\'exite pas";
  • }//end function
  • //------------------------------------------------------------------------------
  • // START PROGRAM TEST
  • //-------------------------------------------------------------------------------
  • void main(){
  • Cl_SVR p;
  • cout << p.StatusSVR() << endl;
  • p.Stop();
  • cout << p.StatusSVR() << endl;
  • // p.ReStart();
  • // p.Start();
  • // p.PsKill("Realmon.exe"); //Kill une application en mémoire(Seulement valable en local)
  • // system("Realmon.exe"); //relance l'application en mémoire(Seulement valable en local)
  • }//end programme
  • //------------------------------------------------------------------------------
  • // END PROGRAM TEST
  • //-------------------------------------------------------------------------------
#include <windows> 
#include <stdlib> 
#include <iostream.h> 
  
//-------------------------------------------------------- 
// DEBUT CLASSE SERVICE 
//-------------------------------------------------------- 
  class Cl_SVR { 
    protected: 
      string service; 
      string nompc; 
      int status; 
      SC_HANDLE hSCManager; 
      SC_HANDLE hService; 
      BOOL bServiceStatus; 
      BOOL bControlService; 
      BOOL bStartServices; 
      SERVICE_STATUS ServiceStatus; 
      void Status(); 
      string getStatusString(int);
   
    public: // Les données et les méthodes publiques. 
      Cl_SVR(); 
      Cl_SVR(const char *,const char *); 
      ~Cl_SVR(); 
      string StatusSVR(); 
      void ChangeService(const char *); 
      void ChangePc(const char *); 
      string NomPc()const; 
      string Service()const; 
      void Stop(); 
      void Start(); 
      void ReStart(); 
      void PsKill(const char *); 
  }; 
//-------------------------------------------------------- 
// FIN CLASSE SERVICE 
//-------------------------------------------------------- 
//------------------------------------------------------------------------------ 
// FONCTION : Constructeur 
// DESCRIPTION : Initialisation par défaut 
//------------------------------------------------------------------------------- 
  Cl_SVR::Cl_SVR(): service("inort"), nompc("\\\\"){ 
      nompc+=getenv("COMPUTERNAME"); 
      Status(); 
  }//end procedure 
  
//------------------------------------------------------------------------------ 
// FONCTION : Constructeur 
// DESCRIPTION : Initialisation par défaut 
//------------------------------------------------------------------------------- 
  Cl_SVR::Cl_SVR(const char * s,const char * pc): service(s), nompc("\\\\"){ 
      nompc+=pc; 
      Status(); 
  }//end procedure 
  
//------------------------------------------------------------------------------ 
// FONCTION : Destructeur 
// DESCRIPTION : Destruction de l'objet 
//------------------------------------------------------------------------------- 
  Cl_SVR::~Cl_SVR(){ 
  }//end procedure 
  
//------------------------------------------------------------------------------ 
// FONCTION : Service_Status 
// DESCRIPTION : Permet de savoir le status de fonctionnement du service 
// RUNNING,STOOPED,PAUSE,PENDING,etc.... 
//------------------------------------------------------------------------------- 
  void Cl_SVR::Status(){ 
  //Fait la liaison avec le process manager des services 
    hSCManager = OpenSCManager(nompc.c_str(),NULL,SC_MANAGER_ALL_ACCESS); 
    if (hSCManager !=0){ 
      hService = OpenService(hSCManager,service.c_str(),SERVICE_ALL_ACCESS); 
    //Connection avec le service 
      if (hService !=0){ 
      //Demande le status du service 
        bServiceStatus = QueryServiceStatus(hService,&ServiceStatus); 
        switch(ServiceStatus.dwCurrentState){ 
          case SERVICE_STOPPED: 
            status=0; 
            break; 
          case SERVICE_START_PENDING: 
            status=1; 
            break; 
          case SERVICE_STOP_PENDING: 
            status=2; 
            break; 
          case SERVICE_RUNNING: 
            status=3; 
            break; 
          case SERVICE_CONTINUE_PENDING: 
            status=4; 
            break; 
          case SERVICE_PAUSE_PENDING: 
            status=5; 
            break; 
          case SERVICE_PAUSED: 
            status=6; 
            break; 
        }//end switch 
      }else 
         status=7; 
      //end if 
      CloseServiceHandle(hService); 
    }//end if 
    CloseServiceHandle(hSCManager); 
  }//end process 
//------------------------------------------------------------------------------ 
// FONCTION : Status 
// DESCRIPTION : Renvoie le status de fonctionnement du service 
//------------------------------------------------------------------------------- 
  string Cl_SVR::StatusSVR(){ 
    return getStatusString(status); 
  }//end function 
//------------------------------------------------------------------------------ 
// FONCTION : ChangeService 
// DESCRIPTION : Change le nom du service 
//------------------------------------------------------------------------------- 
  void Cl_SVR::ChangeService(const char *s){ 
    service=s; 
  }//end function 
//------------------------------------------------------------------------------ 
// FONCTION : ChangePc 
// DESCRIPTION : Change le nom du pc 
//------------------------------------------------------------------------------- 
  void Cl_SVR::ChangePc(const char * pc){ 
    nompc=pc; 
  }//end function 
//------------------------------------------------------------------------------ 
// FONCTION : NomPc 
// DESCRIPTION : Renvoie le nom du pc 
//------------------------------------------------------------------------------- 
  string Cl_SVR::NomPc()const{ 
     return nompc; 
  }//end function 
//------------------------------------------------------------------------------ 
// FONCTION : Service 
// DESCRIPTION : Renvoie le nom du Service 
//------------------------------------------------------------------------------- 
  string Cl_SVR::Service()const{ 
     return service; 
  }//end function 
//------------------------------------------------------------------------------ 
// FONCTION : Service_Stop 
// DESCRIPTION : Permet d'arreter le fonctionnement d'un service. 
//------------------------------------------------------------------------------- 
  void Cl_SVR::Stop(){ 
  //Fait la liaison avec le process manager des services 
    hSCManager = OpenSCManager(nompc.c_str(),NULL,SC_MANAGER_ALL_ACCESS); 
    if (hSCManager !=0){ 
    //Connection avec le service 
      hService = OpenService(hSCManager,service.c_str(),SERVICE_ALL_ACCESS); 
      if (hService !=0){ 
        bControlService = ControlService(hService,SERVICE_CONTROL_STOP,&ServiceStatus); 
        if (bControlService != 0) 
          status=0; 
        //end if 
        CloseServiceHandle(hService); 
      }//End If 
      CloseServiceHandle(hSCManager); 
    }//End If 
  }//end function 
//------------------------------------------------------------------------------ 
// FONCTION : Service_Start 
// DESCRIPTION : Permet de demarrer un service. 
//------------------------------------------------------------------------------- 
  void Cl_SVR::Start(){ 
  //Fait la liaison avec le process manager des services 
    hSCManager = OpenSCManager(nompc.c_str(),NULL,SC_MANAGER_ALL_ACCESS); 
    if (hSCManager !=0){ 
    //Connection avec le service 
      hService = OpenService(hSCManager,service.c_str(),SERVICE_ALL_ACCESS); 
      if (hService !=0){ 
        bStartServices = StartService(hService,0,0); 
        if (bStartServices != 0) 
          status=3; 
        //end if 
        CloseServiceHandle(hService); 
      }//End If 
      CloseServiceHandle(hSCManager); 
    }//End If 
  }//end function 
//------------------------------------------------------------------------------ 
// FONCTION : ReStart 
// DESCRIPTION : Permet de restarter un service 
//------------------------------------------------------------------------------- 
  void Cl_SVR::ReStart(){ 
  //Fait la liaison avec le process manager des services 
    hSCManager = OpenSCManager(nompc.c_str(),NULL,SC_MANAGER_ALL_ACCESS); 
    if (hSCManager !=0){ 
    //Connection avec le service 
      hService = OpenService(hSCManager,service.c_str(),SERVICE_ALL_ACCESS); 
      if (hService !=0){ 
      //stop du service 
        bControlService = ControlService(hService,SERVICE_CONTROL_STOP,&ServiceStatus); 
      //Boucle d'attente de l'arret 
        do{ 
          bServiceStatus = QueryServiceStatus(hService,&ServiceStatus); 
        }while(ServiceStatus.dwCurrentState != SERVICE_STOPPED); 
        //end do 
        status=0; 
        cout << "Service '" << service << "' est en état " << StatusSVR() << endl; 
      //start du service 
        bStartServices = StartService(hService,0,0); 
      //Boucle d'attente de demarrage 
        do{ 
          bServiceStatus = QueryServiceStatus(hService,&ServiceStatus); 
        }while(ServiceStatus.dwCurrentState != SERVICE_RUNNING); 
        //end do 
        status=3; 
        cout << "Service '" << service << "' est en état " << StatusSVR() << endl; 
        CloseServiceHandle(hService); 
      }//End If 
      CloseServiceHandle(hSCManager); 
    }//End If 
  }//end function 
//------------------------------------------------------------------------------ 
// FONCTION : PsKill 
// DESCRIPTION : Renvoie le nom du Service 
//------------------------------------------------------------------------------- 
  void Cl_SVR::PsKill(const char * proc){ 
    string cmd;
    cmd = "pskill -t " + nompc + " " + proc + " >log.txt"; 
    system(cmd.c_str()); 
  }//end function 
  
//------------------------------------------------------------------------------ 
// FONCTION : PsKill 
// DESCRIPTION : Renvoie le nom du Service 
//------------------------------------------------------------------------------- 
  string Cl_SVR::getStatusString(int nStatus){
    switch (nStatus){
      case 0: return "Stopped";
      case 1: return "Pending Start";
      case 2: return "Pending Stop";
      case 3: return "Running";
      case 4: return "Pending Continu";
      case 5: return "Pending Pause";
      case 6: return "Paused";
      default: break;
    }//end switch
    return "N\'exite pas";
  }//end function
     
//------------------------------------------------------------------------------ 
// START PROGRAM TEST 
//------------------------------------------------------------------------------- 
  void main(){ 
   Cl_SVR p; 
    cout << p.StatusSVR() << endl; 
    p.Stop(); 
    cout << p.StatusSVR() << endl; 
// p.ReStart(); 
// p.Start(); 
// p.PsKill("Realmon.exe"); //Kill une application en mémoire(Seulement valable en local) 
// system("Realmon.exe"); //relance l'application en mémoire(Seulement valable en local) 
  
}//end programme 
//------------------------------------------------------------------------------ 
// END PROGRAM TEST 
//------------------------------------------------------------------------------- 
  

Conclusion

Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
Cl_SVR.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
pas d'erreur de compilation
02 juin 2006 22:14:30 :
Correction du code source suivant les bonnes remarques de excrt. J'espère qu'il sera content.
  • signaler à un administrateur
    Commentaire de excrt le 02/06/2006 17:49:12

    pour la Xeme fois

    #include <stdlib.h> // C
    #include <cstdlib> // C++
    #include <iostream.h> // BAD! sans .h << cette version est obsolète(elle existe encore pour une raison de compatibilité avec de ~vieux programmes)
    #include <iostream> // GOOD

    ta gestion des chaines de caractères est _Complètement_ nulle

    Cl_SVR::Cl_SVR(){
        service="\0"; // c'est un char*, pas d'allocation mémoire ni rien d'autre du genre
        strcat(service,"inort"); // ca va faire !!!CABOUME!!!
        nompc="\\\\"; strcat(nompc,getenv("COMPUTERNAME")); // ca aussi!
        Status();
    }//end procedure

    pourquoi est-ce que tu n'utiliserais pas les basic_string hein?

    #include <string>

    class Cl_SVR
    {
    // ...
    string service;
    string nompc;
    // ...
    };

    Cl_SVR::Cl_SVR() : service("inort"), nompc("\\\\")
    {
        nompc += getenv("COMPUTERNAME");
        Status();
    }//end procedure

    Cl_SVR::Cl_SVR(const char * s,const char * pc) : service(s), nompc("\\\\")
    {
        nompc += pc;
        Status();
    }//end procedure

    service.c_str() pour obtenir un pointeur sur la chaine

    const char* c_str() const {
      return un_pointeur_sur_la_chaine;
    }


    etc...
    etc...
    etc...

    void Cl_SVR::PsKill(const char * proc)
    {
      //char * cmd = new (char[100]);
      char cmd[100+1]; // si tu ne veux pas libérer la mémoire alors pas de « new » !
      snprintf(cmd, 100, "pskill -t %s %s >log.txt", nompc, proc);
      //strcpy(cmd,"\0");
      //strcat(cmd,"pskill -t ");
      //strcat(cmd,nompc);
      //strcat(cmd," ");
      //strcat(cmd,proc);
      //strcat(cmd," >log.txt");
      system(cmd);
    }//end function

    Je suis désolé de te le dire mais ton code n'est pas bon, mais pas du tout!
    Va reviser la « Gestion Des Chaînes De Caractères » !!!

    si tu utilise un « char* », tu dois lui assigner/allouer de la _Mémoire_
    tu ne peux pas manipuler ton pointeur, qui, pointe sur _Rien_ !

    sinon, comme j'ai dit plus haut, utilise basic_string >> #include <string>
    avec basic_string, pas besoin de t'occuper de la gestion de la mémoire, basic_string le fait tout seul comme un grand!

    autre petite chose, pour le « status », utilise un entier quelconque pour connaître le status et non une chaine, avec un entier ca serait tellement plus simple/rapide/... et surtout, beaucoup mais beaucoup moins lourd à gérer. si tu tiens absolument a obtenir le status en « texte », ajoute une simple/petite/... fonction qui va te retourner le status(en texte)

    const char* getStatusString(int nStatus)
    {
      switch (nStatus)
      {
        case X: return "status X";
        case Y: return "status Y";
        // ...
        default: break;
      }
      return "unknown status";
    }


    ...
    ...
    ...

  • signaler à un administrateur
    Commentaire de excrt le 02/06/2006 17:50:47

    en passant, retire cette phrase « pas d'erreur de compilation »
    je ne veux pas être méchant mais c'est ridicule puisque
    « 0 error(s), 0 warning(s) » ne veut strictement _rien_ dire ...

  • signaler à un administrateur
    Commentaire de excrt le 02/06/2006 17:59:41

    dernière petite chose

    BOOL hServiceStatus;
    BOOL hControlService;
    BOOL hStartServices;

    « h » désigne un « HANDLE », pas un BOOL

    BOOL bServiceStatus;
    BOOL bControlService;
    BOOL bStartServices;
    // serait plus ... approprié

      // ton code
      hServiceStatus = QueryServiceStatus( ... );

    quand on lit ca, on ce dit, ah! QueryServiceStatus() retourne un « HANDLE », mais non! c'est faux! QueryServiceStatus() retourne un « BOOL » !

  • signaler à un administrateur
    Commentaire de BruNews le 02/06/2006 20:28:14 administrateur CS

    C'est très clair, la compil ok indique seulement que la syntaxe du langage est correcte, que le prog ne plante pas est une toute autre affaire.

Ajouter un commentaire

Discussions en rapport avec ce code source

Pub



Appels d'offres

CalendriCode

Août 2008
LMMJVSD
    123
45678910
11121314151617
18192021222324
25262728293031

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Téléchargements

Boutique

Boutique de goodies CodeS-SourceS