Précédent   Forum du club des développeurs et IT Pro > Autres langages > Pascal > Lazarus
Lazarus Forum d'entraide sur Lazarus, l'EDI RAD multiplateforme basé sur Free Pascal
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 22/02/2013, 13h32   #1
[ZiP]
Membre confirmé
 
Homme
Inscription : octobre 2006
Messages : 807
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Pas de Calais (Nord Pas de Calais)

Informations forums :
Inscription : octobre 2006
Messages : 807
Points : 248
Points : 248
Par défaut Utilisation d'une DLL externe = crash !

Bonjour,

Je suis en train de développer une unité pour utiliser la librairie libacarsd.dll dans mon programme.

J'ai réalisé, pour le moment, ce morceau de code :
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
 
unit libacarsd;
 
{$mode objfpc}{$H+}
 
interface
 
uses
    Windows;
 
const
    // Type of soundstreams
    // Only 3 types are supported at the moment:
    // 19500 Hz
    // 22050 Hz
    // 44100 Hz
    // all streams have to be MONO, 8bit
    STREAM19500 = 0;
    STREAM22050 = 1;
    STREAM44100 = 2;
 
type
    // Typedefinition for a single char within ACARS stream
    ACD_CONT = packed record
        error : Byte; // Error indicated by 1. No error = 0
        data  : Byte; // Decoded char - without error? see above
    end;
 
    // Typedefinition for the complete ACARS stream
    ACD = packed record
        len      : Integer; // Count of decoded chars
        errors   : Integer; // Errorcounter
        closed   : Integer; // Transmission correct closed
        flags    : Integer; // Flags for this transmission - see above
        squitter : Integer; // This is a Squitter message
        uplink   : Integer; // This is a Uplink message
        lastpos  : Integer; // Last position within soundstream
        crc      : Word;    // Calcutated CRC. 0 if message is complete and validated!
        c        : array[1..1024] of ACD_CONT;
    end;
 
    P_libacarsd = ^libacarsd;
    libacarsd = packed record
        acarsd_codepos : Integer;
        acarsd_utable  : array[1..10] of LongWord;
        codeholder     : array[1..100] of ACD;
        private        : Pointer;
    end;
 
    function acarsd_init(const buf: Integer; const sample: Integer; const pass: Integer): P_libacarsd; cdecl; external 'libacarsd.dll';
 
implementation
 
end.
Je l'utilise comme ça :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
 
procedure TForm1.FormCreate(Sender: TObject);
const
     Fichier = 'sndfile.snd';
var
   L : P_libacarsd;
begin
     if FileExists(ExtractFilePath(Application.ExeName) + Fichier) then
     begin
          L := acarsd_init(FileSize(ExtractFilePath(Application.ExeName) + Fichier), STREAM19500, 8);
     end;
end;
Le programme plante...

Je pense que ma conversion est bonne :
Code c :
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
 
/* Typedefinition for a single char within ACARS stream */
typedef struct {
    unsigned char error; /* Error indicated by 1. No error = 0 */
    unsigned char data;  /* Decoded char - without error? see above */
} ACD_CONT;
 
/* Typedefinition for the complete ACARS stream */
typedef struct {
    int len;             /* Count of decoded chars */
    int errors;          /* Errorcounter */
    int closed;          /* Transmission correct closed */
    int flags;           /* Flags for this transmission - see above */
    int squitter;        /* This is a Squitter message */
    int uplink;          /* This is a Uplink message */
    int lastpos;         /* Last position within soundstream */
    unsigned short crc;  /* Calcutated CRC. 0 if message is complete and validated! */
    ACD_CONT c[1024];    /* Included typedef from above */
} ACD;
 
/* Public part of Library structure 
   !!! DONT CHANGE ANYTHING ON THIS DEFINITION !!!
*/
typedef struct {
    int acarsd_codepos;
    unsigned long acarsd_utable[10];
    ACD codeholder[100];
    void *private;
} libacarsd;
 
