Bonjour,

J'utilise une dll fournit avec un lecteur de carte

Cette dll possede une fonction permettant de mettre à jour le firmware du lecteur de carte, et une fonction de callback permettant de voir l'avancement du téléchargement/mise à jour de ce firmware.
Cette dll est codé en C.
Voici ce que j'ai dans la doc concernant cette fonction:

La fonction sCscSetInstallHookEx définit la fonction de rappel de progression-indicateur exécutée lors de l'exécution de la fonction sCscInstallFileEx (fonction de mise à jour du firmware)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
short sCscSetInstallHookEx(CSC_HANDLE hCsc,
                           fHookInstall pHookFunc,
                           void *pArg);
hCsc = Handle du lecteur de carte.
pHookFunc = Fonction de rappel fournie par l'utilisateur
pArg = Argument de rappel fourni par l'utilisateur, à utiliser par l'utilisateur dans la routine de rappel. (=> j'ai pas trop compris à quoi servait cet argument)

prototype de la fonction pHooFunc
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
typedef void (*fHookInstall)(CSC_HANDLE hCsc,
                             UINT ratio,
                             void *pArg);
hCsc = Handle du lecteur de carte.
ratio = indicateur de progression (0 a 100).
pArg = Argument sans type utilisateur. La valeur de pArg est la valeur transmise à la fonction sCscSetInstallHookEx.


Et voici mon code (c'est du code juste pour tester, pour comprendre comment ca fonctionne):

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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Imports System.Runtime.InteropServices
 
<StructLayout(LayoutKind.Sequential, CharSet := CharSet.Ansi)> _
Public Structure CSC_FW_INFO
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst := 48)> Public blVersionName As String
    Public blPushButtonGD As System.Byte
    Public appStatus As System.Byte
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst := 48)> Public appVersionName As String
    Public fwExecutionFlag As System.Byte
    <MarshalAs(UnmanagedType. ByValArray, SizeConst := 12)> Public serialNumber() As byte
End Structure
 
Public Delegate Sub fHookInstall (ByVal hCsc As System.UInt32, ByVal ratio As System.uint32, ByVal pArg As System.IntPtr) 'As System.Int16
Private shared ProcpHookFunc as fHookInstall
 
Public Class SocietyCscApi
 
<DllImport("SocietyCscApi.dll", EntryPoint:="sCSCReaderStartEx", SetLastError:=True, CharSet:=CharSet.ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Winapi)>
Public Shared Function sCSCReaderStartEx(byval pszComName As System.String, byval ulSpeed As System.UInt32, byref phCsc As System.UInt32) As System.Int16
End Function
 
<DllImport("SocietyCscApi.dll", EntryPoint:="sCscRebootEx", SetLastError:=True, CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Winapi)>
Public Shared Function sCscRebootEx(byval phCsc As System.UInt32) As System.Int16
End Function
 
<DllImport("SocietyCscApi.dll", EntryPoint:="sCscGetFwInfoEx", SetLastError:=True, CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Winapi)>
Public Shared Function sCscGetFwInfoEx(byval hCsc As System.UInt32, byref pFwInfo As CSC_FW_INFO) As System.Int16
End Function
 
<DllImport("SocietyCscApi.dll", EntryPoint:="sCscInstallFileEx", SetLastError:=True, CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Winapi)>
Public Shared Function sCscInstallFileEx(byval hCsc As System.UInt32, byval pszFileName As System.String) As System.Int16
End Function
 
<DllImport("SocietyCscApi.dll", EntryPoint:="sCscSetInstallHookEx", SetLastError:=True, CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Winapi)>
Public Shared Function sCscSetInstallHookEx(byval hCsc As System.UInt32, byval pHookFunc As fHookInstall, byval pArg As System.IntPtr) As System.Int16
End Function
 
End Class    
 
 
 
Public Partial Class MainForm
    Public Sub New()
        ' The Me.InitializeComponent call is required for Windows Forms designer support.
        Me.InitializeComponent()
 
        Dim retour As System.Int16
 
'Paramètre de la connexion avec le lecteur PORTCOM, SPEED, HANDLE
        Dim PORTCOM As System.String = "COM11"
        Dim SPEEDCOM As System.UInt32 = 0
        Dim pCSCHANDLE As New System.UInt32
 
'Paramètre pour le firmware
        Dim pFIRMINFO As New CSC_FW_INFO
        Dim pFILENAME As System.String = "Firmware.dfl"
 
 
        Dim ProcedurepHookFunc as New fHookInstall(AddressOf ProcpHookFunc)
 
 
        'initialise la connexion avec le lecteur
        retour = SocietyCscApi.sCSCReaderStartEx(PORTCOM, SPEEDCOM, pCSCHANDLE)
        'reboot pour etre sur que le lecteur est dans un état initial
        retour = SocietyCscApi.sCscRebootEx(pCSCHANDLE)
        'on récupère les infos du firmware existant
        retour = SocietyCscApi.sCscGetFwInfoEx(pCSCHANDLE, pFIRMINFO)
        'paramètrage de la fonction de callback pour la mise à jour du firmware
        retour = SocietyCscApi.sCscSetInstallHookEx(pCSCHANDLE, ProcedurepHookFunc, IntPtr.Zero)
        'mise à jour du lecteur avec le nouveau firmware
        retour = SocietyCscApi.sCscInstallFileEx(pCSCHANDLE, pFILENAME)
        'on récupère les infos du firmware mis à jour
        retour = SocietyCscApi.sCscGetFwInfoEx(pCSCHANDLE, pFIRMINFO)
 
    End Sub
 
    'Fonction de callback
    Private sub ProcpHookFunc (ByVal hCsc As System.UInt32, ByVal ratio As System.uint32, ByVal pArg As System.IntPtr)
 
            Msgbox(ratio)  'pour voir la valeur du ratio s'incrémenter
 
        End Sub
End Class
Mon problème est que je rentre bien dans la fonction de callback, mais à sa sortie j'ai l'erreur suivante:

"
Debug error
Program UpdateFirmware.exe
File: i386\chkesp.c
Line: 42

The value of ESP was not properly saved accross a function call. This is usually a result of callinf a function declared with one calling convention with a function pointer declared with a different calling convention
Pour écrire mon code je m'étais aidé de cette page:
https://olsimare.developpez.com/arti...k/?page=page_4

Mais la je suis bloqué, sans la fonction de callback, tous fonctionne bien , le firmware se met à jour, mais dés que j'essaie de faire appel à la fonction de call back, j'ai cette erreur que je n'arrive pas à résoudre.


NB: Je suis pas un expert en VB.net , j'essaie d'apprendre à travers cet essaie.

Merci