The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Mar 8, 2013
Post comments count 0
Post likes count 0

Microsoft-internal Chuck Norris facts

Raymond Chen

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.

Mar 8, 2013
Post comments count 0
Post likes count 1

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

Raymond Chen

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

Mar 7, 2013
Post comments count 0
Post likes count 1

What are the conventions for managing standard handles?

Raymond Chen

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, Get­Std­Handle 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...

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

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

Raymond Chen

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

Mar 5, 2013
Post comments count 0
Post likes count 0

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

Raymond Chen

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

Mar 5, 2013
Post comments count 0
Post likes count 0

Inadvertently creating dress-like-Steve day

Raymond Chen

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

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

Around and around and back and somewhere else

Raymond Chen

I dreamed that I was navigating through an enormous house, with lots of twists and turns. I eventually became convinced that the house was only locally Euclidean. Yes, I sometimes have topology dreams.

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

Marking a shortcut to say that it should not be placed on the Windows 8 Start page upon installation or treated as a newly-installed application

Raymond Chen

Today's Little Program creates a shortcut on the Start menu but marks it as "Do not put me on the front page upon installation." This is something you should do to any secondary shortcuts your installer creates. And while you're at it, you may as well set the "Don't highlight me as a newly-installed program" attribute used by Windows 7. (Remember, Little Programs do little to no error checking.) #define UNICODE #define _UNICODE #define STRICT #include <windows.h> #include <shlobj.h> #include <atlbase.h> #include <propkey.h> #include <shlwapi.h> int __cdecl wmain(int, wchar_t...

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

The source of much confusion: “backed by the system paging file”

Raymond Chen

Perhaps one of the most misunderstood sentences in the Win32 documentation is this little bit in the documentation for : If hFile is INVALID_HANDLE_VALUE, the calling process must also specify a size for the file mapping object in the dwMaximum­Size­High and dwMaximum­Size­Low parameters. In this scenario, Create­File­Mapping creates a file mapping object of a specified size that is backed by the system paging file instead of by a file in the file system. When people read the underlined portion, they interpret this to mean "The data in the file mapping object will be written to the ...