/* Initialize internal structures */
EXPORT libacarsd __stdcall *acarsd_init(const int buf,    /* Size of buffer with sounddata  */
					const int sample, /* Sampling rate (see above)      */
					const int pass);  /* How many passes on each stream */

Qu'en pensez-vous ?

La documentation de la DLL est consultable en ligne à cette adresse : http://www.acarsd.org/docu.html

Merci pour votre aide,
ZiP
[ZiP] est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/02/2013, 14h09   #2
M.Dlb
Rédacteur/Modérateur
 
Avatar de M.Dlb
 
Inscription : avril 2002
Messages : 2 275
Détails du profil
Informations personnelles :
Âge : 28

Informations forums :
Inscription : avril 2002
Messages : 2 275
Points : 3 392
Points : 3 392
Le champ crc dans le record ACD est de type unsigned short, j'aurais plutôt mis Byte en correspondance plutôt que Word. Pour les tableaux, je sais pas si ca a vraiment une incidence, mais en C les tableaux commencent à 0, tu devrais peut-être les faire commencer à 0 aussi.
__________________
M.Dlb - Modérateur z/OS - Rédacteur et Modérateur Pascal
M.Dlb est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/02/2013, 14h21   #3
[ZiP]
Membre confirmé
 
Homme
Inscription : octobre 2006
Messages : 807
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Pas de Calais (Nord Pas de Calais)

Informations forums :
Inscription : octobre 2006
Messages : 807
Points : 248
Points : 248
Bonjour,

Pour les types, je me suis basé sur ça : http://wiki.freepascal.org/Pascal_for_C_users

Je viens de redémarrer Lazarus et en fait, c'est cette erreur là que j'ai :



Merci,
ZiP
[ZiP] est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/02/2013, 14h40   #4
[ZiP]
Membre confirmé
 
Homme
Inscription : octobre 2006
Messages : 807
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Pas de Calais (Nord Pas de Calais)

Informations forums :
Inscription : octobre 2006
Messages : 807
Points : 248
Points : 248
Voici la liste des fonctions de ma DLL extraites avec DLL Export Viewer :
Citation:
==================================================
Function Name : ACARS_Decoder@8
Address : 0x6a081590
Relative Address : 0x00001590
Ordinal : 12 (0xc)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : ACARS_VInfo@4
Address : 0x6a081570
Relative Address : 0x00001570
Ordinal : 2 (0x2)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : acarsd_destroy@4
Address : 0x6a081510
Relative Address : 0x00001510
Ordinal : 7 (0x7)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : acarsd_errors_of_msg@8
Address : 0x6a081bc0
Relative Address : 0x00001bc0
Ordinal : 8 (0x8)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : acarsd_goodoffset@8
Address : 0x6a081660
Relative Address : 0x00001660
Ordinal : 9 (0x9)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : acarsd_human_readable@8
Address : 0x6a081890
Relative Address : 0x00001890
Ordinal : 10 (0xa)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : acarsd_init@12
Address : 0x6a081450
Relative Address : 0x00001450
Ordinal : 11 (0xb)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : acarsd_option@12
Address : 0x6a081300
Relative Address : 0x00001300
Ordinal : 1 (0x1)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : acarsd_sorttables@4
Address : 0x6a081700
Relative Address : 0x00001700
Ordinal : 13 (0xd)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : codetable
Address : 0x6a084020
Relative Address : 0x00004020
Ordinal : 14 (0xe)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : codetable22
Address : 0x6a084080
Relative Address : 0x00004080
Ordinal : 15 (0xf)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : codetable44
Address : 0x6a0840e0
Relative Address : 0x000040e0
Ordinal : 16 (0x10)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : errornames
Address : 0x6a084140
Relative Address : 0x00004140
Ordinal : 17 (0x11)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : LACS_AUT
Address : 0x6a084004
Relative Address : 0x00004004
Ordinal : 3 (0x3)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : LACS_DAT
Address : 0x6a084008
Relative Address : 0x00004008
Ordinal : 4 (0x4)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : LACS_ID
Address : 0x6a08400c
Relative Address : 0x0000400c
Ordinal : 5 (0x5)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : LACS_REV
Address : 0x6a084000
Relative Address : 0x00004000
Ordinal : 6 (0x6)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : libacarsdmajorversion
Address : 0x6a0812e0
Relative Address : 0x000012e0
Ordinal : 18 (0x12)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : libacarsdminorversion
Address : 0x6a0812dc
Relative Address : 0x000012dc
Ordinal : 19 (0x13)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : libacarsdrevision
Address : 0x6a0812e4
Relative Address : 0x000012e4
Ordinal : 20 (0x14)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : preample
Address : 0x6a0812e8
Relative Address : 0x000012e8
Ordinal : 21 (0x15)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : preample2
Address : 0x6a0812ec
Relative Address : 0x000012ec
Ordinal : 22 (0x16)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================

