1. threads and objects
A thread has two user objects, window and hook. When the thread stops running, the system automatically
Undo any windows and uninstall any hooks created or installed by the thread. Other objects only have
The process of the thread is canceled only when it stops running.
2. Create
In C ++, to create a new thread, do not call the createthread function of the operating system.
Must call the C/C ++ Runtime library function _ beginthreadex.
Note that the _ beginthreadex function only exists in the multi-threaded version of the C/C ++ Runtime Library. If
Link to the single-threaded runtime database, you will get an "unconverted external symbol" reported by the linked program"
Error message.
3. "pseudo handle"
Getcurrentprocess (), the getcurrentthread () function returns a "pseudo handle" (current
In the operating system, it is a constant value-1). It is only used to identify the calling thread/process itself and cannot be passed.
To other processes/threads. If you want to transmit the data, you must use the duplicatehandle () function to copy the data.
The output "real handle" is used for transmission.
For example
Duplicatehandle (
Getcurrentprocess (),/* hsourceprocesshandle */
Getcurrentthread (),/* hsourcehandle */
Getcurrentprocess (),/* htargetprocesshandle */
& Hrealhandle,/* lptargethandle */
0,/* dwdesiredaccess */
False,/* binherithandle */
Duplicate_same_access,/* dwoptions */
);
Because duplicatehandle increases the usage count of a specific object, when you use the Copied object handle,
It is important to pass the target handle to closehandle to reduce the use count of the object.