are callbacks and function pointers the same thing

Are callbacks in win32 just like function pointers in c++
Last edited on
A callback is a function that gets called when a certain condition or event occurs. A function pointer is a pointer to a function (really? wow...)

Function pointers are often used for storing a function for a callback event.
A callback is a design pattern. A function pointer is usually the concrete implementation of a callback.

The callback design pattern is used when there needs to be a mutual relationship between two entities, but for other reasons there can't be.

For example, someone writes an open source library that implements networking. You write code to use that library. Clearly, you are dependent on the library, but not vice versa. (And by "dependent", I mean you include the library's header files, but the library cannot include yours).

But somewhere in the networking library it receives data from a network connection and wants to give the data to your code. As the writer of the library, I can't just call your function by name -- I can't include your headers and I don't know what you named the function anyway. Somehow, I need to "call back" into your code. How? I make my API such that you have to pass me a "callback function", or in other words, a pointer to a function with a signature that I mandate, so that I can call that function when data is received.
crips I wish I could explain stuff as well as you. that was awesome thanks.
Topic archived. No new replies allowed.