==================================================
Function Name : spec
Address : 0x6a084180
Relative Address : 0x00004180
Ordinal : 23 (0x17)
Filename : libacarsd.dll
Full Path : C:\libacarsd.dll
Type : Exported Function
==================================================
Si je modifie mon code en :
Code :
function acarsd_init(const buf: Integer; const sample: Integer; const pass: Integer): P_libacarsd; external 'libacarsd.dll' name 'acarsd_init@12';
Code :
function acarsd_init(const buf: Integer; const sample: Integer; const pass: Integer): P_libacarsd; cdecl; external 'libacarsd.dll' name 'acarsd_init@12';
Code :
function acarsd_init(const buf: Integer; const sample: Integer; const pass: Integer): P_libacarsd; stdcall; external 'libacarsd.dll' name 'acarsd_init@12';
Je n'ai plus le message d'erreur mais mon programme crash...

J'ai également essayé des tableaux commençant à 0. Même problème.

Cordialement,
ZiP
[ZiP] est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/02/2013, 15h55   #5
Ph. B.
Expert Confirmé
 
Avatar de Ph. B.
 
Homme Philippe
Inscription : avril 2002
Messages : 1 032
Détails du profil
Informations personnelles :
Nom : Homme Philippe
Âge : 46
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : avril 2002
Messages : 1 032
Points : 2 665
Points : 2 665
Envoyer un message via ICQ à Ph. B. Envoyer un message via Skype™ à Ph. B.
Bonjour,

Je commencerais déjà par nommer les fonctions appelées correctement, cad soit par leur nom littéral, soit par leur index, mais pas les 2...
Et en respectant la convention d'appel C puis que cette dll est écrite apparemment en C.

Soit :
Code :
1
2
3
function acarsd_init(const buf: Integer; const sample: Integer; const pass: Integer): P_libacarsd; cdecl; external 'libacarsd.dll' name 'acarsd_init';
// OU BIEN
function acarsd_init(const buf: Integer; const sample: Integer; const pass: Integer): P_libacarsd; cdecl; external 'libacarsd.dll' index 12;
__________________
Philippe.
Ph. B. est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/02/2013, 16h49   #6
[ZiP]
Membre confirmé
 
Homme
Inscription : octobre 2006
Messages : 807
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Pas de Calais (Nord Pas de Calais)

Informations forums :
Inscription : octobre 2006
Messages : 807
Points : 248
Points : 248
Bonjour,

J'ai corrigé et je vous propose le projet de test ci-joint.

C'est plus facile pour tester.

J'ai toujours cette erreur :



Si je mets ça :

Code :
function acarsd_init(const buf: Integer; const sample: Integer; const pass: Integer): P_libacarsd; cdecl; external NomDLL name 'acarsd_init@12';
Ou ça :

Code :
function acarsd_init(const buf: Integer; const sample: Integer; const pass: Integer): P_libacarsd; cdecl; external NomDLL index 12;
Le programme crash...

