Results 1 to 7 of 7

Thread: How to retrieve a return value from thinBasic_FunctionSimpleCall?

  1. #1
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    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.

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    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?

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    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.

  6. #6

    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

  7. #7
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    Re: How to retrieve a return value from thinBasic_FunctionSimpleCall?

    Thanks Charles, I'll try that.

Similar Threads

  1. Script to retrieve each process CPU usage
    By Petr Schreiber in forum Real world situations and solutions using thinBasic
    Replies: 5
    Last Post: 16-04-2011, 11:52
  2. How to conect to an online MYSQL database and retrieve fields
    By Michael Hartlef in forum thinBasic General
    Replies: 10
    Last Post: 16-06-2009, 06:07

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •