The Old New Thing
Practical development throughout the evolution of Windows.
Latest posts

Redistributing computers among offices for heating purposes

Some time ago, I joked about the people who rearrange computers in their house during the winter in order to use them as space heaters. Turns out this happens a lot at Microsoft. One of my friends said that one of his coworkers used a small heater in her office to keep warm. On the other hand, his office always ran warm because of all the computers in it. They hit upon a simple solution to both problems: "Now she's using a 12 core/24 thread space heater that's a lot quieter than her old one." At one point in time, I had a large number of computers in my office, including an Itanium prototype. (You knew it w...

Derive the age of the planet Jupiter from the properties of liquid hydrogen and the planet’s surface temperature

I dreamed that my homework assignment was to derive the age of the planet Jupiter. The professor hinted that physical properties of liquid hydrogen and the current Jupiter surface temperature would be useful. My classmate Ted, on the other hand, had to extend a C++ base class to record a GUID name. The two of us were taking a class together where we watched a reality show about two ditzy celebrities, and the professor said, "The next episode is so stupid, I don't even want anybody to watch it. But they do learn about Sirens of Greek mythology, so can you guys write up a quick one-pager to get everybody up t...

How can I see what files and shares are being accessed remotely, and the general usage pattern for the NetXxx functions

Today's Little Program is a command line version of the Shared Folders MMC snap-in. Why? Because it illustrates the usage pattern for the NetXxx family of functions. (It's also a clone of the networking portion of the openfiles tool.) The NetXxx family of functions generally work like this: You pass in some parameters that describe what you want. Server name, that sort of thing. You pass a "level" parameter that describes what information you want. The function allocates memory to hold the results you requested, and it returns a pointer to that memory through a bufptr para...

Microsoft-internal Chuck Norris facts

A colleague of mine forwarded me some status mail from his team's internal bug push. (This is a push to fix bugs, not a push to introduce new bugs.) Apparently, one of the ways the developers lifted the tension was to discover some new Chuck Norris Facts, two of which were shared in the status mail: Chuck facts today: Happy birthday, Chuck! (Remember, don't let the facts get in the way of a good story.) Bonus: Google-internal Chuck Norris facts.

Why do Explorer and the command prompt interpret file times differently?

A customer observed that if they use Explorer to view the timestamp on a file, it is not always in agreement with the value shown if they run a plain in a command prompt. They are sometimes off by an hour. Why is that? Whenever you hear the phrase "off by an hour" you should immediately think "Daylight Saving Time". The formatting of file timestamps shown by Explorer has changed over time. The most recent algorithm (at the time of this writing) is to use the time zone that was in effect at your current location at the time the timestamp was created. For example, a file created at noon in June 22 will show ...

What are the conventions for managing standard handles?

Consider this function: void ChangeConsoleColor(WORD wColor) { HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); if (h != INVALID_HANDLE_VALUE) { SetConsoleTextAttribute(h, wColor); CloseHandle(h); } } "When I call this function, it works the first time, but when I call it a second time, GetStdHandle returns a handle numerically identical to the one returned by the first call, but the handle is now invalid, presumably because I closed it. I closed it because I was taught to clean up after myself. Is this a case where I shouldn't?" Yes, you should clean up after yourself, but you should also have...

What are the dire consequences of not selecting objects out of my DC?

The convention when working with device contexts is to restore them to the way you found them. If a drawing function selects a bitmap into a device context, then it should select the original bitmap into the device context before returning. Same for fonts, pens, all that stuff. But what if you decide to violate that convention? For example, maybe you create a memory DC, select a bitmap into it, and just leave the bitmap selected there, selecting it out only when you get around to destroying the DC. Is that really so bad? It sort of depends. The danger of leaving objects selected into a DC for an extended ...

Space Mountain as if the lights were on, and other Disneyland/World secrets

Many years ago, some friends of mine went to Disneyland and got to experience Space Mountain in an unusual way. They went through the ride the normal way, but when the car returned to the load/unload area, the cast member (because that's what Disney calls them) asked, "Do you want to go again?" Everybody in the car enthusiastically shouted, "Yes!" (Presumably they were falling behind on the loading and unloading, and waving a car through saved them a bit of time they could use to catch up.) The second time through the ride was qualitatively different: Their eyes had already acclimated to the dark, so ...

Inadvertently creating dress-like-Steve day

Even if you haven't been paying much attention, you may have noticed that Steve Sinofsky has developed a bit of a uniform for himself. You can pretty much count on him wearing a T-shirt with a V-neck sweater. (There appears to be some sort of alphabetic theme there, but I'm not going to check if he's also wearing a G-string.) Some time ago, I realized as I was heading in to work that for the second day in a row, I happened to be wearing the Steve Sinofsky uniform. Was I subconsciously mirroring the boss? As fate would have it, later that morning, I happened to run into Steve as we both headed from one buildi...