The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Raymond 1, Sidewalk 1
May 19, 2006
Post comments count 0
Post likes count 0

Raymond 1, Sidewalk 1

Raymond Chen
Raymond Chen

I successfully avoided the stealth sidewalk the other day. This evens the score. (Today is Starbucks Bike to Work Day.)

Redirecting output can result in altered program behavior
May 19, 2006
Post comments count 0
Post likes count 0

Redirecting output can result in altered program behavior

Raymond Chen
Raymond Chen

Consider a program whose output to the console goes like this. (I've prefixed each line with the output stream.) You want to capture both the normal and error streams, so you run the program and append "" to capture both streams into a single file. But when you look at the resulting output file, you get this: What happened? Most programs change their output behavior depending on whether the output stream is a file or a device. If the output stream is a device (such as the screen), then buffering is disabled and every print statement goes to the screen immediately. On the other hand, if the output stream ...

Making up new Winter Olympic events
May 18, 2006
Post comments count 0
Post likes count 0

Making up new Winter Olympic events

Raymond Chen
Raymond Chen

My approach to inventing new Winter Olympic events is to create new opportunities for head-to-head competition, opening the door to new dramatic possibilities. For example, in Ski Jump Biathlon, one team jumps while the other team tries to shoot them (with paint pellets, of course) as they sail through the air. In Figure Curling, one team performs a free skate while the other team hurls granite stones down the ice in an attempt to foil that triple toe loop. Japanese filmmaker Riichiro Mashima was also bitten by the sport-inventing bug. His creation: Ski Jumping Pairs. I'm going to have to check it out.

The redirection operator can occur in the middle of the command line
May 18, 2006
Post comments count 0
Post likes count 0

The redirection operator can occur in the middle of the command line

Raymond Chen
Raymond Chen

Although the redirection operator traditionally appears at the end of a command line, there is no requirement that it do so. All of these commands are equivalent: All of them echo "A B" to the file "C". You can use this trick to avoid the redirection problem we discussed last time. We saw that writing inadvertently interprets the "2" as part of the redirection operator. One solution was to insert a space: but this assumes that the space won't cause a problem. If you're in a case where that space will indeed cause a problem, you can use the trick above to move the redirection operator to a location wh...

Don't mention the war. I mentioned it once, but I think I got away with it all right
May 17, 2006
Post comments count 0
Post likes count 0

Don't mention the war. I mentioned it once, but I think I got away with it all right

Raymond Chen
Raymond Chen

The Germans is probably the most well-known episode of Fawlty Towers. Who better than John Cleese, therefore, to release the song Don't Mention the War, just in time for the World Cup. The purpose is to mend fences between Britain and Germany, but it might just make things worse, who knows.

Beware of digits before the redirection operator
May 17, 2006
Post comments count 0
Post likes count 0

Beware of digits before the redirection operator

Raymond Chen
Raymond Chen

If you want to put the string "Meet at 2" into the file "schedule", you might be tempted to use If you try this, however, you'll see the string "Meet at" on the screen and the "schedule" file will be blank. [Typo fixed, 10am] What happened? A digit immediately before a redirection operator modifies which stream the redirection operator applies to. If you're going to redirected an alternate output stream, it'll nearly always be the standard error stream, or stream 2. To put the error output into a file, you would write something like this: There is also the operator ">&" that reopens a strea...

The real scoop on the the x64 calling convention on 64-bit Windows
May 16, 2006
Post comments count 0
Post likes count 0

The real scoop on the the x64 calling convention on 64-bit Windows

Raymond Chen
Raymond Chen

Official (though preliminary) documentation on the x64 calling convention is available on MSDN, for those who want more than my quack overview. (Oops, I meant "quick overview". Little Freudian slip there.)

Command line redirection is performed by the command line interpreter
May 16, 2006
Post comments count 0
Post likes count 0

Command line redirection is performed by the command line interpreter

Raymond Chen
Raymond Chen

The magic characters like <, >, and | in command lines like are interpreted by the command interpreter ; they aren't built into the function. (This is obvious if you think about it. That command line created two processes; which one should return a handle to?) If you pass a command line like this to , it will merely run the program with the command line arguments "| sort > output.txt". (The function behaves similarly.) If you want these characters to be interpreted as redirection operators, you need to give them to someone who will interpret those characters in the manner you intend: Since d...

The first word on the command line is the program name only by convention
May 15, 2006
Post comments count 0
Post likes count 0

The first word on the command line is the program name only by convention

Raymond Chen
Raymond Chen

The format of the command line returned by is "", but this is only a convention. If you pass for the to the function, then the function will treat the first word of the as the program name. However, if you pass a value for , then that string determines the program that is run, and the string passed as the is not used for that purpose. This means that if somebody runs your program with the following parameters to the function then when your program calls the function, it will get the string , which doesn't give your program much help at all in determining its own name or location. If your program need...