PDA

View Full Version : How to retrieve a return value from thinBasic_FunctionSimpleCall?



Michael Hartlef
09-09-2010, 20:58
Hi Eros,



'----------------------------------------------------------------------------
'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



How do I retrieve a return value from the function that was called. The function could look this this:




Function myFunc()
Console_PrintLine("Hello from TB->myfunc")
Function = 1
End Function



I call it inside the module like this:



num2 = thinBasic_FunctionSimpleCall(sBSTR,ret1, ret2)


but get only as a value.

ErosOlmi
09-09-2010, 21:26
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:


'---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))

If you are in FreeBasic, I think it is something similar.
Eros

Michael Hartlef
09-09-2010, 22:46
Thanks Eros. Yes, Freebasic... do you know how to convert an EXT number into a LONG?

ErosOlmi
09-09-2010, 23:09
I think you can use a VARPTR to an "extended" UDT you can find into "thinCore.bi" present in FreeBasic SDK.

type extended
dbl as double
xtn as word
end type

Than just keep the DOUBLE part

Maybe Charles can help on this :read:

Michael Hartlef
10-09-2010, 12:54
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.

Charles Pegge
10-09-2010, 17:55
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


asm
mov eax,[p]
fldt [eax]
fistp dword ptr [i]
end asm


and doing the reverse:

FreeBasic


asm
fild dword ptr [i]
mov eax,[p]
fstpt [eax]
end asm




Charles

Michael Hartlef
10-09-2010, 22:44
Thanks Charles, I'll try that.