What is the handle? This problem has plagued me since I learned VC. Recently I found a good answer from Microsoft's book windows core programming, the answers previously found in Baidu, googo, and other search engines were not satisfactory. Everyone interpreted the handle as a pointer and identified an object. In fact, this understanding is not completely correct.
Now, the structure of the handle table is as follows:
We know that when a process is initialized, the system will allocate a handle table to it. This handle table is only used by kernel objects and is not applicable to user objects, any function used to create a kernel object will return a process-related handle, which can be used by all threads running in the same process, the system uses indexes to identify the location where the kernel object information is stored in the Process Handle table. To obtain the actual index value, you need a handle. In most operating systems, the relationship between the handle and the index is to shift the handle value to the right by two places.
Therefore, we usually say that the handle identifies an object. There is no error in this sentence. If it is a pointer, there will be problems, because we use the handle of an object to obtain the index of the object in the handle table, and finally get the address of the object in the memory, that is, the pointer.