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

2013 Q1 link clearance: Microsoft blogger edition

It's that time again: Linking to other Microsoft bloggers.

How do I convert a method name to a method index for the purpose of INTERFACEINFO?

The IMessageFilter::HandleIncomingCall method describes the incoming call by means of an INTERFACEINFO structure: typedef struct tagINTERFACEINFO { LPUNKNOWN pUnk; IID iid; WORD wMethod; } INTERFACEINFO, *LPINTERFACEINFO; The wMethod is a zero-based index of the method within the interface. For example, IUnknown::QueryInterface has index zero, IUnknown::AddRef has index one, and IUnknown::Release has index two. If you want to filter on a method in an interface, you need to know its index. One way of doing this would be to sit and count the methods, but this is erro...

The C language specification describes an abstract computer, not a real one

If a null pointer is zero, how do you access the memory whose address is zero? And if C allows you to take the address one past the end of an array, how do you make an array that ends at , since adding one to that value would wrap around? First of all, who says that there is a byte zero? Or a byte ? The C language does not describe an actual computer. It describes a theoretical one. On this theoretical computer, it must be possible to do certain things, like generate the address of one item past the end of an array, and that address must compare greater than the address of any member of the array. But how...

“Adjust visual effects for best performance” should really be called “Adjust visual effects for crappiest appearance”

In the Performance Options control panel, on the tab labeled Visual Effects, there is a radio button called Adjust for best performance. If you select it, then all the visual effects are disabled. But the name of that radio button has been wrong for a long time. It doesn't actually adjust your visual effects for best performance. It just adjusts them for crappiest appearance. Starting in Windows Vista, a lot of visual effects were offloaded to the graphics card. Consequently, the impact on system performance for those visual effects is negligible, and sometimes turning off the effect actually makes your syst...

There’s no law that says two people can’t have the same thing to eat

Some time ago, my group went out for a team lunch. It was to a restaurant we were not familiar with, so there was quite a bit of time studying the menu. As everybody looked over the menu, discussion naturally turned to "So what are you going to have?" "I think I'll have the salmon sandwich." One of my colleagues replied, "Oh, rats. I was thinking of having that." I remarked, "There's no law that says two people can't order the same thing." My colleague disagreed. Not if you ask my wife. Whenever we go out to eat, she'll ask me what I'm having, and then she'll say "Oh, rats. I was thinking of having ...

Dreaming about a rather unusual guitar rehearsal

I dreamed that I watched a long-time colleague of mine rehearse the guitar in preparation for the new "hot pants" competition of the Miss Universe pageant. The scary thing is that the pageant may actually do it.

Using accessibility to monitor windows as they come and go

Today's Little Program monitors windows as they come and go. When people contemplate doing this, they come up with ideas like installing a WH_CBT hook or a WH_SHELL hook, but one of the major problems with those types of hooks is that they are injected hooks. Injection is bad for a number of reasons. It forces the hook to be in a DLL so it can be injected. Hook activities need to be marshaled back to the main program. Your DLL will capture events only in processes of the same bitness, because you cannot load a 32-bit DLL into a 64-bit process or vice versa. You can inject into an elevated process o...

When will GetMessage return -1?

A source of great consternation is the mysterious return value from : If there is an error, the return value is −1. For example, the function fails if is an invalid window handle or is an invalid pointer. That paragraph has caused all sorts of havoc, because it throws into disarray the standard message pump: But don't worry, the standard message pump is safe. If your parameters are exactly then will not fail with . Originally, the function did not have a failure mode. If you passed invalid parameters, then you invoked undefined behavior, and you probably crashed. Later, somebody sai...

Does this operation work when file system redirection is disabled? The default answer is NO

A customer reported that when their program called to get the icon for a folder, the call failed. "It works on some machines but not others. We don't know what the difference is between the working and non-working machines." They included the offending function from their program, but everything in the function looked good. The problem was something outside the function itself. Eventually, the customer confessed that they had called the function to disable file system redirection, and the call to took place while redirection was disabled. "We found that if we re-enable file system redirection before calling ...