We often make some applications (such as timer event callback processing, recording actions with callback functions, etc.) when designing the callback function, so that its inner mechanism is, how is it defined? ? Is it different from other functions (such as hook functions)? Here is a simple introduction to your own experience.
Using the callback function is actually when a function is called (usually an API function), the address of one of its functions (this function is a callback function) is passed to that function. And that function is required to call the callback function using the delivered address, then you can use this opportunity to process messages in the callback function or complete a certain action. As for how to define the callback function, it is related to the specific API function, generally in the help, the parameters and return values of the callback function. C generally requires Callback before the callback function, which is mainly to explain the call mode of the function.
As for the hook function, just a special case of the callback function. It is used to refer to the callback function used with the setWindowsHooKex function as the hook function. Some people use the function that uses the VirtualQueryEx installed as hook functions, but this called is not popular.
It can also be more likely to understand that the callback function is like an interrupt processing function, and the system is automatically called when it meets the conditions you set. To this end, you need to do three things:
Declaration;
2. Definition;
3. Set the trigger condition, which is transformed into the address as a parameter in your function to make the system call.
Note and definition should pay attention to: The callback function is called by the system, so it can be considered to be a Windows system, do not treat it as a member of your class.
This is my coarse knowledge, I hope to correct.