IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API, COM et SDKs Delphi Discussion :

Comment créer une connexion accès distant ?


Sujet :

API, COM et SDKs Delphi

  1. #1
    Membre à l'essai
    Inscrit en
    Mars 2005
    Messages
    19
    Détails du profil
    Informations forums :
    Inscription : Mars 2005
    Messages : 19
    Points : 10
    Points
    10
    Par défaut Comment créer une connexion accès distant ?
    Bonjour,

    Quelqu'un saurait comment crééer une connexion accès distant avec Delphi ?

  2. #2
    Membre éclairé
    Avatar de MD Software
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    613
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 613
    Points : 680
    Points
    680
    Par défaut
    Je crois qu'un composant de la JVCL le permet
    MD Software
    ---------------------------
    F.A.Q. Delphi - Cours Delphi - Composants Delphi - Sources Delphi

  3. #3
    Membre à l'essai
    Inscrit en
    Mars 2005
    Messages
    19
    Détails du profil
    Informations forums :
    Inscription : Mars 2005
    Messages : 19
    Points : 10
    Points
    10
    Par défaut
    Y a plus qu'à chercher ... Merci.
    Autrement si quelqu'un s'y connait en API et qu'il existe quelque chose à ce sujet ;-)

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2002
    Messages : 22
    Points : 30
    Points
    30
    Par défaut
    Bonsoir,

    Voici comment je m'y prends pour établir une connexion :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
     
    unit Connexion;
    {$N+}
     
    //Unit permettant d'accèder à des fonctions de la dll RASAPI32.DLL
    // pour d'autres fonctions contenues dans la dll RASAPI32, allez voir sur
    // le site de Piette http://www.rtfm.be/fpiette.
     
    interface
     
    uses Windows,Dialogs,Types,SysUtils;
     
    const
      UNLEN = 256;
      PWLEN = 256;
      DNLEN = 15;
      RAS_MaxEntryName      =  256;
      RAS_MaxDeviceName     =  128;
      RAS_MaxDeviceType     =  16;
      RAS_MaxPhoneNumber    =  128;
      RAS_MaxCallbackNumber =  RAS_MaxPhoneNumber;
     
    type
      HRASConn = DWORD;
     
      PRASConn = ^TRASConn;
      TRASConn = record
                 dwSize: DWORD;
                 rasConn: HRASConn;     // handle de la connexion
                 szEntryName: Array[0..RAS_MaxEntryName] of Char;
                 szDeviceType : Array[0..RAS_MaxDeviceType] of Char;
                 szDeviceName : array [0..RAS_MaxDeviceName] of char;
                 end;
     
      PRASConnStatus = ^TRASConnStatus;
      TRASConnStatus = record
                       dwSize: LongInt;
                       rasConnstate: Word;
                       dwError: LongInt;
                       szDeviceType: Array[0..RAS_MaxDeviceType] of Char;
                       szDeviceName: Array[0..RAS_MaxDeviceName] of Char;
                       end;
     
      PRASDialParams = ^TRASDialParams;
      TRASDialParams = record 
                       dwSize: DWORD;
                       szEntryName     : Array[0..RAS_MaxEntryName] of Char;
                       szPhoneNumber   : Array[0..RAS_MaxPhoneNumber] of Char;
                       szCallbackNumber: Array[0..RAS_MaxCallbackNumber] of Char;
                       szUserName      : Array[0..UNLEN] of Char;
                       szPassword      : Array[0..PWLEN] of Char;
                       szDomain        : Array[0..DNLEN] of Char;
                       end;
     
      PRASDIALEXTENSIONS= ^TRASDIALEXTENSIONS;
      TRASDIALEXTENSIONS= record
                          dwSize: DWORD;
                          dwfOptions: DWORD;
                          hwndParent: HWnd;
                          reserved: DWORD;
                          end;
     
    var
       RasEnumConnections: function (RASConn: PrasConn;            { buffer recevant les données }
                                     var BufSize: DWord;           { taille du buffer }
                                     var Connections: DWord        { nombre de connexions }
                                     ): LongInt; stdcall;
       RasHangUp: function(RASConn: hrasConn): LongInt; stdcall;  { handle de la connection à déconnecter }
     
       RasGetConnectStatus: function(RASConn: hrasConn;           { handle de la connexion à examiner}
                                     RASConnStatus: PRASConnStatus{ buffer recevant les données }
                                     ): LongInt; stdcall;
     
       RasDial: function(lpRasDialExtensions : PRASDIALEXTENSIONS ;// pointer to function extensions data
                         lpszPhonebook   : PChar;          // pointer to full path and filename of phone-book file
                         lpRasDialParams : PRASDIALPARAMS; // pointer to calling parameters data
                         dwNotifierType  : DWORD;          // specifies type of RasDial event handler
                         lpvNotifier     : DWORD;          // specifies a handler for RasDial events
                         var rasConn     : HRASConn        // Handle de la connexion
                         ): DWORD; stdcall;
     
       RasGetErrorString: function(ErrorCode: DWord;      // valeur (DWord) de l'erreur dont on veut conaitre le
                                                          // message d'erreur associé
                                   szErrorString: PChar;  // buffer contenant le message d'erreur
                                   BufSize: DWord         // taille du buffer
                                   ): LongInt; stdcall;
     
    function OpenRASAPI: boolean;
    function fermeConnexion(HandleConnexion:HRASConn): boolean;
     
    implementation
     
     
    {------------------------------------------------------------------------------}
    function OpenRASAPI: boolean;
    {------------------------------------------------------------------------------}
    begin
       OpenRASAPI := false;
       rasapiDLL := loadLibrary(Pchar('RASAPI32.DLL'));   //Chargement dynamique
       if rasapidll = 0 then
          begin
          showmessage('Erreur au chargement de RASAPI32.DLL');
          exit;
          end;
       @RasEnumConnections := GetProcAddress(Rasapidll,'RasEnumConnectionsA');   
       if @RasEnumConnections=nil then
          begin
          ShowMessage('Fonction RasEnumConnections non chargée');
          FreeLibrary(rasapiDll);
          rasapiDll := 0;
          exit;
          end; 
       @RasHangUp := GetProcAddress(rasapidll,'RasHangUpA');   
       if @RasHangUp=nil then
          begin
          ShowMessage('Fonction RasHangUp non chargée');
          FreeLibrary(rasapiDll);
          rasapiDll := 0;
          exit;
          end;     
       @RasGetConnectStatus := GetProcAddress(rasapidll,'RasGetConnectStatusA');   
       if @RasGetConnectStatus=nil then
          begin
          ShowMessage('Fonction RasGetConnectStatus non chargée');
          FreeLibrary(rasapiDll);
          rasapiDll := 0;
          exit;
          end;
       @RasDial := GetProcAddress(rasapidll,'RasDialA');   
       if @RasDial=nil then
          begin
          ShowMessage('Fonction RasDial non chargée');
          FreeLibrary(rasapiDll);
          rasapiDll := 0;
          exit;
          end;
       @RasGetErrorString := GetProcAddress(rasapidll,'RasGetErrorStringA');   
       if @RasGetErrorString=nil then
          begin
          ShowMessage('Fonction RasGetErrorString non chargée');
          FreeLibrary(rasapiDll);
          rasapiDll := 0;
          exit;
          end; 
       OpenRasapi := true;   
    end;
     
    //------------------------------------------------------------------------------
    function fermeConnexion(HandleConnexion:HRASConn): boolean;
    //------------------------------------------------------------------------------
    var
       ReponseFonction   :DWord;
       RASConnStatus     :TRASConnStatus;
       ResultatRasHangUp :DWord;
    begin
       fermeConnexion := false;
       if HandleConnexion<>0 then
          begin
          RASConnStatus.dwSize := Sizeof(TRASConnStatus);
          ResultatRasHangUp:= RasHangUp(HandleConnexion);
          if ResultatRasHangUp=0 then //si pas d'erreur
                                      // la boucle suivante permet de ne pas rendre la main tant que la déconnexion n'est pas terminée
                                      // voir aide à ce sujet sur aide API RasHangUp
             begin                         
             repeat
             ReponseFonction := RasGetConnectStatus(HandleConnexion, @RASConnStatus);
             sleep(0);
             until ReponseFonction = ERROR_INVALID_HANDLE;
             fermeConnexion := true;
             end
          else 
             showMessage('erreur RasHangUp');
          end
    end;
     
    end.

    //mise en oeuvre de la connexion

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
     
    var
       HandleDeLaConnexion: HRASConn;
       ParametreConnexion:TRASDialParams;
       RasdialExtensions:  TRASDIALEXTENSIONS;
       ResultatRasDial:integer;
     
    begin
       .........
       HandleDeLaConnexion := 0;
       if DialName.Text <> '' then  //contient le nom de la connexion
          begin
          screen.cursor := crHourGlass;
          RasdialExtensions.dwSize:=sizeof(RasdialExtensions);
          RasdialExtensions.dwfOptions:=0;
          FillChar(ParametreConnexion, SizeOf(ParametreConnexion), 0);
          ParametreConnexion.dwSize:=sizeof(TRASDialParams);
          strCopy(ParametreConnexion.szEntryName,   PChar(DialName.Text));
          strCopy(ParametreConnexion.szPhoneNumber, PChar(''));
          strCopy(ParametreConnexion.szUserName,    PChar(Diallogin.Text));
          strCopy(ParametreConnexion.szPassword,    PChar(DialPasse.Text));
          ParametreConnexion.szCallbackNumber:='';
          ParametreConnexion.szDomain:='';
          ResultatRasDial:=RasDial(@RasdialExtensions,   { pointer to function extensions data }
                                      nil,                  { pointer to full path and filename of phonebook file}
                                      @ParametreConnexion,  //lpRasDialParams : PRASDIALPARAMS;
                                                            { pointeur vers les paramètre d'appel de la connexion}
                                      0,                    //dwNotifierType : DWORD;
                                                            {  specifies type of RasDial event handler}
                                      0,                    //lpvNotifier: DWORD;
                                                            { specifies a handler for RasDial events}
                                      HandleDeLaConnexion); // var rasConn: HRASConn
                                                            { handle de la connexion}
          if ResultatRasDial <> 0 then
             begin
             RasGetErrorString(ResultatRasDial, @ChaineRepresentantLErreur, SizeOf(ChaineRepresentantLErreur));
             Memo2.Lines.Add(intToStr(ResultatRasDial)+' '+String(ChaineRepresentantLErreur));
             if fermeConnexion(HandleDeLaConnexion) then
                HandleDeLaConnexion := 0;
             screen.cursor := crdefault;
             exit;
             end;
          end;
     
       .......

  5. #5
    Membre à l'essai
    Inscrit en
    Mars 2005
    Messages
    19
    Détails du profil
    Informations forums :
    Inscription : Mars 2005
    Messages : 19
    Points : 10
    Points
    10
    Par défaut
    Merci Noel Sybille je vais étudier ce code, mais à première vue il ne s'agit pas de créer puis supprimer une connexion.
    MD Software je n'ai pas trouvé le composant dans la JVCL. Pourrais-tu m'en dire plus ?

    Pour être plus précis sur ma demande, j'ai régulièrement besoin de créer une connexion modem sur des PC pour faire quelques tests d'applications, puis supprimer cette connexion. C'est très chiant.
    Voilà pourquoi je cherche le moyen de créer un exe qui le ferait tout seul.

    Merci.

  6. #6
    Membre éclairé
    Avatar de MD Software
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    613
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 613
    Points : 680
    Points
    680
    Par défaut
    C'était une connexion d'un lecteur réseau.

    Pardon, j'ai rien dit !
    MD Software
    ---------------------------
    F.A.Q. Delphi - Cours Delphi - Composants Delphi - Sources Delphi

  7. #7
    Membre à l'essai
    Inscrit en
    Mars 2005
    Messages
    19
    Détails du profil
    Informations forums :
    Inscription : Mars 2005
    Messages : 19
    Points : 10
    Points
    10
    Par défaut
    Oh non y a pas de souci, la JVCL est tellement vaste en plus. Pas facile d'y trouver quelque chose, j'ai regardé plusieurs fois avant de dire que j'ai pas trouvé ;-)
    Je pense que la solution que je recherche doit passer par l'utilisation de rasapi comme l'a suggéré Noel Sybille. Mais honnêtement si y a un compo qui gère déjà tout ça je serai très heureux de mettre la main dessus !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Comment créer une connexion avec une base de données MySql en VBA
    Par jinkey dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 01/12/2008, 15h39
  2. Comment créer une connexion entre Delphi et une base de données ?
    Par pttangediabolik dans le forum Débuter
    Réponses: 2
    Dernier message: 29/04/2008, 14h59
  3. Réponses: 1
    Dernier message: 05/02/2007, 10h11
  4. Comment créer une connexion Bluetooth ?
    Par kurkaine dans le forum C++Builder
    Réponses: 3
    Dernier message: 17/06/2006, 22h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo