Bonjour
Je suis en train de m'essayer à Lazarus 2.2.6 et FPC 3.2.2sur PI4 B
J'essai de créer et faire des appels à une DLL. Le code écrit ci-dessous fonctionne sur Lazarus sous Windows, mais pas sous Lazarus sur Raspberry.
Voici le code de la DLL qui se compile bien sur Raspberry
Code:
1
2
3
4
5
6
7
8 Library PessaiDDL; {$mode objfpc} {$H+} Uses Classe, UessaiDll; Begin End.
Voici le code du programme utilisant la DLL qui se compile bien sur RaspberryCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 Unit UessaiDLL; {$mode objfpc} {$H+} Uses Classe, SysUtils, Dynlibs; Implementation Function Somme(A,B: integer): integer; StdCall ; Begin Result :=A+B; End; Exports Somme ; Begin End.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 program PtestDLL; {$mode objfpc} {$H+} Uses {$IFDEF UNIX} cthreads, {$ENDIF} {$IFDEF HASAMIGA} athreads, {$ENDIF} Interface, forms, UtestDLL; {$R *.res} begin RequireDerivedFormResource:=true; Application.Scales:=true; Application.Initialize; Application.createForm(Tform1, Form1) Application.Run end.
Quand j'exécute le code du click sur le bouton, j'ai le plantage suivant à l'appel de la fonction "Somme" avec le message suivant :Code:
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 Unit UtestDLL; {$mode objfpc} {$H+} Interface Uses Classes, SysUtils, Forms , Controls, Graphics, Dialogs, StdCtrls, dynlibs; Type Tform1:=class(Tform) Button1 : Tbutton; Edit1 : Tedit; Edit2 : Tedit; Procedure Button1Click(sender : TObject); Procedure FormClose(sender : TObject; var CloseAction: TCloseAction); Procedure FormCreate(sender : TObject); Private Public End; Var Form1 : Tform1; Implementation {$R *.lfm} { Tform1 } Type TSomme = function (A,B: integer): integer; StdCall ; Var Somme : TSomme ; LibHandle : Thandle ; Procedure ChargeDLL; begin LibHandle := LoadLibrary(Pchar('/home.../libPessaiDll.so')); If LibHandle<>0 then begin pointer(Somme):=GetProcAddress(LibHandle,'Somme'); end else showmessage ('Erreur de chargement de la librairie') end; Procedure DetruitDLL; begin Somme:=nil; FreeLibrary(LibHandle); end; Procedure Button1Click(sender : TObject); var A,B : integer; st : string; Begin A:=strtoInt(Edit1.text); B:=strtoInt(Edit2.text); St:=IntToStr(A,B); Showmessage(st); end; Procedure FormClose(sender : TObject; var CloseAction: TCloseAction); Begin DetruitDLL end; Procedure FormCreate(sender : TObject); Begin ChargeDLL; end; end.
[Le projet PessaiDll a levé une classe d'exception " External:SIGSEGV" ].
Quelqu'un peut il m'aider a faire fonctionner cet appel a a la DLL ?
Merci d'avance .