The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Apr 4, 2013
Post comments count 0
Post likes count 1

Don’t forget, the fourth parameter to ReadFile and WriteFile is sometimes mandatory

Raymond Chen

The Read­File and Write­File functions have a parameter called lp­Number­Of­Byte­Read, which is documented as __out_opt LPDWORD lpNumberOfBytesRead, // or __out_opt LPDWORD lpNumberOfBytesWritten, "Cool," you think. "That parameter is optional, and I can safely pass NULL." My program runs fine if standard output is a console, but if I redirect standard output, then it crashes on the Write­File call. I verified that the handle is valid. int __cdecl main(int, char **) { // error checking removed for expository purposes HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); ...

Apr 3, 2013
Post comments count 0
Post likes count 1

How can I move an HTREEITEM to a new parent?

Raymond Chen

Suppose you have a TreeView control, and you created an item in it, and you want to move the to a new parent. How do you do that? You can't, at least not all in one motion. You will have to delete the and then re-create it in its new location. If you want to move an within the same parent (say, to reorder it among its siblings), then you can use and pass a custom sort function that rearranges the children into the order you want.

Apr 2, 2013
Post comments count 0
Post likes count 1

Where did the research project RedShark get its name?

Raymond Chen

Project code names are not arrived at by teams of focus groups who carefully parse out every semantic and etymological nuance of the name they choose. (Though if you read the technology press, you'd believe otherwise, because it turns out that taking a code name apart syllable-by-syllable searching for meaning is a great way to fill column-inches.) Usually, they are just spontaneous decisions, inspired by whatever random thoughts jump to mind. Many years ago, there was an internal user interface research project code named RedShark. Not Red Shark but RedShark, accent on the Red. Where did this strange name come...

Apr 1, 2013
Post comments count 0
Post likes count 1

The joke’s on you, because PATH goes to Penn Station, not Grand Central!

Raymond Chen

I dreamed that I was asked to develop a hill-avoiding bike route from my childhood home. Along the way, I rode through a daycare playroom (twice, due to a spiral path), met Madonna, the ghost of Alec Baldwin's wife, a team from The Amazing Race trying to figure out which PATH train goes to Grand Central (trick question!) and waited for the next train with a supervillain who demonstrated his powers by using his stretchy arms to punch one of my colleagues who was standing ten feet away and who electrocuted another colleague's pacemaker by force of will. Yes, I know that Alec Baldwin is not a widower, and my colle...

Apr 1, 2013
Post comments count 0
Post likes count 2

Some trivia about the //build/ 2011 conference

Raymond Chen

Nothing important.

Mar 29, 2013
Post comments count 0
Post likes count 1

2013 Q1 link clearance: Microsoft blogger edition

Raymond Chen

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

Mar 29, 2013
Post comments count 0
Post likes count 1

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

Raymond Chen

The IMessage­Filter::Handle­Incoming­Call method describes the incoming call by means of an INTERFACE­INFO 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::Query­Interface has index zero, IUnknown::Add­Ref 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...

Mar 28, 2013
Post comments count 0
Post likes count 1

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

Raymond Chen

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...

Mar 27, 2013
Post comments count 0
Post likes count 5

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

Raymond Chen

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...