Bonjour,

Je pense que ce probleme a deja etait aborde plusieurs fois mais apres avoir cherche partout je ne trouve toujours pas la reponse a mon probleme. Je souhaite utiliser un dll detaillant une methode de calcul pour l implementer dans un programme en VB. Je cherche donc a utiliser les fonctions qui se trouvent dans le dll. Le probleme est la correspondance des types.
Je souhaite pour l instant simplement adapter un simple exemple d utilisation du dll en C dans un environnement VB.
L exemple est tres simple en C :

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
void* p2p ;
double att[27] ;
// initialize the PointToPoint module
p2p = P2P_Create() ;
if (p2p == NULL)
{
... // error handling : could not create a P2P structure
}
// setup the cross-section
// remember : the origin = point on the road surface below the source
P2P_Clear(p2p) ; // source foot point (0,0)
P2P_AddSegment (p2p, 10.0, 0.0, 7) ; // top of embankment
P2P_AddSegment (p2p, 14.0, -3.0, 5) ; // bottom of embankment
P2P_AddSegment (p2p, 50.0, -3.0, 4) ; // receiver foot point
// set the source and receiver heights relative to the local terrain
// heights at the first and last points of the cross-section
P2P_SetSourceHeight (p2p, 0.3, 0.0) ;
P2P_SetReceiverHeight (p2p, 5.0, 0.0) ;
// calculate the excess attenuation and return the result in “att”
P2P_GetResult (p2p, att) ;
// do something with the excess attenuation values...
Mon code VB est le suivant :

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
Private Declare Function Create Lib "C:\Documents and Settings\guerini-grossc\My Documents\PointToPoint.dll" Alias "P2P_Create" () As Integer
    Private Declare Function Clear Lib "C:\Documents and Settings\guerini-grossc\My Documents\PointToPoint.dll" Alias "P2P_Clear" (ByRef p2p_struct As Integer) As Integer
    Private Declare Function AddSegment Lib "C:\Documents and Settings\guerini-grossc\My Documents\PointToPoint.dll" Alias "P2P_AddSegment" (ByRef p2p_struct As Integer, ByVal D As Double, ByVal Z As Double, ByVal impedanceModel As Integer) As Integer
    Private Declare Function SetSourceHeight Lib "C:\Documents and Settings\guerini-grossc\My Documents\PointToPoint.dll" Alias "P2P_SetSourceHeight" (ByRef p2p_struct As Integer, ByVal hSource As Double, ByVal delta_hs As Double) As Integer
    Private Declare Function SetReceiverHeight Lib "C:\Documents and Settings\guerini-grossc\My Documents\PointToPoint.dll" Alias "P2P_SetReceiverHeight" (ByRef p2p_struct As Integer, ByVal hRec As Double, ByVal delta_hRec As Double) As Integer
    Private Declare Function GetResults Lib "C:\Documents and Settings\guerini-grossc\My Documents\PointToPoint.dll" Alias "P2P_GetResults" (ByRef p2p_struct As Integer, ByRef att_dB As Double) As Integer
    Private Declare Function Delete Lib "C:\Documents and Settings\guerini-grossc\My Documents\PointToPoint.dll" Alias "P2P_Delete" (ByRef p2p_struct As Integer)
 
    Sub Main()
        Dim p2p As Integer
        p2p = Create()
        Clear(p2p)
        AddSegment(p2p, 10.0, 10.0, 1)
        'AddSegment(p2p, 14.0, -3.0, 5)
        'AddSegment(p2p, 50.0, -3.0, 4)
        'SetSourceHeight(p2p, 0.3, 0.0)
        'SetReceiverHeight(p2p, 5.0, 0.0)
 
        ' Dim att(0 To 27) As Double
 
        'GetResults(p2p, att(0))
 
    End Sub
J obtiens un message d erreur du type :
The runtime has encountered a fatal error. The address of the error was at 0x79e784b6, on thread 0xc78. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
La fonction AddSegment fait planter le tout. Je pense que cela provient du fait que toutes les fonctions attendent un void* et que moi je passe un Integer Byref. Je ne sais pas quoi faire. Si quelqu un peut m aider

Please....