The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

The problem with adding more examples and suggestions to the documentation is that eventually people will stop reading the documentation
Apr 10, 2013
Post comments count 0
Post likes count 0

The problem with adding more examples and suggestions to the documentation is that eventually people will stop reading the documentation

Raymond Chen
Raymond Chen

I am a member of a peer-to-peer discussion group on an internal tool for programmers which we'll call Program Q. Every so often, somebody will get tripped up by smart quotes or en-dashes or ellipses, and they will get an error like C:\> q select table –s “awesome table” Usage: q select table [-n] [-s] table Error: Must specify exactly one table. After it is pointed out that they are a victim of Word's auto-conversion of straight quotes to slanted quotes, there will often be a suggestion, "You should treat en-dashes as plain dashes, smart quotes as straight quotes, and fancy-ell...

On giving a name at the register to be called when your order is ready
Apr 9, 2013
Post comments count 0
Post likes count 0

On giving a name at the register to be called when your order is ready

Raymond Chen
Raymond Chen

Shultzy's Sausage describes itself as "Seattle's Wurst Restaurant since 1989!" It's a local hangout for sausage, beer, chili, and advanced dishes like sausage with beer or sausage with chili. In the early 1990's, Shultzy's expanded to a second location just a few blocks from Microsoft's main campus in Redmond, at a location known to my circle of friends as the location of death. Many neighborhoods have a location of death: It's the location where there's a restaurant that can never manage to stay open. First it's a gyro restaurant. After a few months the gyro restaurant shuts down and a crêpe restaura...

Another meaning of the word leptoceratops
Apr 8, 2013
Post comments count 0
Post likes count 0

Another meaning of the word leptoceratops

Raymond Chen
Raymond Chen

I dreamed that a number of the form (10ⁿ−1)/9 was called a "leptoceratops." And it had to be tied up with a squid.

The managed way to retrieve text under the cursor (mouse pointer)
Apr 8, 2013
Post comments count 0
Post likes count 0

The managed way to retrieve text under the cursor (mouse pointer)

Raymond Chen
Raymond Chen

Today's Little Program is a managed version of the text-extraction program from several years ago. It turns out that it's pretty easy in managed code because the accessibility folks sat down and wrote a whole framework for you, known as UI Automation. (Some people are under the mistaken impression that UI Automation works only for extracting data from applications written in managed code. That is not true. Native code can also be a UI Automation provider. The confusion arises because the name UI Automation is used both for the underlying native technology as well as for the managed wrappers.) using Syste...

How do I wait until all processes in a job have exited?
Apr 5, 2013
Post comments count 0
Post likes count 0

How do I wait until all processes in a job have exited?

Raymond Chen
Raymond Chen

A customer was having trouble with job objects, specifically, the customer found that a Wait­For­Single­Object on a job object was not completing even though all the processes in the job had exited. This is probably the most frustrating part of job objects: A job object does not become signaled when all processes have exited. The state of a job object is set to signaled when all of its processes are terminated because the specified end-of-job time limit has been exceeded. Use Wait­For­Single­Object or Wait­For­Single­Object­Ex to monitor the job object for this event....

Don’t forget, the fourth parameter to ReadFile and WriteFile is sometimes mandatory
Apr 4, 2013
Post comments count 0
Post likes count 0

Don’t forget, the fourth parameter to ReadFile and WriteFile is sometimes mandatory

Raymond Chen
Raymond Chen

The Read­File and Write­File functions have a parameter called lp­Number­Of­Byte­Read, which is documented as __out_opt LPDWORD lpNumberOfBytesRead, // or __out_opt LPDWORD lpNumberOfBytesWritten, "Cool," you think. "That parameter is optional, and I can safely pass NULL." My program runs fine if standard output is a console, but if I redirect standard output, then it crashes on the Write­File call. I verified that the handle is valid. int __cdecl main(int, char **) { // error checking removed for expository purposes HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); ...

How can I move an HTREEITEM to a new parent?
Apr 3, 2013
Post comments count 0
Post likes count 0

How can I move an HTREEITEM to a new parent?

Raymond Chen
Raymond Chen

Suppose you have a TreeView control, and you created an item in it, and you want to move the to a new parent. How do you do that? You can't, at least not all in one motion. You will have to delete the and then re-create it in its new location. If you want to move an within the same parent (say, to reorder it among its siblings), then you can use and pass a custom sort function that rearranges the children into the order you want.

Where did the research project RedShark get its name?
Apr 2, 2013
Post comments count 0
Post likes count 0

Where did the research project RedShark get its name?

Raymond Chen
Raymond Chen

Project code names are not arrived at by teams of focus groups who carefully parse out every semantic and etymological nuance of the name they choose. (Though if you read the technology press, you'd believe otherwise, because it turns out that taking a code name apart syllable-by-syllable searching for meaning is a great way to fill column-inches.) Usually, they are just spontaneous decisions, inspired by whatever random thoughts jump to mind. Many years ago, there was an internal user interface research project code named RedShark. Not Red Shark but RedShark, accent on the Red. Where did this strange name come...

The joke’s on you, because PATH goes to Penn Station, not Grand Central!
Apr 1, 2013
Post comments count 0
Post likes count 0

The joke’s on you, because PATH goes to Penn Station, not Grand Central!

Raymond Chen
Raymond Chen

I dreamed that I was asked to develop a hill-avoiding bike route from my childhood home. Along the way, I rode through a daycare playroom (twice, due to a spiral path), met Madonna, the ghost of Alec Baldwin's wife, a team from The Amazing Race trying to figure out which PATH train goes to Grand Central (trick question!) and waited for the next train with a supervillain who demonstrated his powers by using his stretchy arms to punch one of my colleagues who was standing ten feet away and who electrocuted another colleague's pacemaker by force of will. Yes, I know that Alec Baldwin is not a widower, and my colle...