Merci pour votre aide,
ZiP
Fichiers attachés
Type de fichier : zip libacarsd.zip (1,13 Mo, 2 affichages)
[ZiP] est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/02/2013, 22h31   #7
Ph. B.
Expert Confirmé
 
Avatar de Ph. B.
 
Homme Philippe
Inscription : avril 2002
Messages : 1 032
Détails du profil
Informations personnelles :
Nom : Homme Philippe
Âge : 46
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : avril 2002
Messages : 1 032
Points : 2 665
Points : 2 665
Envoyer un message via ICQ à Ph. B. Envoyer un message via Skype™ à Ph. B.
Bonjour,
J'ai regardé votre projet.
Les fonctions sont bien nommées telles que vous les aviez notées dans le 1° message. Mea Culpa !
Par contre, je suis allé récupérer le fichier libacars.h qui décrit les fonctions exportées : prototype et convention d'appel.
On a :
Code c :
1
2
3
4
/* Initialize internal structures */
EXPORT libacarsd __stdcall *acarsd_init(const int buf,    /* Size of buffer with sounddata  */
					const int sample, /* Sampling rate (see above)      */
					const int pass);  /* How many passes on each stream */
Ce n'est donc pas cdecl qu'il faut utiliser côté Lazarus mais stdcall !
On a donc :
Code :
1
2
function acarsd_init(const buf: Integer; const sample: Integer; const pass: Integer): P_libacarsd;
  stdcall; external NomDLL name 'acarsd_init@12';
Et là, plus d'erreur, on récupère bien une structure vide prête à l'emploi.
__________________
Philippe.
Ph. B. est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 22/02/2013, 23h01   #8
[ZiP]
Membre confirmé
 
Homme
Inscription : octobre 2006
Messages : 807
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Pas de Calais (Nord Pas de Calais)

Informations forums :
Inscription : octobre 2006
Messages : 807
Points : 248
Points : 248
Bonsoir,

Merci d'avoir pris le temps de regarder !

Je vais corriger ce point tout de suite.

J'ai également avancé de mon côté, en fait, le crash est causé par le débogueur, si je lance mon programme à l'extérieur de Lazarus, il fonctionne correctement.

Il y a donc un problème au niveau du débogueur, surement à cause de mon Windows 7 qui est en 64 bits alors que le reste (Lazarus, mon programme et ma DLL) est en 32bits.

Merci,
ZiP
[ZiP] est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/02/2013, 03h58   #9
Dr.Who
Membre Expert
 
Avatar de Dr.Who
 
Inscription : septembre 2009
Messages : 980
Détails du profil
Informations personnelles :
Âge : 34

Informations forums :
Inscription : septembre 2009
Messages : 980
Points : 1 175
Points : 1 175
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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
 
unit Libacarsd;
 
interface
 
 
// Flags for messages with errors - see ACD->flags
const
  MSG_NOERROR = $00;
  MSG_ERR_ALL = $01;  // This message is trash
  MSG_ERR_REG = $02;  // Registration is not valid
  MSG_ERR_LAB = $04;  // Label is not valid
  MSG_ERR_BLK = $08;  // Blockindicator is not valid
  MSG_ERR_MSG = $10;  // The messagenumber is not valid
  MSG_ERR_FLI = $20;  // The flightnumber is not valid
  MSG_ERR_EXT = $40;  // The messagecontent is not valid
 
// Typedefinition for a single char within ACARS stream
type
  PAcdCont= ^TAcdCont;
  TAcdCont = record
    error: byte; // Error indicated by 1. No error = 0
    data : byte;  // Decoded char - without error? see above
  end;
 
