Utilisation d une DLL

ncyshaolin Messages postés 6 Date d'inscription mercredi 21 novembre 2007 Statut Membre Dernière intervention 4 janvier 2008 - 10 déc. 2007 à 16:43
ncyshaolin Messages postés 6 Date d'inscription mercredi 21 novembre 2007 Statut Membre Dernière intervention 4 janvier 2008 - 4 janv. 2008 à 12:13
Bonjour,

Dans le cadre de mon boulot, je dois utiliser une DLL creee par un organisme europeen qui permet de calculer l attenuation sonore due aux reliefs et conditions meteo. Pour se faire, je dois utiliser differentes fonctions dont les prototypes en C sont:
<li>void* P2P_Create (void)</li><li>int P2P_Clear (void* p2p_struct)</li><li>int P2P_AddSegment (void* p2p_struct, double D, double Z, int impedanceModel)</li><li>int P2P_SetSourceHeight (void* p2p_struct, double hSource, double delta_hs)</li><li>int P2P_SetReceiverHeight (void* p2p_struct, double hRec, double delta_hRec)</li><li>int P2P_GetResults (void* p2p_struct, double *att_dB)</li><li>void P2P_Delete (void* p2p_struct)</li>Apres pas mal de recherche sur Internet, surtout pour le void*, j ai abouti a ce code:
<hr size="2" width="100%" />Imports System.Runtime.InteropServices

Module Module1
    Private Declare Function Create Lib "C:\Documents and Settings\guerini-grossc\My Documents\PointToPoint.dll" Alias "P2P_Create" () As Byte
    Private Declare Function Clear Lib "C:\Documents and Settings\guerini-grossc\My Documents\PointToPoint.dll" Alias "P2P_Clear" (<MarshalAsAttribute(UnmanagedType.AsAny)> ByVal p2p_struct As Object) As Integer
    Private Declare Function AddSegment Lib "C:\Documents and Settings\guerini-grossc\My Documents\PointToPoint.dll" Alias "P2P_AddSegment" (<MarshalAsAttribute(UnmanagedType.AsAny)> ByVal p2p_struct As Object, 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" (<MarshalAsAttribute(UnmanagedType.AsAny)> ByVal p2p_struct As Object, 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" (<MarshalAsAttribute(UnmanagedType.AsAny)> ByVal p2p_struct As Object, 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" (<MarshalAsAttribute(UnmanagedType.AsAny)> ByVal p2p_struct As Object, 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" (<MarshalAsAttribute(UnmanagedType.AsAny)> ByVal p2p_struct As Object) As Double
    Private Declare Function VersionDLL Lib "C:\Documents and Settings\guerini-grossc\My Documents\PointToPoint.dll" Alias "P2P_GetVersionDLL" (<MarshalAsAttribute(UnmanagedType.AsAny)> ByVal p2p_struct As Object) As Double

    Sub Main()
        Dim p2p As Byte
        Dim att(0 To 27) As Double

        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)
        AddSegment(p2p, 60.0, -3.0, 3)
        SetSourceHeight(p2p, 0.3, 0.0)
        SetReceiverHeight(p2p, 5.0, 0.0)
        'GetResults(p2p, att(0))
        Delete(p2p)

        'Dim i As Integer
        'For i = 0 To att.GetUpperBound(0)
        '   Console.WriteLine("att(" & i & ") = " & att(i))
        'Next i
        Dim ligne As String = Console.In.ReadLine()
    End Sub

End Module
<hr size="2" width="100%" />
Cela semble fonctionner pour toutes les fonctions excepte la fonction principale GetResults qui fait tout planter avec une erreur de type:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt

J ai vraiment besoin de faire fonctionner cette DLL. Aidez moi s il vous plait. Je ne sais pas si c est un probleme avec mon void* ou autre chose...

5 réponses

mstarsup5 Messages postés 527 Date d'inscription lundi 15 octobre 2007 Statut Membre Dernière intervention 10 octobre 2013 1
10 déc. 2007 à 17:56
Salut,

c'est peut être (sûrement) con ce que je dis, mais pour toutes tes fonctions tu utilises des ByVal, et pour ta fonction GetResult, tu utilises un ByRef, tu as essayé un ByVal?

 Pourapprendretoujoursplus!
0
ncyshaolin Messages postés 6 Date d'inscription mercredi 21 novembre 2007 Statut Membre Dernière intervention 4 janvier 2008
10 déc. 2007 à 20:04
oui j'ai essayé les 2. La synthaxe que j utilise vient d un tuto pour faire passer un tableau donc normalement c'est par ref dans le tuto mais bon, je suis ouvert a toutes les propositions
0
Utilisateur anonyme
24 déc. 2007 à 16:12
(vb.net 2005)
essaye ça:

<DllImport("C:\Documents and Settings\guerini-grossc\My Documents\PointToPoint.dll", EnTryPoint:="P2P_GetResults")> Public Shared Function GetResults( <MarshalAsAttribute(UnmanagedType.AsAny)> ByVal p2p_struct As
Object, ByRef att_dB As Double) As Integer
End Function

ou ça (IntPtr):
<DllImport("C:\Documents and Settings\guerini-grossc\My Documents\PointToPoint.dll", EnTryPoint:="P2P_GetResults")> Public Shared Function GetResults( <MarshalAsAttribute(UnmanagedType.AsAny)> ByVal p2p_struct As
Object, ByRef att_dB As Double) As IntPtr
End Function
0
ncyshaolin Messages postés 6 Date d'inscription mercredi 21 novembre 2007 Statut Membre Dernière intervention 4 janvier 2008
24 déc. 2007 à 17:14
Merci,

je suis en vacances, je regarderai en janvier...
Ca pourrait me faire un joli cadeau de noel!

;-)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
ncyshaolin Messages postés 6 Date d'inscription mercredi 21 novembre 2007 Statut Membre Dernière intervention 4 janvier 2008
4 janv. 2008 à 12:13
ca ne marche toujours pas....
Je commence a desesperer, j ai toujours l erreur:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

S' il vous plait aidez moi!!
0
Rejoignez-nous