Announcement

Collapse
No announcement yet.

Function as a parameter to a Function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Function as a parameter to a Function

    Is there a mechanism in PB DLL to pass a function's address
    as a parameter to another function. The following code
    shows the idea of what I'd like to do. It can be accomplished
    other ways, but just thought I'd ask for future reference.
    -------------------------------------------------------------
    Code:
    #COMPILE EXE
    #REGISTER NONE
    $INCLUDE "WIN32API.INC"
    
    FUNCTION F1() AS LONG
    MSGBOX "F1"
    END FUNCTION
    
    FUNCTION F2() AS LONG
    MSGBOX "F2"
    END FUNCTION
    
    FUNCTION FF(BYVAL PName AS FUNCTION PTR)
    CALL @PName()
    END FUNCTION
    
    FUNCTION PBMAIN() AS LONG
    CALL FF(F1)
    CALL FF(F2)
    END FUNCTION

  • #2
    Pointers (any pointer) are simply DWORD's. So simply pass a DWORD by value and call it using CALL DWORD.

    --Dave


    ------------------
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Home of the BASIC Gurus
    www.basicguru.com

    Comment


    • #3
      Joe --
      It's enough easy (see CALL DWORD in HLP):
      Code:
         #Compile Exe
         #Register None
         Declare Function MyFunc () As Double
         Function F1() As Double: Function = 5.23#: End Function
         Function F2() As Double: Function = 7.18#: End Function
         Function FF(PName As Dword) As Double
            Call Dword PName Using MyFunc() To lResult#: Function = lResult#
         End Function
         Function PbMain() As Long
            MsgBox Str$(FF(CodePtr(F1)) + FF (CodePtr(F2)))
         End Function
      ------------------

      Comment


      • #4
        Thanks guys. The manual needs work. It was not possible to get
        to the information via use of its description of function
        parameters, or the index. The old PB DOS manual was great,
        particularly "See Also" for related subjects. In this case if
        VARPTR had a "See Also" reference to CODEPTR I'm sure I'f have
        figured it out without bothering the forum with such a simple
        question.

        Still I understand that it is difficult to make a manual for
        all possible users with differing skill levels. PB DLL is
        a great product!

        ------------------

        Comment

        Working...
        X