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

Lazarus Pascal Discussion :

Utilisation d'une DLL externe = crash ! [Lazarus]


Sujet :

Lazarus Pascal

  1. #1
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    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 : 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
     
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : 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
     
    /* 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

  2. #2
    Rédacteur/Modérateur
    Avatar de M.Dlb
    Inscrit en
    Avril 2002
    Messages
    2 465
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Avril 2002
    Messages : 2 465
    Points : 4 312
    Points
    4 312
    Par défaut
    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

  3. #3
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut
    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

  4. #4
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut
    Voici la liste des fonctions de ma DLL extraites avec DLL Export Viewer :
    ==================================================
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    function acarsd_init(const buf: Integer; const sample: Integer; const pass: Integer): P_libacarsd; external 'libacarsd.dll' name 'acarsd_init@12';
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    function acarsd_init(const buf: Integer; const sample: Integer; const pass: Integer): P_libacarsd; cdecl; external 'libacarsd.dll' name 'acarsd_init@12';
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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

  5. #5
    Expert confirmé
    Avatar de Ph. B.
    Homme Profil pro
    Freelance
    Inscrit en
    Avril 2002
    Messages
    1 784
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 784
    Points : 5 915
    Points
    5 915
    Par défaut
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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.

  6. #6
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    function acarsd_init(const buf: Integer; const sample: Integer; const pass: Integer): P_libacarsd; cdecl; external NomDLL name 'acarsd_init@12';
    Ou ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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 Fichiers attachés

  7. #7
    Expert confirmé
    Avatar de Ph. B.
    Homme Profil pro
    Freelance
    Inscrit en
    Avril 2002
    Messages
    1 784
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 784
    Points : 5 915
    Points
    5 915
    Par défaut
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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.

  8. #8
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut
    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

  9. #9
    Membre éprouvé
    Avatar de Dr.Who
    Inscrit en
    Septembre 2009
    Messages
    980
    Détails du profil
    Informations personnelles :
    Âge : 45

    Informations forums :
    Inscription : Septembre 2009
    Messages : 980
    Points : 1 294
    Points
    1 294
    Par défaut
    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
    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!

  10. #10
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut
    Bonjour Dr.Who,

    Merci pour votre travail à cette heure si tardive !

    ZiP

  11. #11
    Expert confirmé
    Avatar de Ph. B.
    Homme Profil pro
    Freelance
    Inscrit en
    Avril 2002
    Messages
    1 784
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 784
    Points : 5 915
    Points
    5 915
    Par défaut
    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.

  12. #12
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut
    Bonjour,

    Savez-vous comment transcrire ça :
    Code c : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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

  13. #13
    Modérateur
    Avatar de tourlourou
    Homme Profil pro
    Biologiste ; Progr(amateur)
    Inscrit en
    Mars 2005
    Messages
    3 865
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Yvelines (Île de France)

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

    Informations forums :
    Inscription : Mars 2005
    Messages : 3 865
    Points : 11 331
    Points
    11 331
    Billets dans le blog
    6
    Par défaut
    Tu as une piste dans ce post ; tout le thread est intéressant
    Delphi 5 Pro - Delphi 11.3 Alexandria Community Edition - CodeTyphon 6.90 sous Windows 10 ; CT 6.40 sous Ubuntu 18.04 (VM)
    . Ignorer la FAQ Delphi et les Cours et Tutoriels Delphi nuit gravement à notre code !

  14. #14
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut
    Bonsoir,

    Merci, je vais lire le thread complet.

    ZiP

  15. #15
    Expert confirmé
    Avatar de Ph. B.
    Homme Profil pro
    Freelance
    Inscrit en
    Avril 2002
    Messages
    1 784
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 784
    Points : 5 915
    Points
    5 915
    Par défaut
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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.

  16. #16
    Membre averti
    Homme Profil pro
    Paramétreur de progiciels
    Inscrit en
    Octobre 2006
    Messages
    970
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Paramétreur de progiciels

    Informations forums :
    Inscription : Octobre 2006
    Messages : 970
    Points : 381
    Points
    381
    Par défaut
    Bonsoir Ph. B.,

    Ça marche à merveille !

    Merci !

    Cordialement,
    ZiP

  17. #17
    Modérateur
    Avatar de tourlourou
    Homme Profil pro
    Biologiste ; Progr(amateur)
    Inscrit en
    Mars 2005
    Messages
    3 865
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Yvelines (Île de France)

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

    Informations forums :
    Inscription : Mars 2005
    Messages : 3 865
    Points : 11 331
    Points
    11 331
    Billets dans le blog
    6
    Par défaut
    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 - Delphi 11.3 Alexandria Community Edition - CodeTyphon 6.90 sous Windows 10 ; CT 6.40 sous Ubuntu 18.04 (VM)
    . Ignorer la FAQ Delphi et les Cours et Tutoriels Delphi nuit gravement à notre code !

  18. #18
    Expert confirmé
    Avatar de Ph. B.
    Homme Profil pro
    Freelance
    Inscrit en
    Avril 2002
    Messages
    1 784
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Freelance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 784
    Points : 5 915
    Points
    5 915
    Par défaut
    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.

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

Discussions similaires

  1. [WD12] Utilisation d'une dll externe
    Par rems033 dans le forum WinDev
    Réponses: 4
    Dernier message: 10/12/2009, 14h07
  2. [WD12] utiliser une DLL externe
    Par yann_72 dans le forum WinDev
    Réponses: 8
    Dernier message: 31/07/2008, 09h12
  3. Utilisation d'une classe externe dans une DLL
    Par xChRiSx dans le forum C++
    Réponses: 6
    Dernier message: 04/06/2007, 09h32
  4. Probleme d'utilisation d'une DLL externe
    Par Pasiphae dans le forum C++/CLI
    Réponses: 2
    Dernier message: 19/02/2007, 15h17
  5. dll ActiveX utilisant une DLL externe
    Par Metal3d dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 10/11/2005, 18h02

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