Monday, May 24, 2010

What is a callback function ? Explain in C , C++ and WIN API environment.?

It was asked in assessment test but I couldn't answer correctly. I'm not familiar with WIN API environment too. Can u plz help me on these ?

What is a callback function ? Explain in C , C++ and WIN API environment.?
Callback function— callback procedure with return value.


Callback procedure— procedure to be called from external execution flow than the execution flow (main) of unit that contains procedure. The description refers to executed unit, ex. binary executable file loaded into memory and executed as *self* operating system task. Such procedure operates out of direct-inherited environment of the main execution flow.


In C simple example of callback function is one passed as argument with "sort()". This function is next used for comparing and is called before "sort()" returns to main execution flow from C library.


[C++— omited answer.]


In Windows API callback functions are used for events (messages) [explained in earlier answer] and reporting states of asynchronous operation.


Usually pointer to callback function is passed as argument to function that initiates some operation.
Reply:A callback function is a function that executes when an event occurrs in the GUI. For example, you press the back button on a browser, and the callback function reloads the previous page. They can respond to clicks, double clicks, key down, key up, Any event.


No comments:

Post a Comment