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

Microspeak: Zap

You may hear an old-timer developer use the verb zap. That proposed fix will work. Until everybody gets the fix, they can just zap the assert. The verb to zap means to replace a breakpoint instruction with an appropriate number of NOP instructions (effectively ignoring it). The name comes from the old Windows 2.x kernel debugger. (Actually, it may be even older, but that's as far back as I was able to trace it.) The (zap) command replaces the current instruction with a NOP if it is an (the x86 single-byte breakpoint instruction), or replaced the previous instruction with NOPs if it is an (the x86 two-by...

Why doesn't the window manager have a SetClipboardDataEx helper function?

Jonathan Wilson asks why the clipboard APIs still require GlobalAlloc and friends. Why is there not a or something that does what does but without needing to call ? Okay, here's your function: Whoop-dee-doo. Historically, Windows doesn't go out of its way to include functions like this because you can easily write them yourself, or you can at least find a framework library that did it for you. Windows focused on doing the things that only Windows could do, providing you the building blocks with which you can create your own programs. Besides, the classic clipboard is so old-school. The OLE clipboard...

During process termination, the gates are now electrified

It turns out that my quick overview of how processes exit on Windows XP was already out of date when I wrote it. Mind you, the information is still accurate for Windows XP (as far as I know), but the rules changed in Windows Vista. What about critical sections? There is no "Uh-oh" return value for critical sections; doesn't have a return value. Instead, the kernel just says "Open season on critical sections!" I get the mental image of all the gates in a parking garage just opening up and letting anybody in and out. In Windows Vista, the gates don't go up. Instead they become electrified!...

Historically, Windows didn't tend to provide functions for things you can already do yourself

Back in the old days, programmers were assumed to be smart and hardworking. Windows didn't provide functions for things that programs could already do on their own. Windows worried about providing functionality for thing that programs couldn't do. That was the traditional separation of responsibilities in operating systems of that era. If you wanted somebody to help you with stuff you could in principle do yourself, you could use a runtime library or a programming framework. You know how to open files, read them, and write to them; therefore, you could write your own file copy function. You know how to walk a l...

The wrong way to determine the size of a buffer

A colleague of mine showed me some code from a back-end program on a web server. Fortunately, the company that wrote this is out of business. Or at least I hope they're out of business!

The hardest part of writing the video game Monty Python's Complete Waste of Time

Many years ago, I happened to have lunch with one of the programmers who worked on the video game Monty Python's Complete Waste of Time (read a review). This program was notable in many ways, most geekily that it was brought on board the Mir space station by astronaut Michael Foale. Anyway, during the course of lunch, I learned something unusual: "The hardest part of writing that program? Synchronizing the farts [sounds] to the video." Vaguely related : How the Space Shuttle and International Space Station use Outlook. Not really related: Trailer for IMAX Hubble 3D movie.

People just like you, for certain values of you

I received a brochure in the mail for a local church which says that it's "full of people just like you." Everybody in the brochure is white. "You'll fit right in!" it concludes. Bonus chatter: My friends guessed that perhaps the church members are all computer programmers who work at Microsoft and speak Swedish badly.

It's fine to rename a function in your DEF file, but when you do, you have to link to that function by its new name

Jeffrey Riaboy asks why, if he renames a function in his DEF file, attempts to link to the function by its old name fail. Well, um, yeah, because you renamed it. Let's take the situation apart a bit; maybe it'll make more sense. I'm going to ignore a lot of details (, calling conventions) since they are not relevant to the discussion and would end up just being distracting. I'm also going to assume we are running on an x86-class machine, just for concreteness. The same discussion works for other platforms; you just have to adjust the conventions accordingly. First, here is some source code for a DLL, let...

How you might be loading a DLL during DLL_PROCESS_DETACH without even realizing it

As you are I'm sure aware, you shouldn't be doing much of anything in your function, but you have to watch out for cases where you end up doing them accidentally. Some time ago, I was investigating a failure which was traced back to loading a DLL inside . Wait, what kind of insane person loads a DLL as part of shutting down? Shouldn't you be cleaning up stuff, not creating new stuff? The following is not the actual code, but it captures the same spirit: There is some global variable that contains a pointer to memory that was allocated by . In this case, I made it a cache, but the details aren't important...