C/C++ Callback function
Callback function are those functions which are called by framework or operating system or other external modules or any component which is not a part of the program. Programmer never call these functions directly. These are called asynchronously and parallely to the normal program flow. C signal handlers are good example of callback function. These are called by task scheduler of the operating system.
COM/DCOM Callback function
COM client calls interface functions. These call goes to server and executes the function code. A return from the function move the execution context back to client code. This flow is good when we have couple of non-bloking functions or functions having short span of CPU time. There can be some function which deals with some longer and time taking tasks like downloading a file from internet, wait for message bytes in socket, copy a file etc. This type of tasks can not be fitted in normal interface design. Normal interface call will block the client until the actual task is ended.
COM/DCOM framework should support calling a client function from server side. Here the flow of the call is from server to client and this is the reverse direction compared to normal interface. These type of functions are known as events or notifications or callbacks. COM server often provides event interface with a couple of events. Client has to implement these events. COM server implements a non-blocking function to initiate a long task. This returns immediately creating a thread. This thread executes the long task and calls client events. Client gets notification of the status of the task through different evets.
COM/DCOM events example
C++ COM events are a bit complex. To understand callback mechanism here we have taken a VB example to demostrate a COM callback or event. We have taken WebBrowser COM object and one Text box with a button. Button click initiate Navigate() method to a URL which is a big winzip executable. WebBrowser server calls DownloadBegin() and then ProgressChange() events as the file downloads. We have implemented these events. We update text in the textbox as we receive events from COM server.
About our authors: Team EQA
You have viewed 1 page out of 67. Your COM/DCOM learning is 0.00% complete. Login to check your learning progress.
Learn on Youtube