Function pointers and arguments
Posted: Wed Dec 28, 2011 10:20 am
Probably a simple question, but I do not know how to solve it:
I have this piece of code:
This works fine, but I want to eliminate globals in my code: I would like to pass the reference to the function as a procedure argument.
Something like this: genericFunction( @test_a(), "ok", 1)
genericFunction() will indirectly call test_a() once implemented...
It should not be to hard to do this (Windows API uses callback functions all the time), but I simply can't figure out how.
I have this piece of code:
Code: Select all
Prototype myProto(arg1.s, arg2)
Global myFunctionPtr.myProto
Procedure test_a(arg1.s, arg2)
Debug arg1 + " = " + Str(arg2)
EndProcedure
Procedure test_b(arg1.s, arg2)
Debug arg1 + " ==> " + Str(arg2)
EndProcedure
myFunctionPtr = @test_a()
myFunctionPtr("ok",1)
Something like this: genericFunction( @test_a(), "ok", 1)
genericFunction() will indirectly call test_a() once implemented...
It should not be to hard to do this (Windows API uses callback functions all the time), but I simply can't figure out how.