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

As random as I wanna be: Why cmd.exe's %RANDOM% isn't so random

Somebody on my team reported that a particular script in our project's build process would fail with bizarre output maybe once in fifty tries. This script was run from a , and the result was a failed build. Rerunning make fixed the problem, but that's not much consolation when the build lab encounters it approximately every other day. The strange thing about the bizarre output was that it appeared to contain a mix of two different runs. How could the output of two runs be mixed into one output file? The script was a batch file, and it generated its output in a few different steps, storing the intermediate outp...

I always do a double-take when I see the name Andrew Bynum

I always think, "Does he have teammates Andrew Byref and Andrew Byval?"

Why can't AppLocale just be added to the Compatibility property sheet page?

Commenter DoesNotMatter wants to know why AppLocale cannot just be added to the Compatibility property sheet as a dropdown option. One of the things about having a huge topic backlog is that if I just wait long enough, there's a good chance somebody else will answer it, and then I don't have to write anything. And more often than not, that somebody else is Michael Kaplan, who addressed this question in April 2010: Not only is AppLocale not installed by default, AppLocale does everything in its power to remind you that you shouldn't be using it! AppLocale is the emergency compact spare tire that you pull out ...

What does the PRE in PREfast stand for?

Commenter Jeff asks what the PRE in PREfast stands for. It's an inside joke. The Microsoft Programmer Productivity Research Center (MSPPRC) originally produced a tool called PREfix. Michael Howard put me in touch with the development team, and they explained that it was called PREfix because it helps you fix your bugs before (PRE) you even run the code. The problem with PREfix was that it required monster hardware, and even if you got the hardware up and running, the results took days to generate, and tuning the program's parameters required intricate knowledge of its inner workings. In other words, it was ...

Hunting for loopholes in Washington state's driving-while-phoning-or-texting law

Last week, a law went into effect in the state of Washington which makes driving while texting or using a hand-held phone a primary offense, meaning that you can be pulled over for doing it. (Previously, it was a secondary offense, which means that the officer must have some other reason for pulling you over.) One of my colleagues studied the new law when it was passed and believes he found a loophole. According to RCW 46.61.667 subsection (2)(c)(i), driving-while-phoning is legal if the driver is using the phone to report illegal activity. My colleague points out that the law does not say whom you have t...

Annotating function parameters and using PREfast to check them

Via the suggestion box, Sys64738 asks, whether I think is a good C/C++ programming style to add IN and OUT to function prototypes. Remember, this is my opinion. Your opinion may validly differ. I would go beyond just IN and OUT and step up to SAL annotations, which describe the semantics of function parameters in more detail than simply IN and OUT. For example, the annotation lets you specify not only that the buffer is an output parameter, but also lets you specify how big the buffer is. This added expressiveness is used by tools like PREfast and its user-mode equivalent the C/C++ Code Analysis tool. The...

My niece asked me what color seashell I would like her to draw

My niece was amusing herself by drawing pictures with crayon, and she asked me, "I'm going to draw a seashell for you. What color do you want?" I said, "Blue." She responded, "No."

How do I indicate that I want my window to follow right-to-left layout rules?

There are many ways, depending on how wide a scope you want. If there is one specific window that you want to follow right-to-left layout rules, then you pass the extended window style when you create the window. This extended style is inherited by child windows, so once you set a top-level window to have right-to-left layout, all child windows will have it, too. To block the extended style from being inherited by child windows, pass the style when you create the parent window. Sidebar: If you're calling the function, then you don't directly control the styles of the top-level window. But there's a weird ba...

When you set a 100% CPU program to real-time priority, you get what you asked for

Real-time priority is really dangerous. It's higher priority than nearly everything else. It's higher priority than mouse input, keyboard input, and the disk cache. If you foolishly set the priority class of a CPU-intensive program to real-time, it will suck up your entire processor, leaving no cycles for anything else. In particular, since not even input runs at real-time priority, you can't stop it via any interactive means, because the thread that manages input can't even run to process your input. Mind you, even if the input thread did run at real-time priority, that wouldn't really help you any. Sure, it...