Dll Callback/Context

    • Offizieller Beitrag

    Hallo

    Ich stehe (schon wieder) auf dem Schlauch ;)
    Ich will ein CallBack erzeugen. Aber wenn dieser Callback aufgerufen werden sollte, stürzt AutoIt ab (AutoIt.exe hat ein Problem festgestellt und muss...)
    In der Hilfe steht:

    Spoiler anzeigen

    lgLcdSoftbuttonsChangedContext/lgLcdOnSoftButtonsCB
    The lgLcdSoftbuttonsChangedContext is part of the lgLcdOpenContext and is used to give the library enough information to allow changes in the state of the soft buttons to be signaled into the calling application through a callback.

    [/spoiler]

    Mein Versuch sah ca so aus:

    [autoit]

    Global Const $LGLCD_STRUCT_SoftbuttonsChangedContext = DllStructCreate("ptr;ptr")

    [/autoit] [autoit][/autoit] [autoit]

    $hReg = DllCallbackRegister("_Test","dword","int;dword;ptr")

    [/autoit] [autoit][/autoit] [autoit]

    DllStructSetData($LGLCD_STRUCT_SoftbuttonsChangedContext,1,DllCallbackGetPtr($hReg))
    DllStructSetData($LGLCD_STRUCT_SoftbuttonsChangedContext,2,DllCallbackGetPtr($hReg))
    ;[...]
    Func _Test($iDevice,$dwButtons,$pContext)
    ConsoleWrite($iDevice & @CRLF)
    ConsoleWrite($dwButtons & @CRLF)
    ConsoleWrite($pContext & @CRLF)
    EndFunc

    [/autoit]


    (Bei [...] ist natürlich noch mehr Code)

    Aber er schafft noch nicht mal die ConsoleWrites. Sobald ich die Buttons auf dem LCD drücke schmiert er ab. Interessant ist auch, dass selbst wenn ich dies Freilasse, also statt "DllCallbackGetPtr($hReg)" einfach False reinschreibe (sollte laut Hilfe ja klappen) schmiert er auch ab.

    Hat da jemand eine Idee?
    Vielen Dank :)

    Mfg Spider

  • also, versuch mal, die Struct ohne Const zu deklarieren oder auch ein cdecl callback.. hab leider keine G15 zum testen :(

    [autoit]

    Global $LGLCD_STRUCT_SoftbuttonsChangedContext = DllStructCreate("ptr;ptr")

    [/autoit][autoit][/autoit][autoit]

    $hReg = DllCallbackRegister("_Test","dword","int;dword;ptr")
    ; sollte stimmen, teste aber auch mal cdecl, auch wenn WINAPI stdcall sein soll ;)
    ; $hReg = DllCallbackRegister("_Test","dword:cdecl","int;dword;ptr")

    [/autoit][autoit][/autoit][autoit]

    DllStructSetData($LGLCD_STRUCT_SoftbuttonsChangedContext,1,DllCallbackGetPtr($hReg)) ; Pointer zum Callback
    DllStructSetData($LGLCD_STRUCT_SoftbuttonsChangedContext,2,0x102030) ; Wert von pContext
    ;[...]
    Func _Test($iDevice,$dwButtons,$pContext)
    ConsoleWrite($iDevice & @CRLF)
    ConsoleWrite($dwButtons & @CRLF)
    ConsoleWrite($pContext & @CRLF) ; sollte 0x102030 sein
    EndFunc

    [/autoit]

    //Edit: vielleicht ist der Code falsch, in dem du das Callback setzt...

    //Edit: hast du auch beachtet, dass die Struct direkt, ohne Pointer in lgLcdOpenContext eingebunden ist?
    -->

    [autoit]

    Global Const $lgLcdSoftbuttonsChangedContext= "ptr softbuttonsChangedCallback; ptr softbuttonsChangedContext;"
    Global Const $lgLcdOpenContext = "int connection; int index;" & $lgLcdSoftbuttonsChangedContext & " int device;"
    [...]
    $OpenStruct = DLLStructCreate($lgLcdOpenContext)
    DLLStructSetData($OpenStruct,"softbuttonsChangedCallback",DLLCallbackGetPtr($hReg))
    DLLStructSetData($OpenStruct,"softbuttonsChangedContext",0x102030)
    [...]

    [/autoit]

    2 Mal editiert, zuletzt von progandy (26. Dezember 2008 um 16:15)