Windows core programming Chapter 1 notes

Source: Internet
Author: User
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.

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.