J'essaie d'utiliser une DLL non managée dans VB.NET. L'exemple de code source fourni avec la DLL est en VB6 et ci-dessous est ma tentative de le convertir en .NET. Lorsque la DLL tente d'effectuer un rappel, j'obtiens une exception «Tentative de lecture ou d'écriture de mémoire protégée». Je ne me soucie pas vraiment de la fonction de rappel appelée. Mon code:Fonction de rappel à partir d'une DLL non gérée dans VB .NET
<DllImport("AlertMan.dll")> _
Public Shared Function AlertManC(_
ByVal CallbackAddr As AlertManCallbackDel) As Long
End Function
Public Delegate Sub AlertManCallbackDel(ByVal data As Long)
Public Sub AlertManCallback(ByVal data As Long)
End Sub
Public mydel As New AlertManCallbackDel(AddressOf AlertManCallback)
'protected memeory exception here
Dim IStat as Long = AlertManC(mydel)
exemple de code original VB6:
Declare Function AlertManC _
Lib "AlertMan.dll" _
Alias "AlertManC" (ByVal CallbackAddr As Long) As Long
Private Sub AlertManCallback(ByVal data As Long)
End Sub
' calling code
Dim IStat As Long
IStat = AlertManC(AddressOf AlertManCallBack)
tête dll originale
typedef void TACBFUNC(char *);
int AlertManC(TACBFUNC *WriteCaller cHANDLEPARM);
Merci, vous bercez! Changer de long en nombre était le problème! Votre solution originale aurait aussi bien fonctionné. il y a en fait 7 autres paramètres sur la méthode que j'ai enlevé pour la brièveté (honte à moi). Les changer en entiers était l'astuce. – Michael