How to retrieve a return value from thinBasic_FunctionSimpleCall?
Hi Eros,
[code=thinbasic]
'----------------------------------------------------------------------------
'thinBasic_FunctionSimpleCall
'----------------------------------------------------------------------------
' Call a script function and optionally returns it value (numeric or string)
'----------------------------------------------------------------------------
Declare Function thinBasic_FunctionSimpleCall _
Lib "thinCore.DLL" _
Alias "thinBasic_FunctionSimpleCall" _
( _
ByVal FunctionName As String, _ '---Name of the function
Optional _
ByVal ptrEXT As Ext Ptr, _ '---Used to get back from the called function a numeric value
ByVal ptrSTR As String Ptr _ '---Used to get back from the called function a string value
) As Long
[/code]
How do I retrieve a return value from the function that was called. The function could look this this:
[code=thinbasic]
Function myFunc()
Console_PrintLine("Hello from TB->myfunc")
Function = 1
End Function
[/code]
I call it inside the module like this:
[code=freebasic]
num2 = thinBasic_FunctionSimpleCall(sBSTR,ret1, ret2)
[/code]
but get only as a value.
Re: How to retrieve a return value from thinBasic_FunctionSimpleCall?
If you want get back a result you need to pass a pointer to an Extended numeric variable or a pointer to a dynamic string.
In PowerBasic you would need something like:
[code=vb]'---To get back a numeric:
DIM MyExt AS EXT
thinBasic_FunctionSimpleCall(sBSTR, VARPTR(MyExt), %NULL)
'---To get back a string:
DIM MyString AS STRING
thinBasic_FunctionSimpleCall(sBSTR, %NULL, VARPTR(MyString))[/code]
If you are in FreeBasic, I think it is something similar.
Eros
Re: How to retrieve a return value from thinBasic_FunctionSimpleCall?
Thanks Eros. Yes, Freebasic... do you know how to convert an EXT number into a LONG?
Re: How to retrieve a return value from thinBasic_FunctionSimpleCall?
I think you can use a VARPTR to an "extended" UDT you can find into "thinCore.bi" present in FreeBasic SDK.
[code=thinbasic] type extended
dbl as double
xtn as word
end type[/code]
Than just keep the DOUBLE part
Maybe Charles can help on this :read:
Re: How to retrieve a return value from thinBasic_FunctionSimpleCall?
Thanks I will try that. Type conversion in FreeBasic is a biatch, big time. It reminds me a little like C/C++. I fight more with the compiler than with the design of the code.
Re: How to retrieve a return value from thinBasic_FunctionSimpleCall?
Hi Mike,
In Freebasic, a little Asm cuts out a lot of compiler nonsense :)
If you have a pointer p to an extended number and you want to convert the Extended number into a Long number i:
FreeBasic
[code=thinbasic]
asm
mov eax,[p]
fldt [eax]
fistp dword ptr [i]
end asm
[/code]
and doing the reverse:
FreeBasic
[code=thinbasic]
asm
fild dword ptr [i]
mov eax,[p]
fstpt [eax]
end asm
[/code]
Charles
Re: How to retrieve a return value from thinBasic_FunctionSimpleCall?
Thanks Charles, I'll try that.