October 7th, 2010

Why does TaskDialog return immediately without showing a dialog?

A customer reported a problem with the Task­Dialog function.

We’ve encountered a strange behavior in the Task­Dialog function. A user reported that when exiting our application, our program played an error beep that didn’t appear to be associated with an error. After investigating, we found that the sound is coming from our application trying to display an error dialog before closing by calling Task­Dialog. The error beep is played but no dialog appears.

Some background on the error condition that we’re trying to report: We’re calling Create­Window­Ex, and the window procedure creates another window in its WM_CREATE handler. It looks like the original window is destroyed before WM_CREATE is finished, so Create­Window­Ex returns ERROR_INVALID_WINDOW_HANDLE. It’s not clear why this is causing Task­Dialog to fail, but this is the only scenario where we see this behavior. All other calls to Task­Dialog work as expected. We know how to fix the original problem with Create­Window­Ex, but we would like to understand what’s going on with Task­Dialog in case there’s another bug here.

With a little bit of psychic powers, you can solve this customer’s problem too.

(If you have a good memory, you may have noticed that it’s a variation on a previous puzzle. But I get to keep recycling it because every year, a new batch of developers stumbles across the problem.)

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.