The Old New Thing

What is the format of a double-null-terminated string with no strings?

One of the data formats peculiar to Windows is the double-null-terminated string. If you have a bunch of strings and you want to build one of these elusive double-null-terminated strings out of it, it's no big deal. But what about the edge cases? What if you want to build a double-null-terminated string with no strings? Let's step back ...

The ways people mess up IUnknown::QueryInterface, episode 3

Today we'll combine information you already know, some of which I covered in The ways people mess up IUnknown::QueryInterface with additional clues from The layout of a COM object. There's still not enough information for you to solve the problem entirely on your own, but maybe you can demonstrate your nascent psychic debugging powers and ...

Why do messages posted by PostThreadMessage disappear?

The only thread message you can meaningfully post to a thread displaying UI is , and even then, it's only because you want to wake up the message loop for some reason. A common problem I see is people who use to talk to a thread that is displaying UI and then wonder why the message never arrives. Oh, the message arrived all right. It ...

The ways people mess up IUnknown::QueryInterface, episode 2

Sadly, I get to add another entry to The ways people mess up : Blindly responding to everything. Some people are just too eager to please. No matter what the interface is, they say, "Sure, we do that!" Furthermore, no matter what you ask for, they always return the same interface. Even if it's not what you asked for. Exercise: ...

The COM marshaller uses the COM task allocator to allocate and free memory

It should be second nature to you that the code which allocates memory and the code which frees memory need to use the same allocator. Most of the time, you think of it as "If you allocate memory, you need to free it with the corresponding mechanism," but this sentence works in the reverse direction as well: If you hand memory to a function ...

What is the logic behind the thumb size and position calculation in scroll bars?

Commenter sarathc asks, "How do we implement a custom scroll bar as Windows does? What is the logic behind the thumb size and position calculation? How we could dynamically manage it?" Let's look at the three questions in turn. To implement a custom scroll bar... don't do it. It's just not worth the effort, and there will almost always be ...

Can you create an information context for the display?

Adrian McCarthy asks, "Can you create an information context for the display? ... I can call CreateDC("DISPLAY"), but perhaps that wouldn't generalize for a multiple-monitor display with different settings on each screen. I'm trying to avoid constantly creating and destroying DCs when all I need to do is measure strings, check color depth, dpi...