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

Stupid command-line trick: Counting the number of lines in stdin

On unix, you can use to count the number of lines in stdin. Windows doesn't come with , but there's a sneaky way to count the number of lines anyway: It is a special quirk of the command that the null string is treated as never matching. The flag reverses the sense of the test, so now it matches everything. And the flag returns the count. It's pretty convoluted, but it does work. (Remember, I provide the occasional tip on batch file programming as a public service to those forced to endure it, not as an endorsement of batch file programming.) Now come da history: Why does the command say that a nul...

Magic dirt, the fate of former professional athletes, and other sports randomness

A sports-related (mostly baseball) link dump.

What do SizeOfStackReserve and SizeOfStackCommit mean for a DLL?

Nothing. Those fields in the structure are meaningful only when they appear in the EXE. The values provided in DLLs are ignored. and fall into the same category. In general, flags and fields which control process settings have no effect when declared in a DLL. We've seen a few examples already, like the flag or the markers which indicate the default layout direction.

Why doesn't the Open Files list in the Shared Folders snap-in show all my open files?

A customer wanted a way to determine which users were using specific files on their server. They fired up the Shared Folders MMC snap-in and went to the Open Files list. They found that the results were inconsistent. Some file types like and did show up in the list when they were open, but other file types like did not. The customer asked for an explanation of the inconsistency and for a list of which file types work and which ones don't. The customer is confusing two senses of the term open file. From the file system point of view, an open file is one that has an outstanding handle reference. This is differ...

You don't make something easier to find by hiding it even more deeply

Commenter rolfhub suggested that, to help people recover from accidentally going into Tiny Footprint Mode, the Task Manager could display a right-click context menu with an entry to return to normal mode. My initial reaction to this was Huh? Who right-clicks on nothing? Tiny Footprint Mode is itself already a bad secret hidden setting. Having the exit from the mode be a right-click menu on a blank space is a double-secret hidden setting. If I had dictatorial control over all aspects of the shell, I would put a Restore button in the upper right corner to let people return to normal mode.

Why are the alignment requirements for SLIST_ENTRY so different on 64-bit Windows?

The function stipulates that all list items must be aligned on a boundary. For 32-bit Windows, is 8, but the structure itself does not have a attribute. Even more confusingly, the documentation for says that the 64-bit structure needs to be 16-byte aligned but says nothing about the 32-bit structure. So what are the memory alignment requirements for a 32-bit , 8 or 4? It's 8. No, 4. No wait, it's both. Officially, the alignment requirement is 8. Earlier versions of the header file did not stipulate 8-byte alignment, and changing the declaration would have resulted in existing structures which ...

Ow, I'm too safe!

One of my friends is a geek, and, naturally, fully researches everything he does, from cement pouring to bicycle parts, perhaps a bit obsessively. He made sure to get five-point restraints for his children's car seats, for example. And he naturally tightens the belts snugly when putting his children in the car. At one point, as he was strapping his daughter in, she complained, "Ow! I'm too safe!" Because as far as she was concerned, "being safe" was a synonym for "having a tight seat belt." I leave you to figure out how she came to this conclusion.

Why does IFileOperation skip junctions even though I passed FOFX_NOSKIPJUNCTIONS?

The method accepts a number of flags to modify the file operation, among them today's subject . A customer reported that they couldn't get this flag to work: Whether they set it or not, the skipped over file system junctions. The term junction evolved two independent different meanings. The shell team invented the term shell namespace junction in Windows 95 to refer to a point in the shell namespace in which one type of namespace extension is grafted into another. For example, a directory of the form serves as the transition point between the default file system namespace and a custom namespace. Meanw...

Starting up inside the box

the shell team received two customer questions about a month apart which seemed unrelated but had the same root cause. I found that in Windows Vista, the command is ten times slower than it was in Windows XP. What is the source of this slowdown, and how can I fix it? We have an application which takes a very long time to start up on Windows Vista than it did in Windows XP. We noticed that the slowdown occurs only if we set the application to autostart. Let's look at the second one first, since that customer provided a useful piece of information: The slowdown occurs only if they set the progr...