The Old New Thing
Practical development throughout the evolution of Windows.
Latest posts
Forcing a file handle closed when it has been opened remotely
Today's Little Program closes a file handle that was opened remotely. It builds on previous discussion on how to use the functions. Forcing a network file handle closed does not actually close the handle. This makes it very different from the various "force handle closed" utilities out there. Rather, forcing a network file handle closed is accomplished by simulating a network failure, so that when the remote machine tries to use the handle again, it's told, "Wha? I'm sorry, we must have a bad connection, because I'm not sure what you're talking about." Since programs which access network resources must dea...
How does InterlockedIncrement work internally?
The Interlocked family of functions perform atomic operations on memory. How do they do it? It depends on the underlying CPU architecture. For some CPUs, it's easy: The x86, for example, has direct support for many interlocked operations by means of the prefix (with the bonus feature that is implied for the opcode.) The ia64 and x64 also have direct support for atomic load-modify-store operations. Most other architectures break the operation into two parts, known as Load-link/store-conditional. The first part (load-link) reads a value from memory and instructions the processor to monitor the memory add...
It rather involved being on the other side of this airtight hatchway: Creating problematic files in a directory that requires administrative access
You have to get there first.
Why does Internet Explorer put tab stops at 8-character intervals instead of 4, like all right-thinking people?
When you embed a TAB character (U+0009) in a <PRE> block (or more precisely, an element whose CSS property is computed to be or ), Internet Explorer will move the current position to the next multiple of eight characters. Many people prefer four. (Some insist that only four is the correct value and anybody who disagrees with them is simply wrong.) Why eight? Because that's what the standard says. All tabs (U+0009) are rendered as a horizontal shift that lines up the start edge of the next glyph with the next tab stop. Tab stops occur at points that are multiples of 8 times the width of a space (U+0020...
Early versions of Aero Peek: Aladdin, Bat Signal, and Squeegee
The feature now known as Aero Peek wasn't born that way. It went through several iterations before becoming what eventually shipped in Windows 7. At the MIX09 conference, Stephan Hoefnagels showed some of the precursors to Aero Peek. Here are the highlights, and the corresponding time codes if you want to jump straight to the demos. Thumbnails in the taskbar (time code 30:20) How it worked: Instead of labeled icons, the taskbar showed miniatures of the windows themselves. How it got its name: Um, it was just named after what it was. Why it failed: When shrunk to taskbar s...
Mom and dad's event-filled first day of school
I dreamed that my wife and I had dropped our daughter off at her new school for the first time, and I made a wrong turn and ended up going the wrong way. We got off at an exit for highway I-5, and the on-ramp turned into a two-lane highway hundreds of feet in the sky. To keep people from going too fast, the road rolled back and forth: First it tilted to the right, then to the left, and so on. (Imagine your hand making the "so-so" gesture.) You just had to drive carefully. The road dead-ended at a building, so we parked the car and got out. It was a tiny gift shop with puppets and marionettes. The attendant came...
Programmatically editing the metadata of an audio file
Today's Little Program edits the metadata of an audio file, ostensibly to correct a spelling error, but really just to show how it's done. Today's smart pointer class library is... (rolls dice)... CComPtr! We open with two helper functions which encapsulate the patterns Get property from property store Call Convert into desired final type Destroy the Set property in property store Create a Call Destroy the Both functions use a lambda to do the type-specific work. Here are some functions that will use the helpers: The function returns an array of po...
How to rescue a broken stack trace on x64: Recovering the stack pointer
No threading, just return addresses.
Why are my posted messages getting lost when the user drags my window around?
This question was inspired by an actual customer question, but I changed a lot of it around to make for a more interesting story. (Trust me, the original story was even more boring.) A customer's background thread posted a message to the main UI thread to signal something (details not important). They found that the posted message was never received if the user was in the process of dragging the main window around at the time the message was posted. Why would dragging a window cause posted messages to be lost? "We used to post a thread message, but then we saw that thread messages are eaten by modal loops, so...