Bonsoir à tous.

Je travaille sous Delphi 6.
Je tente d’utiliser une dll écrite en C.
La fonction en C est la suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
int Connexion(char *TargetName,unsigned long *ConnectionId,char *Login,char *Password,bool ShowPuTTY,long Protocol,unsigned long PortNumber,long GenerateReport,int *CallBackRcvData,unsigned long SpecSettings);
Je l’utilise sous Delphi comme suit :
D’abord les déclarations :

(…)

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
  private
hDLL:THandle;
C_Id_DLL: integer;
  public
  end;
var
  Form1: TForm1;
  function ConnectCllBck (ConnexionId: LongInt;RValue: PChar;Size: LongInt;ConnectStatus: LongInt):LongInt;
implementation
var
    Connexion: function(TargetName: PChar;
                      var ConnexionId: LongInt;
                      Login: PChar;
                      Password: PChar;
                      ShowPuTTY: Boolean; 
                      Protocol: LongInt; 
                      PortNumber: LongInt; 
                      GenerateReport: LongInt; 
                      ptrFctRcv: Pointer; 
                      SpecSettings: LongInt): Integer cdecl  {$IFDEF WIN32} stdcall {$ENDIF};
Puis l’utilisation :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
  hDLL:=LoadLibrary(PChar('ExtraPuTTY.dll')); 
  if hDLL=0 then ShowMessage('erreur au chargement de la DLL');
  Connexion:=GetProcAddress(hDLL,'Connexion');  // affectation de la fonction Connexion de la dll à la fonction Connexion de notre programme
Connexion('192.168.2.1',C_Id_DLL,'root',’mdproot’,true,1,22,0,nil,0);
Jusque là, tout fonctionne parfaitement

LE PROBLEME concerne la fonction pouvant être déclanchée en CallBack.
En effet, si je cherche à utiliser cette fonction, mon programme se compile, mais j’ai une erreur à l’exécution.

L’appel de la fonction de la DLL se fait alors comme suit :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
Connexion('192.168.2.1',C_Id_DLL,'root',’mdproot’,true,1,22,0, @ConnectCllBck,0);
La fonction Callback en C est la suivante :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
int CallBackRcvData(unsigned long ConnectionId,char *buf, DWORD size,DWORD ConnectionStatus)
Et ma fonction dans Delphi celle-ci :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
function ConnectCllBck (ConnexionId: LongInt;RValue: Pchar;Size: LongInt;ConnectStatus: LongInt):LongInt;
begin
//
end;
L’ERREUR provient-elle d’une mauvaise « traduction » C/Delphi de la fonction CallBackRcvData ou d’une mauvaise façon dont ma fonction ConnectCllBck est déclarée ?

D’avance merci pour vos conseils.