// Typedefinition for the complete ACARS stream
type
  PAcd = ^TAcd;
  TAcd = record
    len     : integer;   // Count of decoded chars
    errors  : integer;   // Errorcounter
    closed  : integer;   // Transmission correct closed
    flags   : integer;   // Flags for this transmission - see above
    squitter: integer;   // This is a Squitter message
    uplink  : integer;   // This is a Uplink message
    lastpos : integer;   // Last position within soundstream
    crc     : word;  // Calcutated CRC. 0 if message is complete and validated!
    c       : array[0..1023] of TAcdCont; // Included typedef from above
  end;
 
type
  PAcarsd = ^_Libacarsd;
  _Libacarsd = record
    acarsd_codepos: integer;
    acarsd_utable : array[0..9] of LongWord;
    codeholder    : array[0..99] of TAcd;
    _private      : pointer;
  end;
 
 
// GET or SET values for an libacarsd option
const ACARSD_GET  = $40000000;
const ACARSD_SET  = $80000000;
 
// Posible options to get or set
const ACARSD_CODETABLES = $00000001;
const ACARSD_CRCMODE    = $00000002;
const ACARSD_CODEPOS    = $00000004;
const ACARSD_VOLUME     = $00000008;
const ACARSD_BUFSIZE    = $00000010;
const ACARSD_PASSES     = $00000020;
const ACARSD_SAMPLE     = $00000040;
const ACARSD_BUFFERS    = $00000080;
 
// Get Option
function getOpt(aLib: PAcarsd; aFlags: integer): integer;
 
// Set Option
function setOpt(aLib: PAcarsd; aFlags: integer; aValue: integer):integer;
 
// Macro to test for a uplink message
function isUplink(aLib: PAcarsd; aIndex: integer): boolean;
 
// Macro to test for a squitter message
function isSquitter(aLib: PAcarsd; aIndex: integer): boolean;
 
// Type of soundstreams
//   Only 3 types are supported at the moment:
//   19500 Hz
//   22050 Hz
//   44100 Hz
//   all streams have to be MONO, 8bit
 
const STREAM19500 = 0;
const STREAM22050 = 1;
const STREAM44100 = 2;
 
// Flags to notify the application if there is something in the buffer
//   You can build a while loop like this:
//   while (ACARS_Decoder(buff)==ACD_SUCCESS) {...
 
const ACD_NOTHING = 0;
const ACD_SUCCESS = 1;
 
// Flags for the goodoffset function
const ACARSD_VALIDATED = 1;  // Result is the offset to the validated message
const ACARSD_WITHCRC   = 2;  // Result is the offset to the message without errors but with CRC failed
const ACARSD_BEST      = 3;  // Result is the offset to the best possible message
const ACARSD_NONE      = 4;  // No usable message found
 
 
// Initialize internal structures
function acarsdInit(const aBufferSize, aSampleRate, aPass: integer): PAcarsd; stdcall;
 
// Destroy internal structures
//   Not needed at the moment, because libacarsd uses no dynamic allocated memory!
function acarsdDestroy(aLib: PAcarsd): integer; stdcall;
 
// Run decoder on given buffer
function acarsdDecoder(aLib: PAcarsd; aBuffer: PByte): integer; stdcall;
 
// Get the offset from the codeholder structure where the message
//   is validated
function acarsdGoodOffset(aLib: PAcarsd; aNum: PInteger):integer; stdcall;
 
// Sort the used codetables to the optimal usage
procedure acarsdSortTables(aLib: PAcarsd); stdcall;
 
// GET or SET options for libacarsd
//   On GET functions you'll become the value of the requested option
//   On SET functions you'll return 1 (TRUE) if the option could
//   be changed or 0 (FALSE) on error
//   This function returns -1 on unknown options
function acarsdOption(aLib: PAcarsd; aOption, aValue: integer): integer; stdcall;
 
// Return the volume information string
function acarsdVInfo(aLib: PAcarsd): PChar; stdcall;
 
// Output the ACARS transmission as string
//   The caller has to free the string
function acarsdHumanReadable(aLib: PAcarsd; const aForce: integer): PChar; stdcall;
 
