The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Dec 12, 2006
Post comments count 0
Post likes count 1

A high waiter count on a free critical section may indicate a lock convoy

Raymond Chen

Nobody can make any progress because they keep getting stuck.

Dec 11, 2006
Post comments count 0
Post likes count 1

What does an invalid handle exception in LeaveCriticalSection mean?

Raymond Chen

Internally, a critical section is a bunch of counters and flags, and possibly an event. (Note that the internal structure of a critical section is subject to change at any time—in fact, it changed between Windows XP and Windows 2003. The information provided here is therefore intended for troubleshooting and debugging purposes and not for production use.) As long as there is no contention, the counters and flags are sufficient because nobody has had to wait for the critical section (and therefore nobody had to be woken up when the critical section became available). If a thread needs to be bloc...

Dec 8, 2006
Post comments count 0
Post likes count 0

Throwing things into a blender and seeing what happens

Raymond Chen

Manufacturer of commercial and home blenders Blendtec has produced a marketing web site Will It Blend? which features short videos of the company's CEO and new Internet blending icon Tom Dickson throwing all sorts of unusual objects into one of their blenders, to see what happens. (The videos are also on YouTube, and of course they have a blog, cleverly titled Will it Blog?) There's a miniature profile of Tom Dickson in Utah Business Magazine. When Jamba Juice told Dickson the $14,000 blender package was too expensive, he cut them a deal, asking simply for a nickel of every sale. Now, with 50 million smoot...

Dec 8, 2006
Post comments count 0
Post likes count 1

Do not overload the E_NOINTERFACE error

Raymond Chen

One of the more subtle ways people mess up is returning when the problem wasn't actually an unsupported interface. The return value has very specific meaning. Do not use it as your generic "gosh, something went wrong" error. (Use an appropriate error such as or .) Recall that the rules for are that (in the absence of catastrophic errors such as ) if a request for a particular interface succeeds, then it must always succeed in the future for that object. Similarly, if a request fails with , then it must always fail in the future for that object. These rules exist for a reason. In the case where COM needs ...

Dec 7, 2006
Post comments count 0
Post likes count 5

Okay, I changed my mind, I wrote a book after all

Raymond Chen

The Old New Thing: Practical Development Throughout the Evolution of Windows

Dec 6, 2006
Post comments count 0
Post likes count 0

The wisdom of seventh graders: What to do with a time machine (part 3)

Raymond Chen

(Continuing from part 2.) Here are more sentences from seventh grade time travel essays. Remember, these sentences are not representative of seventh grade writing in general; these are just the funny bits. World History The Future: Most students who travelled to the future wanted to meet themselves. Letter Format: Some students took advantage of the fact that the essay took the form of a letter. Best Conclusion

Dec 6, 2006
Post comments count 0
Post likes count 3

If you let people read a file, then they can copy it

Raymond Chen

Here's a question that floated past my view: How do I set the ACLs on a file so users can read it but can't copy it? I can't find a "Copy" access mask that I can deny. If I can't deny copying, I'd at least like to audit it, so I can tell who made a copy of the file. There is no "Copy" access mask because copying is not a fundamental file operation. Copying a file is just reading it into memory and then writing it out. Once the bytes come off the disk, the file system has no control any more over what the user does with them.

Dec 5, 2006
Post comments count 0
Post likes count 0

The wisdom of seventh graders: What to do with a time machine (part 2)

Raymond Chen

(Make sure you've read Part 1 for background information.) On the subject of where they would go in a time machine, many students wrote well-thought-out essays, beautifully composed. These sentences below did not come from those essays. I've categorized the snippets roughly by theme, though I had to guess at some of them since the sentences are taken out of context. (In a futile attempt to assist non-native speakers, I have glossed some of the trickier parts. I've also added editorial comments in italics.) Introductions Personal History: These are essays from students who would travel to their own pas...

Dec 5, 2006
Post comments count 0
Post likes count 1

How do I find all files with at least one space in their name?

Raymond Chen

You already know how to do this, you just don't realize it. How do you find files with an "x" in their name? That's right, you use . Now you just have to change that x to a space. And since spaces are command line delimiters, you need to quote the sequence so it gets treated as a single parameter rather than two "*" parameters: Stick in a if you want to search recursively.