Hooks (Hook)

Source: Internet
Author: User

Hooks, a platform for Windows message processing, where an application can set up a subroutine to monitor certain messages in a specified window, and the window being monitored can be created by other processes. When the message arrives, it is processed before the target window handles the function. The hook mechanism allows an application to intercept processing of window messages or specific events.

A hook is actually a program segment that processes messages, and it is put into the system by a system call. Whenever a particular message is issued, the hook program captures the message before it reaches the destination window, i.e. the hook function gets control first. At this point the hook function can process (change) the message, or you can continue to pass the message without processing, and you can force the end of the message delivery. This and the front of my blog window sub-class are similar, but the hook can be much more powerful, I was the two days to start to see, so superficial knowledge.

/* Principle of hooks */

I listen to the xinxin Sun teacher C + + Tutorial explanation, think or the hook to speak more image, plus my own some understanding of the hook principle is not very difficult. Windows has always had its own function of handling various messages, and hooks can actually do what the programmer is interested in. In this case, let's say that the Windows message is the vehicle on the road, usually windows itself is sent to check, and then, Hook is to have this ability in Windows to arrange the checkpoint before the inspection, hook according to the needs of programmers can change, For example, I am interested in more than 1 million of the car (may be smuggled), hook can be in the inspection of the special search for more than 1 million of the car, as for other *^__^* car hook release, handed back to Windows own checkpoint. The same hook can "do whatever", can set up a checkpoint, can also be two, three ... in the case of a program, the hook function works: When we create a hook,WINDOWS first creates a data structure in memory that contains information about the hook, and then adds the struct to the existing list of hooks. The new hooks will be added to the old front. When an event occurs, if we install a local hook (explained below, temporarily understood as the program itself), our process of the hook function will be called.

/* Hook list and function */

Each hook has a list of pointers associated with it, called a chain of hooks, which is maintained by the system. The callback function called by the hook, that is, the various processing subroutines of the hook. When the message associated with the specified hook type occurs, the system passes the message to the hook thread. Some hooks can only monitor messages, or modify messages, or stop the progress of messages, to prevent these messages from being passed to the next hook or Destination window. Recently installed hooks are placed at the beginning of the chain, while the first installed hooks are placed at the end, that is, the first to gain control after the addition. A hook thread is an application-defined callback function (callbackfunction) that cannot be defined as a member function of a class and can only be defined as a normal C function. Used to monitor a system or a specific type of event, which can be associated with a particular thread, or it can be an event for all threads in the system.

Hooks (Hook)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.