
CALLBACK, CALLBACK, CALLBACK?
Quote:
> I really want to know what in the world
> the word CALLBACK means for in the context
> of a function declaration?
The specifics of how a CALLBACK is declared can be found
in your particular compiler's help files and header files.
The reason for a callback is, roughly, this. Suppose you
have some item in your program (I'm deliberately avoiding
the term object) such as a window. This window is, in some
ways, looked after by your operating system. And in some
other ways, it is looked after by your program. When the
OS needs to tell your program about something, it does this
by calling your program. It does this through a CALLBACK
function. The idea is, you give the OS a pointer to a function,
and that function has a particular signature. Then the OS
calls that function when it thinks your program should take
action on something.
You can use the idea of a callback in many other contexts.
For example, if you had a program that calculated the integral
of a function, you might give it a callback to a function that
generated values of the function being integrated. Then
the integration program could get the specific values it
needed instead of you having to generate all possible needed
values in advance.
In C++, the notion of a callback is somewhat changed. You
probably don't use a pointer to a function, but rather a pointer
to an instance of a class. Then through virtual functions and
polymorphism, the specific behaviour your window needs can
be provided. You would have a derived class for your particular
kind of window, and it would be derived from some class that
provided an interface the OS knew. The OS calls, say, the
function handleMessage(/* yada yada, message params */)
through the pointer, and then polymorphism sorts it out so it
goes to the version of handleMessage() in your particular
kind of window.
--
Dan Evens
Standard disclaimers etc. No spam please.
Just because nobody complains does not
mean that all parachutes are perfect.