Original Post
Hi, I have benn learning about callback functions recently (for my GUI), but I still don't understand them. As far as I know the definition of a callback function, is a function which has a pointer to another function as a parameter? If I can get this part, then my question is probably more about how they are used, rather than what they are. I just seem to be missing a whole lot? Thanks.
//The function which will be pointed to
int CalledFunction(int a, void *extradata)//not going to use extra data to
//keep it simple for post
{
//do domething.
return a;
}
//declare pointer to a function.
int (*fpointer)(int a, void *extradata);
//The function which will be doing the calling
void WigCallBack( int Afunctionpointer )//would this take the return value
//of the pointed to function
{
switch(Afunctionpointer)
{
case 1:
//something
return 0;
case 2:
//something else
return 0;
}
}
//Start of main
int _tmain(int argc, _TCHAR* argv[])
{
//assign fpointer which we declared earlier to the function
fpointer = CalledFunction;
int anInt = 5;
//call the callback function?
WigCallBack((fpointer(anInt, &somedata));
return 0;
}