// Get all errors from the selected message as string
function acarsdErrorsOfMsg(aLib: PAcarsd; const aOffset: integer): PChar; stdcall;
 
 
type
  TAcarsd = class
  private
    fSampleRate: integer;
    fLib: PAcarsd;
    fBufferSize: integer;
    fPassCount: integer;public
    property Lib: PAcarsd read fLib;
    property BufferSize : integer read fBufferSize;
    property SampleRate : integer read fSampleRate;
    property PassCount  : integer read fPassCount;
  public
    function  Decoder(aBuffer: PByte): integer; stdcall;
    function  GoodOffset(aNum: PInteger):integer; stdcall;
    procedure SortTables; stdcall;
    function  Option(aOption, aValue: integer): integer; stdcall;
    function  VInfo: string; stdcall;
    function  HumanReadable(const aForce: integer): string; stdcall;
    function  ErrorsOfMsg(const aOffset: integer): string; stdcall;
    function isUplink(aIndex:integer): boolean;
    function isSquitter(aIndex: integer): boolean;
  public
    constructor Create(const aBufferSize, aSampleRate, aPass: integer); virtual;
    destructor Destroy;
  end;
 
implementation
 
 
function getOpt(aLib: PAcarsd; aFlags: integer): integer;
begin
  result := acarsdOption(aLib, ACARSD_GET or aFlags, 0);
end;
function setOpt(aLib: PAcarsd; aFlags: integer; aValue: integer):integer;
begin
  result := acarsdOption(aLib, ACARSD_SET or aFlags, aValue);
end;
 
function isUplink(aLib: PAcarsd; aIndex: integer): boolean;
begin
  result := aLib^.codeholder[aIndex].uplink > 0;
end;
 
function isSquitter(aLib: PAcarsd; aIndex: integer): boolean;
begin
  result := aLib^.codeholder[aIndex].squitter > 0;
end;
 
const
  LIB = 'libacarsd.dll';
 
function  acarsdInit;          external LIB name 'acarsd_init';
function  acarsdDestroy;       external LIB name 'acarsd_destroy';
function  acarsdDecoder;       external LIB name 'ACARS_Decoder';
function  acarsdGoodOffset;    external LIB name 'acarsd_goodoffset';
procedure acarsdSortTables;    external LIB name 'acarsd_sorttables';
function  acarsdOption;        external LIB name 'acarsd_option';
function  acarsdVInfo;         external LIB name 'ACARS_VInfo';
function  acarsdHumanReadable; external LIB name 'acarsd_human_readable';
function  acarsdErrorsOfMsg;   external LIB name 'acarsd_errors_of_msg';
 
 
{ TAcarsd }
 
constructor TAcarsd.Create(const aBufferSize, aSampleRate, aPass: integer);
begin
  inherited Create;
  fBufferSize := aBufferSize;
  fSampleRate := aSampleRate;
  fPassCount  := aPass;
  fLib := acarsdInit(fBufferSize, fSampleRate, fPassCount);
end;
 
destructor TAcarsd.Destroy;
begin
  acarsdDestroy(fLib);
  inherited Destroy;
end;
 
function TAcarsd.Decoder(aBuffer: PByte): integer;
begin
  result := acarsdDecoder(fLib, aBuffer);
end;
 
 
function TAcarsd.ErrorsOfMsg(const aOffset: integer): string;
begin
  result := acarsdErrorsOfMsg(fLib, aOffset);
end;
 
function TAcarsd.GoodOffset(aNum: PInteger): integer;
begin
  result := acarsdGoodOffset(fLib, aNum);
end;
 
function TAcarsd.HumanReadable(const aForce: integer): string;
begin
  result := acarsdHumanReadable(fLib, aForce);
end;
 
function TAcarsd.isSquitter(aIndex: integer): boolean;
begin
  result := Libacarsd.isSquitter(fLib, aIndex);
end;
 
