The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

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

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

You'd think that with the name scratch, people wouldn't expect it to be around for a long time

Raymond Chen

There is a server run by the Windows team called . Its purpose is to act as a file server for storing files temporarily. For example, if you want to send somebody a crash dump, you can copy it to the scratch server and send the person a link. The file server is never backed up and is not designed to be used as a permanent solution for anything. The Windows team likes to use the server to test various file server features. For example, the scratch server uses hierarchical storage management and migrates files to tape relatively aggressively, so that the HSM development team can get real-world usage of their fea...

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

Why do Group Policy settings require me to have a degree in philosophy?

Raymond Chen

Commenter Josh points out that Group Policy settings often employ double-negatives (and what's the difference between turning something off and not configuring it)? Group Policy settings are unusual in that they are there to modify behavior that would continue to exist without them. They aren't part of the behavior but rather a follow-on. Suppose that the default behavior is to do XYZ automatically, but due to requests from corporate customers, a Group Policy is added to alter this behavior. The Group Policy for this might look like this: Don't do XYZ automatically Enabled Disabled Not configured The t...

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

Swamping the thread pool with work faster than it can drain

Raymond Chen

This scenarios is real, but details have been changed to protect the guilty. Consider a window showing the top of a multi-page document. The developers found that when the user clicks the down-arrow button on the scroll bar, the program locks up for 45 seconds, over a dozen threads are created, and then suddenly everything clears up and the window displays the final paragraph of the document (i.e., it scrolled all the way to the bottom). The problem was traced to queueing tasks to the thread pool faster than they can drain. The document is an object which, unlike a window, has no thread affinity. (Naturall...