|
-
May 4th, 2001, 04:25 PM
#1
Call back functions
How would I go about creating a callback function. For example, I have function a that takes in a function pointer, and stores it as static, and when i call it again, it would call the function it had stored. How would this be done?
Z.
-
May 4th, 2001, 04:28 PM
#2
Frenzied Member
Don't really see the problem.... which bit are you having trouble with?
Harry.
"From one thing, know ten thousand things."
-
May 4th, 2001, 04:41 PM
#3
Monday Morning Lunatic
Code:
typedef long (*PFNMYFUNCTION)(int, int);
PFNMYFUNCTION pfnTheFunction;
long afunction(int x, int y) {
return x + y;
}
long func() {
pfnTheFunction = afunction;
return (pfnTheFunction)(5, 200);
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 4th, 2001, 07:29 PM
#4
-
May 8th, 2001, 11:57 AM
#5
After a romp thorugh ASM land, i figured out an easier way to do this:
Code:
int somefunction()
{
return 10;
}
int callafunc(void* addr)
{
int retval;
__asm call [addr];
__asm mov retval, eax;
return retval;
}
int main()
{
return callafunc(somefunction);
}
Z.
-
May 8th, 2001, 12:07 PM
#6
Monday Morning Lunatic
Be very careful with calling conventions and passing parameters when doing that
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 8th, 2001, 12:15 PM
#7
Quite, but its much more generic. What i was needing it for was to create a simple menu class, and, instead of having to have a million different classes for each menu item type, just be able to create a single class that would call the function address you passed it. No parameters (could be easily set with the class, if i needed them), and no return value (which would be simple to implement anyway =).
Z.
-
May 8th, 2001, 12:21 PM
#8
Monday Morning Lunatic
Class member functions have a hidden parameter this 
Why can't you use templates?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|