The Old New Thing
Practical development throughout the evolution of Windows.
Latest posts
Using GetLogicalProcessorInformationEx to see the relationship between logical and physical processors
Today's Little Program uses the function to print the mapping of logical processors to physical processors, as well as the mapping of logical processors to packages. (A dual-core processor is a single package with two cores. If those cores are themselves dual-hyperthreaded, then you have four logical processors total.) The helper function takes a typed pointer and adds a byte offset to it. This is just a typing-saver function. Enumerating logical processor information is complicated due to the variable-size structures, so I wrap it inside this helper enumerator class. Construct it with the relationshi...
My, those threads start up really fast nowadays
Here's a little puzzle inspired by an actual bug: Can the assertion at the start of ever fire? Naturally, the answer is Yes, otherwise it wouldn't be a very interesting article. The assertion can fire if the worker thread starts running before the call the returns. In that case, the caller hasn't yet received the handle or ID of the newly-started thread. The new thread calls , which returns since hasn't been initialized yet. The actual bug was something along the lines of this: If the new thread started up so quickly that the original thread doesn't get a chance to receive the new thread ID and p...
When should I use the FIND_FIRST_EX_LARGE_FETCH flag to FindFirstFileEx?
Windows 7 introduces a new flag to the function called . The documentation says that it "uses a larger buffer for directory queries, which can increase performance of the find operation." This is classic MSDN-style normative documentation: It provides "just the facts". Far be it for MSDN to tell you how to write your application; the job of function-level documentation is to document the function. If you want advice, go see a therapist. If the reason why you're calling is to enumerate through the entire directory and look at every entry, then a large buffer is a good thing because it reduces the number o...
It rather involved being on the other side of this airtight hatchway: Planting DLLs into directories on the PATH for applications whose current directory is always System32
Big PATH attack.
The hierarchy of user education, as interpreted by a vice president
One of my colleagues told me a story from his days on the Windows team. He had to give a presentation to his vice president on his feature, and he prepared his presentation and demo obsessively to make sure it went smoothly. At the meeting, there were three presentations on the schedule, all of them with features targeting IT professionals. The first presenter got up and walked through their feature. Upon reaching a particular tricky part of the feature, the vice president asked, "How are customers going to know how to set up those parameters?" The presenter explained, "We'll have a whitepaper explaining how to...
Using a toy cash register as a keyboard doesn't add up
I dreamed that I was composing a blog entry about one of my dreams, but I had to do it on a toy cash register which had been paired to my computer. It turns out that this is difficult for a number of reasons. For one thing, the cash register has only ten letters of the alphabet on it. You have to switch to the alternate keyboard for the rest. Also, there is a backspace key but no other editing keys. Finally, there is a key labeled ≔ which changs the formatting to multi-person mode. Okay, this doesn't actually make typing more difficult, but it's still something unusual.
Opening and manipulating Internet Explorer windows programmatically
Today's Little Program takes the JavaScript application from a few years ago and converts it to C#. This was inspired by a customer who started with the question, "How can I close all Internet Explorer windows programmatically?" This was a strange request. After all, the user may be rather upset that their Amazon shopping spree was suddenly terminated mid-stream. Upon closer questioning, the customer explained that they had a business process which, among other things, opened a bunch of Internet Explorer windows, and when the operation was over, they wanted to close the windows. Okay, so they didn't reall...
The case of the redirected standard handles that won't close even though the child process has exited (and a smidge of Microspeak: reduction)
A customer had a supervisor process whose job is to launch two threads. Each thread in turn launches a child process, let's call them A and B, each with redirected standard handles. They spins up separate threads to read from the child processes' stdout in order to avoid deadlocks. What they've found is that even though child process A has exited, the threads responsible for monitoring the output of child process A will get stuck in the until child process B also exits. The customer further reported that if they added a brief call between creating the thread that launches child proces...
What is the inverse of AdjustWindowRect and AdjustWindowRectEx?
We saw over a decade ago (my goodness I've been doing this way too long) that the and functions do not take menu wrapping into account because they don't take a window handle parameter, so they don't know what menu to test for wrapping. Still, they are useful functions if you aren't worried about menu wrapping because they let you do window size calculations without a window handle (say, before you create your window). But those functions take a proposed client rectangle and return the corresponding non-client rectangle by inflating the rectangle by the appropriate borders, caption, scroll bars, and other n...