The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Feb 25, 2011
Post comments count 0
Post likes count 1

Why does WaitForMultipleObjects return ERROR_INVALID_PARAMETER when all the parameters look valid to me?

Raymond Chen

A customer asked for assistance with the function: I am getting when calling even though all the parameters are valid as far as I can tell. I've narrowed it down to this simple program. First of all, thank you for narrowing the issue down to a minimal program that illustrates the problem. You'd be surprised how often a customer says, "I'm having problem with function X. Here's a program that illustrates the problem." And then attaches a huge project that doesn't compile because it is written in some development environment different from the one you have on your machine. The problem here is that...

Feb 24, 2011
Post comments count 0
Post likes count 1

iPhone pricing as economic experiment

Raymond Chen

Back in 2005, Slate's Tim Harford wondered why Microsoft didn't raise the introductory price of Xbox 360 game consoles. With the price set at $300, lines were long and shortages were many. Harford's readers came up with their own theories for resisting the laws of supply and demand and holding to a fixed price. The Xbox 360 is hardly unique in this respect. When there's a hot product, manufacturers hold to the original price and let the lines grow, the shortages fester, and the customers get more frustrated. Think Tickle Me Elmo or Cabbage Patch Kids. Even though from an economic-theoretical standpoi...

Feb 24, 2011
Post comments count 0
Post likes count 1

Shortcuts are serializable objects, which means that they can be stored in places other than just a file

Raymond Chen

It's true that the vast majority of the time, people consider the shell shortcut object as synonymous with the file it is normally saved into, shortcuts need not spend their time in a file. You can put a shortcut anywhere you can save a hunk of bytes. Here's a program that creates a shortcut to the file name passed on the command line (make sure it's a full path), and then serializes the shortcut to a blob of bytes (in the form of a ). Once that's done, it reconstitutes the bytes back into a shortcut object and sucks information out of it. After creating the shortcut object, we serialize it into a stream bac...

Feb 23, 2011
Post comments count 0
Post likes count 1

How long does an idle UNC connection remain active before it is automatically disconnected?

Raymond Chen

When you access a resource via a UNC, the Windows network redirector keeps the virtual circuit open for a while even after you close the resource. This is done to take advantage of locality: If you access a network resource once, you're probably going to access it again in a short time, so the redirector leaves the connection open for a little bit, on the off chance that you're going to use it again. For example, if copying a bunch of files from a server via a UNC, once one file copy is complete, the next one is going to start very shortly thereafter. If there is no activity on a connection for a while, then th...

Feb 22, 2011
Post comments count 0
Post likes count 1

Dr. Watson and the bluescreen – a story from the trenches

Raymond Chen

A fellow Microsoft employee volunteered a story from his prior work at a hospital as their enterprise architect. I received an escalation from our Tier 1 service desk on a Dr. Watson. Why would I get a simple escalation? Strange... Since I hadn't seen the outside of my cubicle for a while, I decided to walk over to talk to the customer in person. The employee having the problem was named Dr. Watson. His computer had bluescreened. I still get a chuckle out of that years later. That little unexpected name collision threw twelve people in the IT service and support teams into disarray.

Feb 21, 2011
Post comments count 0
Post likes count 0

Sharktopus: Just when you thought it was safe to see what movies are coming out

Raymond Chen

Sharktopus: Half-shark. Half-octopus. All-killer. I am not making that up. The Web site is sharktopusmovie.com, presumably because sharktopus.com was already taken. I am not making that up. I guess they wanted to ride the coattails of Megashark vs. Giant Octopus? Even more disturbing discovery: Megashark vs. Giant Octopus has a sequel: Megashark versus Crocosaurus. One of my colleagues says that he's going to wait for the sequel: Sharktopuses on a Plane.

Feb 21, 2011
Post comments count 0
Post likes count 1

If an operation results in messages being sent, then naturally the target window must be processing messages for the operation to complete

Raymond Chen

If an operation includes as part of its processing sending messages, then naturally the target window for those messages must be processing messages (or more precisely, the thread which owns the target window must be processing messages) in order for the operation to complete. Why? Because processing messages is the only way a window can receive messages! It's sort of tautological yet not obvious to everyone. Generally you run into this problem when you try to manipulate a window from a thread different from the one which created the window. Since windows have thread affinity, operations from off-thread typical...

Feb 18, 2011
Post comments count 0
Post likes count 1

WM_NCHITTEST is for hit-testing, and hit-testing can happen for reasons other than the mouse being over your window

Raymond Chen

The message is sent to your window in order determine what part of the window corresponds to a particular point. The most common reason for this is that the mouse is over your window. Although triggers most often for mouse activity, that is not the only reason why somebody might want to ask, "What part of the window does this point correspond to?" Consider a program that wants to beep when the mouse is over the Close button. This is an artificial example, but you can use your imagination to come up with more realistic ones, like showing a custom mouseover animation or displaying a balloon tip if the doc...

Feb 17, 2011
Post comments count 0
Post likes count 1

What is the highest numerical resource ID permitted by Win32?

Raymond Chen

A customer asked the following question: What is the maximum legal value of a resource identifier? Functions like take a as the resource ID, which suggests a full 32-bit range, but in practice, most resource IDs appear to be in the 16-bit range. Is there any particular history/precedent for avoiding large numbers as resource IDs? (I have a program that autogenerates string IDs, and having a full 32-bit range gives me some more flexibility in assigning the IDs, but I want to make sure I don't run afoul of any limitations either.) Let's answer the literal question first, and then look at the misconceptions behi...