Reputation:
What is callback function [CALLBACK EXPORT] ,how it works , is it infinite loop or recursive. I have a piece of code in vc++ 6.0 can any body explain how it works.
timer_result=SetTimer(NULL,1,(t*1000),Timerflow); //say t=2,or t=10,
===
void CALLBACK EXPORT Timerflow(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime)
{
----
----
}
Upvotes: 0
Views: 2473
Reputation: 51711
Callbacks like this can be used to provide event handling in languages that do not have built in events (like .Net languages).
You call the settimer function, passing a pointer to one of your functions, which will be called when the requisit time has passed.
the Callback macro is there to tell pre 32bit compilers how to pass the function arguements between the API and your function, see this snippit from this paper here
DLL callbacks and why WINAPI is the same as CALLBACK
It is possible to allow the DLL to make calls back into the client code, which is useful if you are writing a DLL to implement a callback function, or designing an event driven interface. The concept is the client calls a function in a DLL, passes the DLL a pointer to a function that resides in the client, and the DLL function will make calls back into the client using the pointer.
Upvotes: 0
Reputation:
A callback function is one which is called from outside your own code, normally by the operating system. In the example you give, the SetTimer function asks the OS to call your callback after a fixed time has elapsed.
Upvotes: 1