Probleme avec API

DeveloppeurVb
Messages postés
125
Date d'inscription
mardi 18 février 2003
Statut
Membre
Dernière intervention
19 avril 2016
- 29 mars 2013 à 12:16
Bonjour,

j'ai la function suivente crite en C++ a traduire vers vb.net.
typedef unsigned short  (API_ENTRY _DLL_PTR T_Hn_IntroductionMstCPS)
(IN short sTempsAttente,
OUT char tcCodeCivilite[2],
OUT char szNomPatronymique[27],
OUT char FARPTR pcPresentPinCode,
OUT short FARPTR psEtatCarte,
OUT unsigned short FARPTR pusCodeErreur);


j'utilise une classe :
Private Class NativeMethods
        ' Methods
        <DllImport("kernel32.dll")> _
        Public Shared Function FreeLibrary(ByVal hModule As IntPtr) As Boolean
        End Function

        <DllImport("kernel32.dll")> _
        Public Shared Function GetProcAddress(ByVal hModule As IntPtr, ByVal procedureName As String) As IntPtr
        End Function

        <DllImport("kernel32.dll")> _
        Public Shared Function LoadLibrary(ByVal dllToLoad As String) As IntPtr
        End Function

    End Class

pour executer ma fonctions API je fais comme suit.
Public Function IntroEtMiseSousTensionCPS() As UInt16
        Debug.WriteLine("Mise sous tension CPS")
        Dim CodeCivilite As Char() = ""
        Dim NomPatronymique As Char() = ""
        Dim PresentPINCode As Char() = ""
        Dim EtatCarte As Short = 0
        Dim ErrorCode As UInt16
        TempsAttente = 0
        Try
            IntroEtMiseSousTensionCPS = HnIntroductionMstCPS(TempsAttente, CodeCivilite, NomPatronymique, PresentPINCode, EtatCarte, ErrorCode)

        Catch ex As Exception

        End Try
        Debug.WriteLine("Retour de la fonction Hn_IntroductionMstCPS : Nom=" & NomPatronymique & " ; PresentPINCode =" & PresentPINCode & " ; ErrorCode =" & ErrorCode & " ; Rc =" & IntroEtMiseSousTensionCPS)
        If (IntroEtMiseSousTensionCPS <> 0) Then
            ReadingAPIExceptionHelper.ThrowExceptionFromReturnCode(IntroEtMiseSousTensionCPS)
        End If
        Return IntroEtMiseSousTensionCPS
    End Function

via cette function :
Private Delegate Function Hn_IntroductionMstCPS(ByVal sTempsAttente As Short, _
                                                    ByRef tcCodeCivilite As Char(), _
                                                    ByRef szNomPatronymique As Char(), _
                                                    ByRef pcPresentPINCode As Char(), _
                                                    ByRef psEtatCarte As Short, _
                                                    ByRef ErrorCode As UInt16) As UInt16

    Private Function HnIntroductionMstCPS(ByVal sTempsAttente As Short, _
                                          ByRef tcCodeCivilite As Char(), _
                                          ByRef szNomPatronymique As Char(), _
                                          ByRef pcPresentPINCode As Char(), _
                                          ByRef psEtatCarte As Short, _
                                          ByRef ErrorCode As UInt16) As UInt16
        If (Me.pDll = IntPtr.Zero) Then
            MsgBox("Les API de lecture ne sont pas charg" & ChrW(233) & "es.", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "")
        End If
        Dim delegateForFunctionPointer As Hn_IntroductionMstCPS = DirectCast(Marshal.GetDelegateForFunctionPointer(NativeMethods.GetProcAddress(Me.pDll, "Hn_IntroductionMstCPS"), GetType(Hn_IntroductionMstCPS)), Hn_IntroductionMstCPS)
        Return delegateForFunctionPointer.Invoke(sTempsAttente, tcCodeCivilite, szNomPatronymique, pcPresentPINCode, psEtatCarte, ErrorCode)
    End Function

Mon probleme est que j'ai une exception de type 'System.ExecutionEngineException' qui est levée, uniquement avec ette fonction, les autres API fonctionnent.
Toutes les suggestions sont les biens venues.
Merci