During this time, I read "Windows core programming", which is really nice. It is really a classic book.
After reading this book, I finally figured out what I didn't quite understand. I felt that I had a deep understanding of windows. Here I want to record the errors I have been writing Code .
1. Critical Section
I have never figured out the true meaning of the critical section. In the past, I used to write this statement to protect resources in the process:
Void threadfunction (pvoid pvparam)
{
// Create a critical section object
Resources to be protected
// Release the critical section object
}
The original critical section object must use global variables (that is, all threads are visible), and all threads here are gentlemen: that is, all threads use the critial section object to access resources, if a thread does not use this critial section object to access resources, the consequences will be very serious ,:)
Looking at the original code, it seems that every time a resource is accessed, a critical section object is created, which obviously cannot protect the resource.
2. Related window APIs
I always thought that setfocus (), getactivewindow (), setactivewindow () and other APIs are global. Now I understand that they are only for the current thread. If the window created by the current thread is not activated, getactivewindow () returns NULL. Now we finally understand the difference between getforegroundwindow () and getactivewindow (). Originally, we wrote an event in a button to get the handle returned by the two functions, and the handle returned in the result is equal, so I mistakenly understood these two APIs. Hoho ~~~, Learning Technology cannot be sloppy.
Now I understand how to use the attachtreadinput () API ,:)
3. Others
I have never paid attention to the "Auxiliary Function" of waitforsingleobject, and I always follow the example on msdn, but I don't understand why. Now we have figured out that waitforsingleobject will set the corresponding object to the "not notified" status.
Bytes -----------------------------------------------------------------------------------------------------------------------------
Among these many technical books, these two books are the most worth collecting:
Programming essence-microsft programming quality error-free CProgramResolution
Windows core programming
When I have the money, I must buy the e-file version of Windows core programming and add it to my favorites. If I have time, it is also a pleasure. ^_^