The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Programmatically controlling which handles are inherited by new processes in Win32
Dec 16, 2011
Post comments count 0
Post likes count 1

Programmatically controlling which handles are inherited by new processes in Win32

Raymond Chen
Raymond Chen

In unix, file descriptors are inherited by child processes by default. This wasn't so much an active decision as it was a consequence of the fork/exec model. To exclude a file descriptor from being inherited by children, you set the flag on the file descriptor. Win32 sort of works like that, but backwards, and maybe a little upside-down. And in high heels. In Win32, handles default to not inherited. Ways to make a handle inherited during have grown during the evolution of Win32. As far as I can tell, back in the old days, inheritability of handles was established at handle creation time. For most handle...

Not even making it to the airtight hatchway: Execution even before you get there
Dec 15, 2011
Post comments count 0
Post likes count 0

Not even making it to the airtight hatchway: Execution even before you get there

Raymond Chen
Raymond Chen

Today's dubious security vulnerability comes from somebody who reported that the function had a security vulnerability which could lead to arbitrary code execution. This is a serious issue, but reading the report made us wonder if something was missing. According to the report, this sample program illustrates that the function will execute whatever you pass as its second parameter. In this case, the program chose to launch Notepad, but obviously an attacker could change the code to something more dangerous. We had trouble trying to figure out what the person was trying to say. After all, it's not the fun...

The peculiar cadence of executive mail messages
Dec 14, 2011
Post comments count 0
Post likes count 0

The peculiar cadence of executive mail messages

Raymond Chen
Raymond Chen

They follow a pattern that appears to be designed to hide information.

Online gift ordering + enthusiastic kids at the keyboard + Unicode, wait… Unicode?
Dec 13, 2011
Post comments count 0
Post likes count 0

Online gift ordering + enthusiastic kids at the keyboard + Unicode, wait… Unicode?

Raymond Chen
Raymond Chen

I was completing an online gift order for my young nephew's birthday, and I was in the middle of typing Happy birthday into the gift card message when an enthusiastic child reached for the keyboard and held down the "a" key as I typed the final "a" in "birthday". I wanted to capture the spontaneous enthusiasm in the gift tag, but I had no idea what font or format rectangle was going to be used, so I couldn't be sure where to put hyphens so that they will ensure line breaks at visually-pleasing locations. And if I didn't insert hyphens at all, then the line would just run off the end of the gift tag and end up t...

What is the API for accessing content on SkyDrive?
Dec 12, 2011
Post comments count 0
Post likes count 0

What is the API for accessing content on SkyDrive?

Raymond Chen
Raymond Chen

The last time I mentioned programmatic access to SkyDrive was last June, where I noted that the interface was given the confusing name Messenger Connect. At least now they renamed it to Live Connect, which is slightly less confusing. The SkyDrive folks have been pretty busy lately. A few days ago, Dare Obasanjo announced a new Live Connect SDK, which means that you now have even more ways of accessing your SkyDrive content programmatically. (I like how the block diagram screen shot still has the red underline squiggles under the word skydrive.) Check it out at the Live Connect Developer Center. You can wat...

How can I tell whether a window is modal?
Dec 12, 2011
Post comments count 0
Post likes count 0

How can I tell whether a window is modal?

Raymond Chen
Raymond Chen

A customer wanted a way to determine whether a particular window is modal. They listed a few methods they had tried but found that it didn't work and asked for assistance. As Eric Lippert is fond of saying, "First, write your spec." Until you know what you want, you won't know how to get it. First, you need to define what you mean by a modal window. There are multiple competing definitions. The customer decided that the definition of modal window they want is this one: A modal window is a child window that requires the user to interact with it before they can return to operating the parent application, ...

Sure, I'm supposed to pass WT_EXECUTELONGFUNCTION if my function takes a long time, but how long is long?
Dec 9, 2011
Post comments count 0
Post likes count 1

Sure, I'm supposed to pass WT_EXECUTELONGFUNCTION if my function takes a long time, but how long is long?

Raymond Chen
Raymond Chen

A customer contacted me to tell a story and ask a question. The customer discovered that in their code base, all calls to passed the flag, regardless of whether the function actually took a long time or not. Their program creates a large number of work items at startup, and the result of passing for all of them was that the thread pool created a new thread for each queued work item, resulting in a bloated thread pool that thrashed the CPU. When he asked the other people on his team why they were passing the flag unconditionally, they pointed to this article from 2005 on the importance of passing the flag t...

What does it mean when my program exits with the message "This application has requested the Runtime to terminate it in an unusual way"?
Dec 8, 2011
Post comments count 0
Post likes count 0

What does it mean when my program exits with the message "This application has requested the Runtime to terminate it in an unusual way"?

Raymond Chen
Raymond Chen

You're running your program, and then it suddenly exits with the message This application has requested the Runtime to terminate it in an unusual way. What happened? That message is printed by the C runtime function , the same function that also causes your program to terminate with exit code 3. Your program might call explicitly, or it might end up being called implicitly by the runtime library itself. The C++ standard spells out the conditions under which is called, and it's quite a long list, so I won't bother repeating them here. Consult your favorite copy of the C++ standard for details. (The mo...

GetParent, just as confusing as EnumClaw, but it's an actual function!
Dec 7, 2011
Post comments count 0
Post likes count 0

GetParent, just as confusing as EnumClaw, but it's an actual function!

Raymond Chen
Raymond Chen

The function , documented as returning "the child or the parent of the window", was a joke, but there's a function whose behavior is just as confusing as the joke function : . The function returns the parent window, or owner window, or possibly neither. All that's left is for it to be a floor wax and it'll have everything covered. The idea behind is that it returns the parent window. Only child windows have parents, so what happens if you pass something that isn't a child window? Well, we shouldn't let a parameter go to waste, right? So let's have it return the owner window if you pass in a top-level window....