Yes, a hook function essentially is a callback function. An extensible program will have several "hook" or "extend points" onto which a third-party programmer wishing to extend or "plug-in" capabilites may "hook" more functionality onto it.
For example, if I create an employee management software package, unless told otherwise, it would be advantageous if I created a generic "base" program that encorperates all functionalities that one may want in such a system. One such function might be something like PayEmployee(). It is safe to say that almost every user will need to use this function, however likewise almost every user will have something different or custom that needs to be done as well. Since I don't know who will want to do what in the future, I will just create "hooks" in my program that others can hook onto. So my PayEmployee function might look like this:
Code:
void PayEmployee(Employee anEmployee, int amount)
{
company.getBankAccount().withdraw(amount);
anEmployee.getBankAccount().deposit(amount);
anEmployee.setPaidThisWeek(TRUE);
void *(*hookList)(Employee, int) = getPaymentHookList();
while(*hookList != NULL)
{
(*hookList)(anEmployee, amount);
++hookList;
}
}
void addPaymentHook(void (*paymentFunc)(Employee, int))
{
getPaymentHookList().addHook(paymentFunc);
}
You'll have to excuse me on my function pointer array, I'm not sure if I've gotten that completely right (check here for a proper example of this), but this was just to illustrate a concept.
This function starts off with the generic code to transfer funds, but then calls every function in the hookList with the parameters it received. So now any third-party person looking to extend my funtion only has to add his/her own functions to the hookList (by calling addPaymentHook and supplying their function name).
The other common use of "hook" is registering hooks for Windows API calls, which uses the same theory above but implemented at a much more complex level by the OS.