Page 1 of 1
Function Pointers
Posted: Tue Dec 23, 2003 3:26 am
by SurreaL
I've noticed you can get the address of a function..I'm just wondering if you can use that address later to call the function?
I'm brand new to PB (used to BB!) and so I'm trying to get a handle on all this extra functionality

(no pun intended!)
Cheers,
-SurreaL
not sure if this helps..
Posted: Tue Dec 23, 2003 4:08 am
by NoahPhense
Posted: Tue Dec 23, 2003 4:45 am
by SurreaL
Thanks for your reply!
However I have already understood the basics of how to set up pointers and use them..
I'm just wondering if there's any way to call a function from a pointed initialized with the address of said function..
IE something like this (doesn't compile..)
Code: Select all
Declare Test()
MyFunc.l = @Test()
Call (*MyFunc ())
MessageRequester("Information","Yup.",#PB_MessageRequester_Ok)
Procedure Test()
a.l
a = a + 1
EndProcedure
Posted: Tue Dec 23, 2003 5:52 am
by Karbon
I don't *think* there is a way to do that.... Yet.
[edit]
errr I mean, of course there is! See below!
Posted: Tue Dec 23, 2003 6:01 am
by p2hicy
Code: Select all
Procedure thefunc(title.s, msg.s)
MessageRequester(title, msg, #NULL)
EndProcedure
thefuncpointer = @thefunc()
CallFunctionFast(thefuncpointer, "hello i'm a title", "hello i'm the message")
Posted: Tue Dec 23, 2003 6:54 am
by SurreaL
Holy Crap.
That rules
I remember looking over CallFunctionFast and wondering if that would be possible.. I was concerned that it only worked with DLL's functions though.. This is wicked

Looks like I can fake some OO w/ PB fairly easily now..
thanks a bunch!
Posted: Tue Dec 23, 2003 7:04 am
by Karbon
If you can, post some examples when you're finished.. There are lots of people that seem to want to use OOP in PB!
Posted: Tue Dec 23, 2003 7:29 am
by LarsG
Hi Surreal.. welcome!
Are we going to see PurePlay soon then eh?!? 8O
-Lars
Posted: Tue Dec 23, 2003 1:39 pm
by El_Choni
Surreal, have a look at Interfaces in the manual, you can "fake" OOP the same way other languages do.
Posted: Tue Dec 23, 2003 7:25 pm
by SurreaL
El_Choni,
I've taken a look at the interfaces section.. It looks like it would be mostly useful for interfacing w/ objects created in another language. Could this be used to create a PB DLL and access objects within it..? I was referencing to simulating OO by having function pointers within a structure, sort of making that a "class" by doing so
LarsG,
Ah hah! Someone recognizes me

In fact.. Porting over my network library is something I'm looking at.. I've been trying to research the better way to do networking however, and have sort of hit a wall w/ IOCP. (I've read elsewhere on these forums that it's not possible within PB..? I wonder why..) Either way.. I do *very* much want to do it, so we'll see

Posted: Tue Dec 23, 2003 11:01 pm
by Hi-Toro
Porting over my network library is something I'm looking at..
AAAAA!!!! Traitor!!!!
... from someone else who recognises you
(I didn't know you could use CallFunctionFast in that way, though -- nice!)
This link to a previous post might be helpful.
Posted: Sat Dec 27, 2003 8:38 am
by ppjm99