Import einer C++ DLL (Fehlerfrei in IDE,Absturz in Exe)

  • VB.NET

Es gibt 3 Antworten in diesem Thema. Der letzte Beitrag () ist von AlexE.

    Import einer C++ DLL (Fehlerfrei in IDE,Absturz in Exe)

    Hallo liebe Community,

    ich habe ein Programm was eine C++ DLL importiert und von dieser Daten empfängt.Das ganze funktioniert auch.Hab leider nur das Problem das wenn ich das Programm außerhalb der IDE ausführe ,nach ein paar Sekunden das Programm abstürzt.(die ersten Aufrufe der DLL gehen noch durch)

    Mit folgender Meldung

    Quellcode

    1. Problemsignatur:
    2. Problemereignisname:APPCRASH
    3. Application Name:WindowsApplication4.exe
    4. Application Version:1.0.0.0
    5. Application Timestamp:4ea5264b
    6. Fault Module Name:unknown
    7. Fault Module Version:0.0.0.0
    8. Fault Module Timestamp:00000000
    9. Exception Code:c0000005
    10. Exception Offset:00411624
    11. Betriebsystemversion:6.1.7600.2.0.0.256.1
    12. Gebietsschema-ID:1031



    EDIT :

    Exception Code steht für folgendes :

    0xC0000005
    EXCEPTION_ACCESS_VIOLATION
    The thread tried to read from or write to a virtual address for which it does not have the appropriate access.


    Mein VB Code :

    VB.NET-Quellcode

    1. Imports System.Runtime.InteropServices
    2. Imports System.Reflection
    3. Imports System.IO
    4. Public Class Form1
    5. #Region "DLL-IMPORT"
    6. Declare Function SetKeyboardHook Lib "dskbhook" (ByVal hwnd As Integer, ByVal Callback As Integer, ByVal Adr As CallbackD) As UInteger
    7. Declare Function SetGlobalParams Lib "dskbhook" (ByVal Repeat As Integer, ByVal Discard As Integer) As UInteger
    8. Declare Function SetKeyParams& Lib "dskbhook" (ByVal KeyCode&, ByVal SCAE&, ByVal RDC&)
    9. Declare Function UseSendMessage Lib "dskbhook" (ByVal Send As Integer) As UInteger
    10. Declare Function SkipInjected& Lib "dskbhook" (ByVal Skip&)
    11. Declare Function NoLLHook Lib "dskbhook" (ByVal LLHook As Integer) As UInteger
    12. Declare Function SetStop& Lib "dskbhook" (ByVal Stp&)
    13. Declare Function HookVB& Lib "dskbhook" (ByVal Hook&)
    14. Declare Function NoTL& Lib "dskbhook" (ByVal TL&)
    15. Declare Function IsNT& Lib "dskbhook" ()
    16. #End Region
    17. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    18. NoLLHook(0)
    19. UseSendMessage(0)
    20. SetKeyboardHook(-1, 1, AddressOf Callback)
    21. SetGlobalParams(0, 1)
    22. End Sub
    23. Public Delegate Sub CallbackD(ByVal action As Integer, ByVal state As Integer, ByVal vcode As Integer, ByVal scode As Integer)
    24. Public Sub Callback(ByVal action As Integer, ByVal state As Integer, ByVal vcode As Integer, ByVal scode As Integer)
    25. RichTextBox1.AppendText(state.ToString & "!" & vcode.ToString & "!" & scode.ToString)
    26. End Sub
    27. End Class


    Bitte helft mir weiter, bin schon am verzweifeln.

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „AlexE“ ()

    Hat sich der erledigt...

    Der Delegat auf den vom Callback verwiesen wurde wurde vom Gargabe Collector eingesammelt.

    Hab ich so gelöst

    VB.NET-Quellcode

    1. Region "DLL-IMPORT"
    2. Declare Function SetKeyboardHook Lib "dskbhook" (ByVal hwnd As Integer, ByVal Callback As Integer, ByVal Adr As CallbackD) As UInteger
    3. Declare Function SetGlobalParams Lib "dskbhook" (ByVal Repeat As Integer, ByVal Discard As Integer) As UInteger
    4. Declare Function SetKeyParams& Lib "dskbhook" (ByVal KeyCode&, ByVal SCAE&, ByVal RDC&)
    5. Declare Function UseSendMessage Lib "dskbhook" (ByVal Send As Integer) As UInteger
    6. Declare Function SkipInjected& Lib "dskbhook" (ByVal Skip&)
    7. Declare Function NoLLHook Lib "dskbhook" (ByVal LLHook As Integer) As UInteger
    8. Declare Function SetStop& Lib "dskbhook" (ByVal Stp&)
    9. Declare Function HookVB& Lib "dskbhook" (ByVal Hook&)
    10. Declare Function NoTL& Lib "dskbhook" (ByVal TL&)
    11. Declare Function IsNT& Lib "dskbhook" ()
    12. Dim handler As CallbackD = AddressOf Callback


    VB.NET-Quellcode

    1. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    2. NoLLHook(0)
    3. UseSendMessage(0)
    4. SetGlobalParams(0, 1)
    5. SetKeyboardHook(-1, 1, handler)