ncyshaolin
Messages postés6Date d'inscriptionmercredi 21 novembre 2007StatutMembreDernière intervention 4 janvier 2008
-
10 déc. 2007 à 16:43
ncyshaolin
Messages postés6Date d'inscriptionmercredi 21 novembre 2007StatutMembreDerniè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
'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...
mstarsup5
Messages postés527Date d'inscriptionlundi 15 octobre 2007StatutMembreDernière intervention10 octobre 20131 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?
ncyshaolin
Messages postés6Date d'inscriptionmercredi 21 novembre 2007StatutMembreDerniè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
<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