PDA

View Full Version : COM Callback



steinie
10-09-2011, 15:34
I have opened a USB interface with COM and the send works fine.:p
I need a CallBack for the input.

Here is a short script, the first part works, just need callback.:neutral:



' AH COM GUI script created on 09-10-2011 07:30:05 by: JDS (ThinAIR)

Uses "Console"
Uses "UI"
Uses "COM" ' -- Create object

Dim Chndl As Long
Dim i As Single
Dim Params(7) As Variant
Dim RetVal As Variant
Chndl = Console_Alloc
Function TBMain()

DWord AHO = COM_CREATEOBJECT ("X10.ActiveHome", Params(7))
' -- Call method (parameters should be supplied in form of Variant array)

Params(1) = "sendplc"
Params(2) = "O09 on"
COM_CALLMETHOD(AHO, "SendAction", 2, Params(),RetVal)


Params(2) = "o09 off"
COM_CALLMETHOD(AHO, "SendAction", 2, Params(), RetVal)

While Time$

If GetAsyncKeyState(%VK_ESCAPE) Then Exit While
Wend

COM_RELEASE(AHO)

End Function
'---------------------------------------
CallBack Function AHO_RecvAction (ByVal bszRecv As Variant _
, ByVal vParm1 As Variant _
, ByVal vParm2 As Variant _
, ByVal vParm3 As Variant _
, ByVal vParm4 As Variant _
, ByVal vParm5 As Variant _
, ByVal vReserved As Variant) As Long 'Handles ActiveHomeObj.RecvAction
Console_WriteLine bszRecv
Console_WriteLine vParm1
Console_WriteLine vParm2
Console_WriteLine vParm3
Console_WriteLine vParm4
Console_WriteLine vParm5
Console_WriteLine vReserved
Console_WriteLine

End Function

Hope someone can help! Thanks

ErosOlmi
11-09-2011, 10:32
steinie,

I'm sorry but thinBasic has no possibility to create function callbacks other than the one used for Windows handling in UI module.
The problem is that script functions do not exists as compiled code at runtime but they are only source code to which I cannot derive a code pointer to be passed to a calling function.

In the past I had an idea on how to solve this puzzle but still had no time to try to implement it.
The idea was to have some many dummy functions in compiled code (Core module) to be linked to script functions at runtime. So each script function can have its counterpart in compiled code. In this way thinBasic, when asked, can pass the function pointer of the compiled function to which a script function was connected. Done that, the problem was how to parse and pass into the calling stack the needed function parameters.

Sorry but this is the current situation.
Eros