Bonjour à tous,

J'ai une question concernant l'utilisation d'une dll issu du Fortran que je voudrais utiliser dans un prog VB. La spécificité de la DLL que je cherche à utiliser est qu'elle contient une fonction externe (fcn) à définir par l'utilisateur, pour que ce soit clair, voici un extrait du code Fortran (que j'ai simplifié au max) :
Code fortran : 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
subroutine SOMME ( fcn, a,b,c, info)
!  Parameters:
!
!    Input, 
!    external FCN, the name of the user-supplied subroutine which
!    calculates the functions.  The routine should have the form:
!
!      subroutine fcn ( a, b, c, iflag )
!
!      real a
!      real b
!      real c
!      integer ( kind = 4 ) iflag
!
!    The value of IFLAG should not be changed by FCN unless
!    the user wants to terminate execution of the routine.
!    In this case set IFLAG to a negative integer.
!
!    Input, real  a, number to sum.
!
!    Input, real  b, number to sum.
!
!    Ouput, real c, the functions evaluated at (a,b) -> c = a+b.
!
!    Output, integer  INFO, error flag.  If the user has terminated 
!    execution, INFO is set to the (negative) value of IFLAG. See the
!    description of FCN. 
!
  !DEC$ ATTRIBUTES DLLEXPORT, ALIAS : "SOMME" :: SOMME
  implicit none
  real    ( kind = 8 ) a
  real    ( kind = 8 ) b
  real    ( kind = 8 ) c
  external             fcn
  integer ( kind = 4 ) info
  integer ( kind = 4 ) iflag
  info = 0
  iflag = 10
  call fcn (a,b,c ,iflag)
 
  info = iflag	
  return
end

Dans mon prog VB, je voudrais utiliser la dll. Je dois donc définir la fonction fcn et appeler la dll pour qu'elle utilise la fcn. voici l'extrait de code en VB :

Code vb : 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
Public Class Form1
 
    Public Msg As String
    Delegate Sub deleguefvecJCH(ByRef ad As Double, ByRef bd As Double, ByRef cd As Double, ByRef iflagd As Integer)
 
    Declare Sub SOMME Lib "fonction_dll.dll" (ByRef fcn As deleguefvecJCH, ByRef ad As Double, ByRef bd As Double, ByRef cd As Double, ByRef INFO As Integer)
 
    Public Sub fvecJCH(ByRef a As Double, ByRef b As Double, ByRef c As Double, ByRef iflag As Integer)
        ' eternal function to be calculate in the dll
        On Error GoTo Err_fvecJCH
        c = a + b
        Exit Sub
Err_fvecJCH:
        iflag = -1
        Msg = "fvecJCH : " & Err.Description
        MsgBox(Msg, 16, "Error")
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        Dim a = 2, b = 1.5
        Dim c As Double
        Dim INFO As Integer = 20
        Dim adressefvecJCH As New deleguefvecJCH(AddressOf fvecJCH)
 
        Dim iflag = 20
 
        ' dll call
        SOMME(adressefvecJCH, a, b, c, INFO)
 
        a = 1
    End Sub
End Class

quand je compile ce code, un message d'erreur apparaît : "attempted to read or write protected memory".
Est ce que quelqu'un aurait une idée du problème ?

Merci d'avance,

Juliette