The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Jun 20, 2011
Post comments count 0
Post likes count 1

In Windows, the directory is the application bundle

Raymond Chen

Aaargh! wonders why Windows doesn't just steal the concept of bundles from Apple and package up each application with all its libraries and everything else it needs into a single directory. This is such a great idea, it's been around since the early 1990's. It's just that Windows didn't give it a cute named like bundle. It just gave it the boring name directory. In other words, it's a victim of bad marketing. Maybe we should have given it a cute name like... elfgrass. The first directory searched by the function is the directory containing the application. If you put all your supporting libraries in the same...

Jun 17, 2011
Post comments count 0
Post likes count 1

How do I make a window remain visible even when the user selects Show Desktop?

Raymond Chen

A customer had this question: I'd like to know how to get a window to remain visible, even when the user has selected Show Desktop. Right now, when the user picks Show Desktop, the desktop appears and covers my window. Um, yeah, because that's the whole point of Show Desktop: To show the desktop and get rid of all those windows that are in the way. Windows like yours. We're sorry that Windows was unprepared for a program as awesome as yours, because there's no way to mark your window as even if the user says to show the desktop instead of this window, override the user's command and show the window anyway. (...

Jun 16, 2011
Post comments count 0
Post likes count 1

How do I create a right-aligned toolbar button?

Raymond Chen

I didn't think this was all that common a request, but it came in twice from two different customers, so I guess there are still people creating toolbars, and creating them with right-aligned buttons (even though it violates Windows user interface guidelines, though I can't find a citation right now). You may have noticed that the toolbar common control doesn't provide a facility for creating right-aligned buttons. Partly because it's a violation of the guidelines anyway, but mostly because the default state of every feature is "not implemented." Adding a feature requires work, and since there is only a finite ...

Jun 15, 2011
Post comments count 0
Post likes count 1

How do I convert a UTF-8 string to UTF-16 while rejecting illegal sequences?

Raymond Chen

By default, when you ask to convert a UTF-8 string to UTF-16 that contains illegal sequences (such as overlong sequences), it will try to muddle through as best as it can. If you want it to treat illegal sequences as an error, pass the flag. The MSDN documentation on this subject is, to be honest, kind of hard to follow and even includes a double-negative: "The function does not drop illegal code points if the application does not set this flag." Not only is this confusing, it doesn't even say what happens to illegal code points when you omit this flag; all it says is what it doesn't do, namely that it doesn'...

Jun 14, 2011
Post comments count 0
Post likes count 0

Sufficiently advanced magic is indistinguishable from technology

Raymond Chen

An informal tradition in a former group was that whenever somebody bought a new car, we all went out to lunch to celebrate, but the person with the new car had to be one of the drivers. During one of our new-car trips, the proud owner of the new car showed off its fancy features. "Check this out, this car has a voice-controlled radio: Radio, On." The car radio turned on. "Radio, Select KUOW." The radio changed its station. "Radio, louder." The volume went up. But this wasn't a demonstration of voice-recognition technology. It was a magic trick. You see, the car has radio controls built into the back of th...

Jun 13, 2011
Post comments count 0
Post likes count 1

You don't need to steal focus if you can just arrange for someone to give it to you

Raymond Chen

Commenter doesn't matter proposes a scenario where focus-stealing is necessary: There are two applications A and B, Application B exposes an interface, and Application A connects to application B via that interface, When some sort of even occurs in application B, it notifies application A, which wants to steal focus in order to interact with the user as a result of the event. Actually, this is still not a situation where focus-stealing is necessary. Application B just needs to call on application A before it fires the event, so that when application A receives ...

Jun 10, 2011
Post comments count 0
Post likes count 1

Generally speaking, if your function fails, you should return a failure code

Raymond Chen

A customer requested assistance with their shell namespace extension, and the request worked its way to me for resolution. The customer was at a loss because the customer's code was nowhere on the stack. What is wrong? The customer didn't provide a dump file or any other information beyond the stack trace. (Hint: When reporting a problem with a shell namespace extension, at least mention the last few method calls your namespace extension received before the crash.) I was forced to use my psychic powers to solve the problem. But you can, too. All the information you need is right there in front of you. The...

Jun 9, 2011
Post comments count 0
Post likes count 1

PE resources must be 4-byte aligned, but that doesn't stop people from trying other alignments

Raymond Chen

Resources in PE-format files must be stored at offsets which are a multiple of four. This requirement is necessary for platforms which are sensitive to data alignment. That doesn't stop people from breaking the rules anyway. After all, it sort of works anyway, as long as you're careful. I mean, sure maybe if somebody running a non-x86 version of Windows tries to read your resources, they will crash, but who uses non-x86 versions of Windows, right? In Windows Vista SP1, additional hardening was added to the resource parsing code to address various security issues, but the one that's important today is that ...

Jun 8, 2011
Post comments count 0
Post likes count 1

Microspeak: The planned unplanned outage, and other operations jargon

Raymond Chen

The Operations group at Microsoft manage the servers which keep the company running. And they have their own jargon which is puzzling to those of us who don't spend all our days in a noisy server room. From what I can gather, an Unplanned Outage would be better termed an Unscheduled Outage: We did not have it marked off on our calendar that the server would be unavailable at this time, but it ended up that way. These unscheduled outages fall into two categories: An Unplanned Unplanned Outage is an unscheduled outage that took place of its own volition. In other words, the server crashed or somebody accidentall...