Bonjour tout le monde,
Je porte une application écrite en C# vers Delphi qui fait plusieurs appels à une DLL externe. Je ne rencontre pas de problème pour la ces appels sauf un pour lequel je ne comprend pas où est le problème.
Voici le code C#:
que j'ai traduit comme ceci
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 [DllImport("maDLL.dll")] public static extern int readBlock(byte address, byte number, int tagTyp, byte blockNR, byte[] serialnumber, int length, ref READBLOCK readblock); public struct READBLOCK { public byte loc; public byte rst; public byte nob1; public int tt1; public int dt1; public byte nr1; public byte size1; public unsafe fixed byte snr[120]; public byte nob2; public int tt2; public int dt2; public byte nr2; public byte size2; public unsafe fixed byte data[120]; }; //L'appel de la fonction se fait comme ceci: byte[] serialnumber = new byte[0]; READBLOCK readblock = new READBLOCK(); int error=readBlock(63,1,5,0,serialnumber,0,ref readblock);
Sur visual studio, aucune erreur, l'appel à la DLL fonctionne correctement (elle lit des données sur un périphérique USB).
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 type READBLOCK=record // Location */ loc:byte; // Reader Status */ rst:byte; // Number of Blocks 1 */ nob1:byte; // Tag typ 1 */ tt1:integer; // Data typ 1 */ dt1:integer; // The nr1 */ nr1:byte; // size of serialnumber */ size1:byte; // The serialnumber */ snr:array[0..119] of byte; // Number of Blocks 2 */ nob2:byte; // Tag typ 2 */ tt2:integer; // Data typ 2 */ dt2:integer; // The nr2 */ nr2:byte; // size of data */ size2:byte; // The messagetyp */ data:array[0..119] of byte; end; pREADBLOCK=^READBLOCK; maFonction:Function(address:byte;number:byte;tagTyp:integer;blockNr:byte;serialnumber: array of byte;length:integer;BLOCK: pREADBLOCK) :integer;stdcall; Blk:READBLOCK; hDLL:THandle; serial:array of byte; error:integer; hDLL:=LoadLibrary('maDLL.dll'); if hDLL>0 then begin maFunction:=GetProcAddress(hDLL,'readBlock'); if assigned(maFunction) then error:= maFunction(63,1,5,0,serial,0,@Blk); end;
Sur Delphi, le bip de lecture du périphérique est déclenché mais j'obtiens une violation d'accès.
J'ai essayé de remplacer byte par UINT8 dans delphi mais sans succès.
Mon compilateur Visual studio, la DLL et mon OS sont en 64bits alors que Delphi compile en 32bits. Je pense que le problème doit se situer au niveau des types mais je n'ai pas trouvé. J'ai remplacé integer par int64 dans ma structure et dans la déclaration de la DLL mais ça n'a rien changé.
Avez-vous des pistes pour ça?
Partager