The Old New Thing
Practical development throughout the evolution of Windows.
Latest posts
Lock-free algorithms: The singleton constructor
The first half may be familiar to many (most?) readers, but there's an interesting exercise at the bottom. A very useful pattern for the Interlocked* functions is lock-free lazy initialization via . Yes, that's a really long function name, but it turns out every part of it important. This is a double-check lock, but without the locking. Instead of taking lock when doing the initial construction, we just let it be a free-for-all over who gets to create the object. If five threads all reach this code at the same time, sure, let's create five objects. After everybody creates what they think is the winning obje...
Lock-free algorithms: Choosing a unique value (warm-up)
Here's a snippet of code whose job is to generate a unique number within the process. Here's some reference reading to get yourself in the mood. Caution: It may or may not be useful. Criticize this code fragment.
Windows is not a .NET Framework delivery channel either
We learned a while ago that Windows is not an MFC delivery channel. And, since you asked, it's not a .NET Framework delivery channel either. If you're developing a program that uses the .NET Framework, you have to have a backup plan if the version of the .NET Framework you need is not installed on the computer. This might mean including a copy of the installer on your CD. It might mean redirecting the user to an appropriate download site. It might just mean telling the user, "This program requires version XYZ of the .NET Framework." Whatever you do, you need to do something. Windows XP didn't come with a...
The funniest joke I've ever told (to a three-year-old)
I've tested this joke on several children ages three and four, and it never fails. There were two kittens walking down the street, and one of them fell on its butt! I developed this joke for one of my honorary nieces. She had just started to learn about joke-telling and asked me to tell her a joke. One of the keys to joke-telling is to know your audience: A three-year-old won't have the attention span for a longer joke, and subtlety and observational humor won't work either. It's got to be short and direct. She thought kittens were cute, and falling on one's butt was funny, so I figured, hey, let me combine t...
The introduction of whimsical teasing in Comic Chat
A few months after my post on the sad demise of whimsical teasing in Comic Chat, I received a piece of email from none other than the author of Comic Chat, DJ Kurlander: I was the person that started the Comic Chat project in Microsoft Research and was responsible for that line, "This person is too lazy to create a profile entry." Not a whole lot of thought went into the default profile. In maybe the 30 seconds that I put into it, I thought that the line was moderately humorous, fit with the quirky nature of Comic Chat, and might motivate more people to create profiles. When we released version 2, MSN got th...
2011 Q1 link clearance: Microsoft blogger edition
It's that time again: Linking to other Microsoft bloggers.
Having an owner window from another process is tricky, but it's sometimes the right thing to do
A customer had a main program (let's call it A) and a helper program (let's call it B), and the customer wanted and wanted B to act like a modal dialog relative to A. When B is launched, we disable A's window and then call to simulate a modal dialog. How do we make sure that focus goes to B's window and not A's? We've found that if the user clicks on the (now-disabled) window from the process A, then window B loses focus. This is not the behavior from regular modal windows however: For normal modal windows, clicking on the disabled owner activates the modal popup. One idea is to watch for...
How do I get the title of a dialog from a dialog resource?
A customer submitted the following question: We are developing automated tests for our application. Among other things, our application uses property sheets, which means that the name of the tab is stored as the title of the dialog template resource. Since we want our automated tests to run on all language versions of our application, we don't want to hard-code the tab names in our automated test. I have not been able to find any information on how to programmatically extract the dialog titles from the dialog resources. Any pointers would be appreciated. I replied with some pointers: The customer was gratef...
Although the default icon for a shortcut is the icon of the target, you can override that
A customer reported that a shortcut they deployed to their employees' desktops was triggering unwanted server traffic. My customer deploys a shortcut on %ALLUSERSPROFILE%\Desktop, and this shortcut points to an EXE file on a remote server. Once a local user logs on, the computer will try logging onto the remote computer to query information and generate a login failure alert on the server. Is there any way to stop Explorer from querying the shortcut information? Fortunately, the customer provided context for the question, because the question the customer is asking doesn't actually match the scenario. The ...