The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Nov 6, 2014
Post comments count 0
Post likes count 2

How do I get a handle to the primary monitor?

Raymond Chen

There are various ways of getting a monitor. You can get the monitor from a point, from a rectangle, or from a window. But how do you get the primary monitor? The primary monitor is defined to be the one which has (0, 0) as its origin. Therefore, one solution is The desktop window by convention is deemed to reside primarily on the primary monitor, so you could also use this: Or you could just pass the null window handle. This is technically an illegal parameter, but by specifying , you are saying, "If anything goes wrong, give me the primary monitor." In this case, we are intentionally going astray b...

Nov 5, 2014
Post comments count 0
Post likes count 1

Passing the incorrect object type for a handle, how bad is it?

Raymond Chen

A customer asked a somewhat strange question: "We are calling but passing the handle to a waitable timer. Application Verifier reports, "Incorrect object type for handle." But the code works well. We want to know the risks of passing the wrong object type to . Is the recommendation only to pass handles of type "Event" to ? Let's answer those questions in reverse order. Yes, the recommendation is only to pass handles of type "Event" to , just as the recommendation is only to pass handles of type "Semaphore" to , and more generally, only to pass valid parameters to functions. What is the risk of passing the wro...

Nov 4, 2014
Post comments count 0
Post likes count 1

Microspeak: Line of sight

Raymond Chen

I first encountered this term in a meeting I attended. Q: We would like to be able to reverse the polarity of the neutron flow without requiring a reboot. A: Yes, that is something we've been thinking about, but we don't have line of sight to having that feature before the end of the month. From context, having line of sight to a result means something like "Have made it part of our immediate plans to achieve that result." This appears to be extending the idiom on the horizon. Literally, something on the horizon. is at the edge of what can be seen. Figuratively, then, something that is on the horizon is a...

Nov 3, 2014
Post comments count 0
Post likes count 2

Applying a filter to the contents of an Explorer Browser

Raymond Chen

Today's Little Program hosts an Explorer Browser but filters the contents to remove DLL files. You can, of course, substitute your own filter. (For example, maybe you want to show only files that changed since the last time the user ran your program, or you might want a view of My Computer but filtered to show only removable drives.) Remember that Little Programs do little to no error checking, and they don't necessarily demonstrate the best programming style. They're just quick demonstrations. Today's smart pointer library is… (rolls dice) … WRL! Start with our minimal explorer browser progra...

Oct 31, 2014
Post comments count 0
Post likes count 1

The case of the file that won't copy because of an Invalid Handle error message

Raymond Chen

A customer reported that they had a file that was "haunted" on their machine: Explorer was unable to copy the file. If you did a copy/paste, the copy dialog displayed an error. Okay, time to roll up your sleeves and get to work. This investigation took several hours, but you'll be able to read it in ten minutes because I'm deleting all the dead ends and red herrings, and because I'm skipping over a lot of horrible grunt work, like tracing a variable in memory backward in time to see where it came from.¹ The Invalid file handle error was most likely coming from the error code . Some tracing of ha...

Oct 30, 2014
Post comments count 0
Post likes count 2

Why is the FAT driver called FASTFAT? Why would anybody ever write SLOWFAT?

Raymond Chen

Anon is interested in why the FAT driver is called FASTFAT.SYS. "Was there an earlier slower FAT driver? What could you possibly get so wrong with a FAT implementation that it needed to be chucked out?" The old FAT driver probably had a boring name like, um, FAT.SYS. At some point, somebody decided to write a newer, faster one, so they called it FASTFAT. And the name stuck. As for what you could possibly get so wrong with a FAT implementation that it needed to be improved: Remember that circumstances change over time. A design that works well under one set of conditions may start to buckle when placed under al...

Oct 29, 2014
Post comments count 0
Post likes count 1

The contents of the Start page are not programmatically accessible

Raymond Chen

A customer wanted to know if is possible for an application to edit the user's Start page. No, there is no interface for editing the user's Start page or even knowing what is on it. The Start page is the user's personal space and applications should not be messing with it. Imagine if it were possible. Every application would edit the Start page to put themselves at the front! It turns out that the customer wanted their application to make some changes to the user's Start page when it was installed. Specifically, they wanted to hunt down tiles belonging to their competitors and delete them, then insert a tile f...

Oct 28, 2014
Post comments count 0
Post likes count 1

A question about preventing the system from going to the idle state turns out to be misguided

Raymond Chen

A customer asked how they could have their program prevent the system from going to the idle state. Specifically, when the system goes idle, the application gets into a weird state where it starts leaking memory like crazy. The program normally uses around 100MB of memory, but when the system goes idle, something funky happens and the program's memory usage shoots up to 4GB. To avoid this problem, they want to prevent the system from entering the idle state. Now, if your application is a special-purpose program running on a dedicated computer, then blocking the entry into the idle state might be acceptable. Aft...

Oct 27, 2014
Post comments count 0
Post likes count 1

Enumerating the ways of distributing n balls into k boxes

Raymond Chen

Suppose you had n indistinguishable balls and k distinguishable boxes. Enumerate the ways of distributing the balls into boxes. Some boxes may be empty. We can represent each distribution in the form of n stars and k − 1 vertical lines. The stars represent balls, and the vertical lines divide the balls into boxes. For example, here are the possible distributions for n = 3, k = 3: This visualization is known in combinatorics circles as stars and bars. From this visualization, we see that what we are doing is taking n + k − 1 slots, and in each slot placing a star or a bar, subject to the const...