• The Old New Thing

    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.

    dwUniqueId = InterlockedCompareExchange(&g_dwUniqueId, 

    Criticize this code fragment.

  • The Old New Thing

    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 any version of the .NET Framework. Windows Vista came with version 2, and Windows 7 came with version 3.5, but these were provided as optional components which were installed by default. You can go into the Programs and Features control panel to remove them.

    As I recall, the application compatibility folks have a list of programs that treated Windows as a .NET Framework delivery channel; if you install any of them, and the version of the .NET Framework they depend on isn't installed, the application compatibility layer will display the informational message that the application neglected to.

    Bonus chatter: These programs which treated Windows as a .NET Framework delivery channel may have been misled by charts like this one or lists like this one which give the impression that Windows is a .NET Framework delivery channel.

  • The Old New Thing

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

    When I told this joke, she fell on the floor in uncontrollable laughter. I had a winner.

  • The Old New Thing

    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 the following complaint. Yes, this is verbatim (and specifically in reference to the default profile):

    I am very offended that this is type of code is allowed to leave microsoft. I am seriously considering dropping my subscription to MSN. I don't get this kind of crap from CompuServe, and I can get comparable Internet access from a local ISP. I can see that there is a serious lack of customer respect at microsoft and this is probably just the tip of the iceberg.

    MSN was pretty conservative, at least at the time, and this caused a big headache for the team. How dare we insult our customers! Did the project not have enough management overhead? Can we make things any more difficult for the small team? Yes we can! As a result, we were required to remove the message from the 2.1 release. It became "This user has no profile." at least in the version that was released on the MSN CD-ROM.

    Meanwhile, we got some advanced notice about an upcoming PC World review of the 2.0 version that had included the original message. The summary (which was emailed to us), said: "She [the reviewer] praises Microsoft for finally having a sense of humor (loves the note about being 'too lazy to have a bio' message). She claims Comic Chat is an absolute delight."

    I love the part about MS finally having a sense of humor. Well at least we were allowed to add back the message for the 2.5 release!

    Check out DJ's history of Comic Chat, which includes links to videos and other time-wasty goodness.

    Bonus chatter: DJ also has a page on Peedy the Parrot, a research project to develop a more natural user interface. Out in the product groups, we just called it that stupid parrot demo because it became tiresome from overexposure, having been used in a CES keynote and multiple company meetings.

  • The Old New Thing

    2011 Q1 link clearance: Microsoft blogger edition


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

  • The Old New Thing

    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 SetForegroundWindow(hwndB) 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 WM_ACTIVATE(FALSE) notifications on hwndSecondProcess, and if the window that took focus from us is the one from the first process, then take it back with SetForegroundWindow(hwndSecondProcess).

    But then we wondered, since we disabled window A, will it even get the normal activation message?

    Since the window is disabled, it will not receive activation messages because disabled windows cannot be activated. So no, this solution won't work.

    The subject line of the question, however, gave the answer without even realizing it. The subject was Out-of-proc pseudo-parent/child window relationship. (Well, okay, the subject line confused parent/child with owner/owned, but that's a common source of sloppiness when talking about the relationship among windows.)

    Instead of having a pseudo-owner/owned window relationship, just have a real one. Why fake it when you can get the real thing?

    When you call DialogBox in process B, pass hwndA as the owner window. Now the two windows have a genuine owner/owned relationship, along with the standard behaviors that come with it. It's legal to have an owner/owned relationship that crosses process boundaries. Note that when you do this, it attaches the two threads' input queues so you have to be careful if both windows process input at the same time. Fortunately, in the modal dialog case, only one of the windows accepts input at a time, so the scariest part of attached input queues doesn't apply.

  • The Old New Thing

    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 grateful for the pointers, then asked:

    Then the only way to do this is to load the dialog resource and parse the data looking for the string I want? Is it even possible to do this in C#?

    Well it depends on what your definition of "the only way" is.

    At the end of the day, somebody has to load the dialog resource and parse it, because after all that is what you said you want to do: "I want to get the title of the dialog from the dialog resource." The alternative is, what, psychic powers?

    There is no dialog template parsing library that comes with Win32. If you don't want to do the parsing, then maybe you can find somebody else who will. And if you're lucky, that other person may even have provided a C# interface.

  • The Old New Thing

    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 customer doesn't want to stop Explorer from querying the shortcut information; the customer just wants to stop Explorer from contacting the server to get the icon.

    The default icon for a shortcut is the icon of the target, and in order to get that icon, Explorer needs to contact the target. But you can override that default. Programmatically, you call IShellLink::SetIconLocation; interactively, you view the shortcut's properties and click Change Icon.... In either case, set it to an icon that doesn't reside on the server. Save the changes and deploy the modified shortcut.

  • The Old New Thing

    Why did Win32 define BOOL as a signed int instead of an unsigned int?


    Igor Levicki wants somebody from Microsoft to explain why BOOL was defined as a signed int instead of an unsigned int.

    You don't need to work for Microsoft to figure this out. All the information you need is publically available.

    Quoting from K&R Classic, which was the operative C standards document at the time Windows was being developed:

    7.6 Relational Operators

    The [relational operators] all yield 0 if the specified relation is false and 1 if it is true. The type of the result is int.

    Win32 defined BOOL as synonymous with int because Brian and Dennis said so. If you want to know why Brian and Dennis decided to have the result of relational operators be signed instead of unsigned, you'll have to ask them.

  • The Old New Thing

    Paul Cézanne and Camille Saint-Saëns may have similar-sounding last names, but they are not the same person


    Next week, the Seattle Symphony Orchestra performs the Saint-Saëns Organ Symphony, but the people responsible for the symphony's radio advertisements don't realize that.

    As the strains of the symphony resound in the background, the announcer proudly announces that tickets are still available for "Cézanne's Organ Symphony."

    The names Cézanne and Saint-Saëns may sound similar, but I can assure you that they are not the same person. Here's a handy chart:

    Cézanne Saint-Saëns
    French X X
    Born in 1830's X X
    Master painter X  
    Master composer   X
    Carnival X  
    The Carnival of the Animals   X
    Died of pneumonia X X

    This is not the first time the Seattle Symphony's radio announcer has made this substitution. I don't know whether somebody is giving him incorrect copy to read, or whether he is performing on-the-fly auto-correction. Or maybe the announcer guy asked, "How do you pronounce Saint-Saëns?" and somebody answered, "It sounds like Cézanne."

    And now that I cleared everything up, let me confuse things some more:

Page 122 of 441 (4,410 items) «120121122123124»