Hi John,
when I am in situation I need a callback in ThinBASIC, I use Oxygen module to handle this for me. Below little example:
' ---------------------------------------------------------------------------------------
' JIT Part Beginning
' ---------------------------------------------------------------------------------------
Uses "Oxygen"
DWord oxyCallback ' -- This will contain pointer to JIT function Oxygen_Callback
DWord oxyTerminate ' -- This will contain pointer to JIT function Oxygen_Terminate
String callbackCode = "
basic
Sub Oxygen_Callback CDECL ( ByVal param1 As DWord) Link #oxyCallback
Dim strMsg As String
strMsg = `Passed param = ` & Str(param1)
Print strMsg
End Sub
Sub Oxygen_Terminate() Link #oxyTerminate
terminate
End Sub
"
' -- JIT compile
O2_BASIC callbackCode
' -- Check for errors
If Len(O2_ERROR) Then
MsgBox 0, O2_ERROR, "JIT compilation failed"
Stop
End If
' -- Activate
O2_EXEC
' ---------------------------------------------------------------------------------------
' JIT Part End
' ---------------------------------------------------------------------------------------
' -- Declare functions from oxygen
Declare Sub Oxygen_Callback ( ByVal param1 As DWord)
Declare Sub Oxygen_Terminate ()
' -- Assign them address to make em callable
Declare Set Address Oxygen_Callback , oxyCallback
Declare Set Address Oxygen_Terminate, oxyTerminate
' -- Main code
Function TBMain()
MsgBox 0, "The code pointer to Oxygen_Callback is &h0" + Hex$(oxyCallback)
MsgBox 0, "The code pointer to Oxygen_Terminate is &h0" + Hex$(oxyTerminate)
Oxygen_Callback(123)
Oxygen_Terminate()
End Function
Petr
Bookmarks