Handle and ID

xiaoxiao2021-03-05  24

In Windows programming, the handle is a terminology that cannot be accurately defined. Just find a master, let him tell you what the handle is, I am afraid he is hard to give you a specific definition. In the Windows program design, the handle is omnipotent, the window has the handle hwnd, threads and processes there are handles, and even someone also called the socket called the handle (I am like this). The handle is Handle in English, which is the meaning of the verb. In short, the handle is an interface to handle the object. For the objects involved in the program, you can operate him through the handle. You should not try to answer the handle, but you should understand him from the perspective of your business, know what he does. Some people say that because of the definition of Handle is void *, he is a pointer. Some people who are familiar with the kernel say this is an index. These statements are not accurate. It should be noted that Microsoft does not precisely define the meaning of the handle, perhaps in a particular operating system, he uses an internal meaning, but in other versions, it will not guarantee this. Any of the intrinsic hypothesis of the handle can lead to catastrophic consequences. The API is an interface, the handle is an interface, what is the difference between the two? The API is a universal function family that handles all objects and the handle is the data structure associated with a specific object. Only by handle, the API knows which object is processed. Some objects have IDs. The handle represents a special object, the ID also represents an object, why do you want two things? First, the handle cannot uniquely represent the object. An object can have multiple handles. For example: Suppose we create a process with CREATEPROCESS, the handle of the first thread of the process returns to the process called CreateProcess. At the same time, in the newly created process, the thread will have a handle. In this way, this thread has two handles. We can also copy a handle with duplicateHandle, which is different from the handle, but they all represent the same object. And each of the objects, within the system range, ID is definitely unique. Second, the function ID that the handle can be implemented cannot be implemented. After all, the ID is just a number, he can't record a lot of information. The handle may record many information (such as authority, no signal, etc.) in its internal structure. In short, if you try to explain what he is, the learning handle will be missed. Understand from the virtual perspective, it is difficult for novice, but this may be the only right way.

转载请注明原文地址:https://www.9cbs.com/read-35862.html

New Post(0)