The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Sep 6, 2013
Post comments count 0
Post likes count 2

How to rescue a broken stack trace on x64: Recovering the stack pointer

Raymond Chen

No threading, just return addresses.

Sep 5, 2013
Post comments count 0
Post likes count 1

Why are my posted messages getting lost when the user drags my window around?

Raymond Chen

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...

Sep 4, 2013
Post comments count 0
Post likes count 1

How permanent is the "Remove from this list" action on the Start menu?

Raymond Chen

From Windows XP to Windows 7, the Start menu showed the programs it thinks you've run most frequently, by employing a conceptually simple but complicated-in-practice algorithm. You can right-click an item on the menu and select Remove from this list. What exactly does this option do? Does it reset the points back to zero, or does it ban the program from the Start menu for all eternity, or something in between? It resets the points back to zero and marks the program as has never been run by the user. This causes it to vanish from the frequently-used list, but if you start running it, it will start ea...

Sep 3, 2013
Post comments count 0
Post likes count 1

If your product is client-managed, how do you sell the server?

Raymond Chen

A friend of mine told me about a project he worked on two decades (and three employers) ago. Let's call it Project Nosebleed. Their project used a client-managed database: You have a central file server that houses the database files, which were in a proprietary file format that only the clients understood. All the client applications open the database files, coördinating¹ access among themselves by using file and record locking primitives. All you needed the server for was a place to house the files. It could have been a NAS server for all anybody cared. (Well, except that the concept of NAS hadn't tak...

Sep 2, 2013
Post comments count 0
Post likes count 1

If you had to deal with preschoolers all day, you'd need a nap too

Raymond Chen

Today, I'm turning it around: This is a dream that one of my friends had about me! She dreamed that she took her camera to school to take some pictures, possibly for the yearbook. She was somewhat surprised to discover that I was the new preschool teacher. When she popped in to my classroom to get a couple of pictures of me, she wasn't able to take any: Apparently, my new position was so exhausting that I'd had to take a nap on the king-size classroom bed...

Sep 2, 2013
Post comments count 0
Post likes count 1

What is the official name of the most popular work visa in the United States?

Raymond Chen

The most popular work visa in the United States is the H1-B visa. But have you looked at its official name? H-1B Specialty Occupations, DOD Cooperative Research and Development Project Workers, and Fashion Models (Today is Labor Day, a holiday in the United States which celebrates the end of summer. Not really, but that's what it has turned into.)

Aug 30, 2013
Post comments count 0
Post likes count 1

Can an x64 function repurpose parameter home space as general scratch space?

Raymond Chen

We saw some time ago that the x64 calling convention in Windows reserves space for the register parameters on the stack, in case the called function wants to spill them. But can the called function use the memory for other purposes, too? You sort of already know the answer to this question. Consider this function: How would a naïve compiler generate code for this function? Observe that after spilling the register parameters into their home locations onto the stack, the function modified the local variable, which updated the value in the home location. Since a function can arbitrarily modify a par...

Aug 29, 2013
Post comments count 0
Post likes count 1

How can I write to a file only as long as nobody's looking?

Raymond Chen

A customer wanted to know how to detect that the user has opened Notepad to view a particular file. They had come up with method based on polling and sniffing the Notepad title bar, but they found that it consumed a lot of CPU. (They hadn't noticed yet that it doesn't localize, and that it can trigger false positives since Notepad shows only the file name and not the full path in the title bar.) Okay, let's step back and make sure we understand the problem, because this sounds like the sort of thing where the customer is looking for an answer rather than a solution. After all, why Notepad? What about some other ...

Aug 28, 2013
Post comments count 0
Post likes count 1

The format of data and custom resources

Raymond Chen

Continuing the highly-sporadic series of Win32 resource formats, today we'll look at the format of resources, which are declared in resource files as . Also the format of custom resources, which are declared in resource files by just giving the custom resource name or ordinal as the second word on the declaration. The format is very simple: It's just raw binary data. If you ask for a 16-bit integer followed by an ANSI string, then you get a 16-bit integer followed by an ANSI string. If you ask for the data to be inserted from a file, then the contents of the file become the resource data. No processing is done...