function TAcarsd.isUplink(aIndex: integer): boolean;
begin
  result := Libacarsd.isUplink(fLib, aIndex);
end;
 
function TAcarsd.Option(aOption, aValue: integer): integer;
begin
  result := acarsdOption(fLib, aOption, aValue);
end;
 
procedure TAcarsd.SortTables;
begin
  acarsdSortTables(fLib);
end;
 
function TAcarsd.VInfo: string;
begin
  result := acarsdVInfo(fLib);
end;
 
end.
__________________
[ Sources et programmes de Dr.Who | FAQ Delphi | FAQ Pascal | Règlement | Contactez l'équipe ]
Ma messagerie n'est pas la succursale du forum... merci!
Dr.Who est déconnecté   Envoyer un message privé Réponse avec citation 20
Vieux 23/02/2013, 09h47   #10
[ZiP]
Membre confirmé
 
Homme
Inscription : octobre 2006
Messages : 807
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Pas de Calais (Nord Pas de Calais)

Informations forums :
Inscription : octobre 2006
Messages : 807
Points : 248
Points : 248
Bonjour Dr.Who,

Merci pour votre travail à cette heure si tardive !

ZiP
[ZiP] est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/02/2013, 11h00   #11
Ph. B.
Expert Confirmé
 
Avatar de Ph. B.
 
Homme Philippe
Inscription : avril 2002
Messages : 1 032
Détails du profil
Informations personnelles :
Nom : Homme Philippe
Âge : 46
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : avril 2002
Messages : 1 032
Points : 2 665
Points : 2 665
Envoyer un message via ICQ à Ph. B. Envoyer un message via Skype™ à Ph. B.
Citation:
Envoyé par [ZiP] Voir le message
Merci pour votre travail à cette heure si tardive !
Ouais, mais peu importe l'heure ou le jour, le Dr Who dispose du Tardis !
Plus sérieusement, pour la contribution !
__________________
Philippe.
Ph. B. est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/02/2013, 16h46   #12
[ZiP]
Membre confirmé
 
Homme
Inscription : octobre 2006
Messages : 807
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Pas de Calais (Nord Pas de Calais)

Informations forums :
Inscription : octobre 2006
Messages : 807
Points : 248
Points : 248
Bonjour,

Savez-vous comment transcrire ça :
Code c :
1
2
3
4
5
6
7
8
9
 
/* Version of libacarsd.* 
   Make a complete versionstring, use the following
   printf("libacarsd %d.%d Revision %d\n",
   libacarsdmajorversion,libacarsdminorversion,libacarsdrevision);
*/
EXPORT const int libacarsdminorversion;
EXPORT const int libacarsdmajorversion;
EXPORT const int libacarsdrevision;

J'ai essayé ça :
Code :
1
2
3
 
function libacarsdmajorversion: Integer; stdcall; external 'libacarsd.dll' name 'libacarsdmajorversion';
function libacarsdminorversion: Integer; stdcall; external 'libacarsd.dll' name 'libacarsdminorversion';
Mais j'ai un beau access violation

En effet, ça ne semble pas être des fonctions mais des constantes...

Une idée ?

Merci,
ZiP
[ZiP] est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/02/2013, 18h56   #13
tourlourou
Modérateur
 
Homme Yves Lemaire
Biologiste ; Progr(amateur)
Inscription : mars 2005
Messages : 1 684
Détails du profil
Informations personnelles :
Nom : Homme Yves Lemaire
Âge : 50
Localisation : France, Yvelines (Île de France)

Informations professionnelles :
Activité : Biologiste ; Progr(amateur)

Informations forums :
Inscription : mars 2005
Messages : 1 684
Points : 3 097
Points : 3 097
Tu as une piste dans ce post ; tout le thread est intéressant
__________________
Delphi 5 Pro et Code Typhon 2.80 sous Win 7 64 bits - Code Typhon 2.70 / Ubuntu 12.04 64 bits
tourlourou est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/02/2013, 21h31   #14
[ZiP]
Membre confirmé
 
Homme
Inscription : octobre 2006
Messages : 807
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Pas de Calais (Nord Pas de Calais)

Informations forums :
Inscription : octobre 2006
Messages : 807
Points : 248
Points : 248
Bonsoir,

Merci, je vais lire le thread complet.

ZiP
[ZiP] est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/02/2013, 21h36   #15
Ph. B.
Expert Confirmé
 
Avatar de Ph. B.
 
Homme Philippe
Inscription : avril 2002
Messages : 1 032
Détails du profil
Informations personnelles :
Nom : Homme Philippe
Âge : 46
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : avril 2002
Messages : 1 032
Points : 2 665
Points : 2 665
Envoyer un message via ICQ à Ph. B. Envoyer un message via Skype™ à Ph. B.
Bonjour,
Citation:
Envoyé par [ZiP] Voir le message
En effet, ça ne semble pas être des fonctions mais des constantes...

Une idée ?
En effet, ce ne sont pas des fonctions ou procédures !
Il faut donc écrire :
Code :
1
2
3
4
var
  Major: Integer; external 'libacarsd.dll' name 'libacarsdmajorversion';
  Minor: Integer; external 'libacarsd.dll' name 'libacarsdminorversion';
  Revision: Integer; external 'libacarsd.dll' name 'libacarsdrevision';
__________________
Philippe.
Ph. B. est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 23/02/2013, 22h03   #16
[ZiP]
Membre confirmé
 
Homme
Inscription : octobre 2006
Messages : 807
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Pas de Calais (Nord Pas de Calais)

Informations forums :
Inscription : octobre 2006
Messages : 807
Points : 248
Points : 248
Bonsoir Ph. B.,

Ça marche à merveille !

Merci !

Cordialement,
ZiP
[ZiP] est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/02/2013, 10h39   #17
tourlourou
Modérateur
 
Homme Yves Lemaire
Biologiste ; Progr(amateur)
Inscription : mars 2005
Messages : 1 684
Détails du profil
Informations personnelles :
Nom : Homme Yves Lemaire
Âge : 50
Localisation : France, Yvelines (Île de France)

Informations professionnelles :
Activité : Biologiste ; Progr(amateur)

Informations forums :
Inscription : mars 2005
Messages : 1 684
Points : 3 097
Points : 3 097
L'importation directe des variables exportées de dll dans Delphi n'était pas prévue jusqu'en Delphi 6 au moins, d'où l'astuce de gb_68.

Heureusement, Lazarus semble l'intégrer, et j'espère que Delphi a évolué depuis aussi...
__________________
Delphi 5 Pro et Code Typhon 2.80 sous Win 7 64 bits - Code Typhon 2.70 / Ubuntu 12.04 64 bits
tourlourou est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/02/2013, 12h31   #18
Ph. B.
Expert Confirmé
 
Avatar de Ph. B.
 
Homme Philippe
Inscription : avril 2002
Messages : 1 032
Détails du profil
Informations personnelles :
Nom : Homme Philippe
Âge : 46
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : avril 2002
Messages : 1 032
Points : 2 665
Points : 2 665
Envoyer un message via ICQ à Ph. B. Envoyer un message via Skype™ à Ph. B.
Citation:
Envoyé par tourlourou Voir le message
L'importation directe des variables exportées de dll dans Delphi n'était pas prévue jusqu'en Delphi 6 au moins, d'où l'astuce de gb_68.

Heureusement, Lazarus semble l'intégrer, et j'espère que Delphi a évolué depuis aussi...
Non, au moins juqu'à XE2 inclus !
Il faut passer par l'astuce donnée par gb_68 :
Comment utiliser une variable globale de dll ? (dynamique)
Comment utiliser une variable globale de dll ? (statique, fin de message)
__________________
Philippe.
Ph. B. est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 23h48.


 
 
 
 
Partenaires

Hébergement Web