Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Event handling using callback functions (http://www.go4expert.com/forums/event-handling-using-callback-functions-t5850/)

priyapai 14Aug2007 15:26

Event handling using callback functions
 
Hi All,

I am not vry clear with the usage of callback function for Event handling.
What i understand is that, the Application registers a callback function. This callback func has the code to handle the diffent events that are expected. When one of these events hapen, the Callbak func gets called. But what i want to understand is that, how does the callback function gets to know that it has to get executed? If the same event is handled by two diff functons, then what should happen..

Plz send me links or pointers wher i can study mor about the same topic.

Thanks in advance.

shabbir 14Aug2007 15:51

Re: Event handling using callback functions
 
When the function is called means the function executes and the callee who provide the function callback knows when to call the function call back.

priyapai 14Aug2007 16:11

Re: Event handling using callback functions
 
Thankx for the quick responce Shabbir.

But m still not clear.

int (*function_cb) (arg1, arg2)

return_val = caller_function (arg11,arg22,(int)function_cb);


In the above case, when will function_cb get called?

shabbir 14Aug2007 17:12

Re: Event handling using callback functions
 
function_cb is a function pointer and it will not get call but depending on the situation the callee will call the function (pointed by the function pointer)

I will give you an example.
1. Say you have a function which updates the progress bar for some copy of files operation.
2. When any chunk of file is copied successfully you call the function.
3. Function does it job to update the progress bar.

priyapai 14Aug2007 17:54

Re: Event handling using callback functions
 
ok..

Could u give me an example in code form, which handles some event by calling a callback function.

shabbir 14Aug2007 18:05

Re: Event handling using callback functions
 
Refer to the API CopyFileEx where you can specify your call back function in the third parameter and you will see how the call back function of yours is called

kaustubh 14Aug2007 21:19

Re: Event handling using callback functions
 
hello priya,
do read this links
http://www.codeguru.com/Cpp/Cpp/cpp_...le.php/c10557/

http://www.newty.de/fpt/callback.html

with regards
kaustubh


All times are GMT +5.5. The time now is 14:35.