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
    Leverkusen, Germany
    Age
    51
    Posts
    3,278
    Blog Entries
    2
    Rep Power
    339

    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.
    Running Windows 7 Home, 64 bit, 8 GB ram, Athlon II X2 255, ATI Radeon HD 4200.

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,170
    Blog Entries
    2
    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/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  3. #3
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Leverkusen, Germany
    Age
    51
    Posts
    3,278
    Blog Entries
    2
    Rep Power
    339

    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?
    Running Windows 7 Home, 64 bit, 8 GB ram, Athlon II X2 255, ATI Radeon HD 4200.

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,170
    Blog Entries
    2
    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/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  5. #5
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Leverkusen, Germany
    Age
    51
    Posts
    3,278
    Blog Entries
    2
    Rep Power
    339

    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.
    Running Windows 7 Home, 64 bit, 8 GB ram, Athlon II X2 255, ATI Radeon HD 4200.

  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
    Leverkusen, Germany
    Age
    51
    Posts
    3,278
    Blog Entries
    2
    Rep Power
    339

    Re: How to retrieve a return value from thinBasic_FunctionSimpleCall?

    Thanks Charles, I'll try that.
    Running Windows 7 Home, 64 bit, 8 GB ram, Athlon II X2 255, ATI Radeon HD 4200.

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

Posting Permissions

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