• The Old New Thing

    Disable your wireless network card to speed up VPN'ing

    • 8 Comments

    As a follow-up to my tip on speeding up connecting via RAS and a SmartCard, I've been told that another trick you can do is to disable your wireless networking card before initiating the VPN connection. Wireless networking cards are a huge attack surface, and the VPN software spends a lot of time trying to secure it.

    I don't have a wireless networking card on the machine I use at home to connect to the work network, so I haven't tried it, but who knows, maybe it'll work for you.

  • The Old New Thing

    Meet the authors: Mario Hewardt and Daniel Pravat, authors of Advanced Windows Debugging

    • 8 Comments

    My colleague Mario Hewart just let me know that he and Daniel Pravat will be presenting at the PDC pre-con. In case you don't recognize the names, they're the authors of Advanced Windows Debugging, a book which I reviewed late last year.

    So if you want to get your debugging tips directly from the source, you know where to go.

    Besides, Mario speaks Swedish, so he's already awesome by default.

    [Raymond is currently away; this message was pre-recorded.]

  • The Old New Thing

    Ah, local Los Angeles television news, how I miss thee

    • 8 Comments

    Sitting in my hotel room the night before the 2008 PDC, I'm watching the Los Angeles local news, and the field reporter just said, "The police say this is an isolated incident, but it could happen anywhere."

  • The Old New Thing

    Follow-up: That shopautodotca seocontest online contest

    • 8 Comments

    So I didn't win the shopautodotca seocontest search engine optimization contest, so I decided to check on how the actual winners were faring. After all, one of the winners was supposed to become the company's SEO manager.

    The top prize winners in the Google category and in the MSN category have both complained that they haven't received their prizes yet and have threatened to file a fraud claim. (Dead link to forum.) The top prize winner in the Yahoo category hasn't said anything one way or the other.

    Meanwhile, the forum hosted by the contest organizers was emptied of all messages, rendering it a breeding ground for message board spam. (It was subsequently taken down late last year.)

    I suspect that's the last I'll hear of this contest; I don't anticipate any resolution to emerge.

  • The Old New Thing

    You didn't know you could add properties by atom, and it's a good thing you didn't know

    • 8 Comments

    As I noted a few days ago, there is weirdness associated with properties added by atom. This weirdness stems from the fact that adding properties by atom is really a hole in the original implementation rather than something designed on purpose.

    The original 16-bit code for adding and removing properties went roughly like this:

    BOOL SetProp(HWND hwnd, LPSTR pszName, HANDLE hValue)
    {
        ... let's look only at the part that adds a new property ...
    
        ATOM atm = HIWORD(pszName) ? GlobalAddAtom(pszName) : LOWORD(pszName);
        if (atm == 0) return FALSE;
    
        ... add the atom "atm" to the property list ...
    }
    
    HANDLE RemoveProp(HWND hwnd, LPSTR pszName)
    {
        ATOM atm = HIWORD(pszName) ? GlobalFindAtom(pszName) : LOWORD(pszName);
        if (atm == 0) return NULL;
    
        ... look for the atom "atm" in the property list and remove it ...
        if (!found) return NULL;
    
        // clean up the atom
        if (HIWORD(pszName)) GlobalDeleteAtom(atm);
    }
    
    void CleanPropertiesWhenWindowIsDestroyed(HWND hwnd)
    {
        for (each property on the window) {
            if (atm >= MAXINTATOM) GlobalDeleteAtom(atm);
        }
        .. delete memory used for recording properties ...
    }
    

    First, let's look at properties set and removed via integer atoms. These are simple: When setting the property, we just add it to the property list, and when removing the property, we remove it. Nothing fancy going on here.

    Similarly, there's nothing particularly exciting going on if a property is set and removed by name. When setting the property, we use GlobalAddAtom to convert the string to an atom (incrementing the reference count), and when removing it, we use GlobalDeleteAtom to clean it up (decrementing the reference count and removing the atom if the reference count goes to zero).

    Finally, when a window is destroyed with outstanding properties, we clean them up by calling GlobalDeleteAtom on all the string atoms, counteracting the GlobalAddAtom we performed when we added the property.

    So what's the big deal? Looks great, right?

    See if you can find the hole in this implementation.

    Hint 1: There are actually three ways of adding and removing properties from a window, not the two I led you to believe.

    Hint 2: What happens if you mix and match these three methods?

    Hint 3: What happens to each of the three types of properties when the window manager is forced to clean them up?

    These problems with properties were fixed a long time ago, but old-timers remain wary of adding named properties by string atom. It's one of those superstitions.

  • The Old New Thing

    I just discovered that the Scandinavian Gift Shop in Ballard is closing

    • 8 Comments

    When in Ballard for SeafoodFest, I was saddened to discover that one of the last remaining Scandinavian businesses in Ballard, the Scandinavian Gift Shop, is closing. They were in their final stages of "everything must go!", and I picked up a small number of Glad Påsk greeting cards, some pretty napkins (including a set that would be illegal if U.S. law applied to the Swedish flag), and a dozen tiny Swedish flag stick-pins. Fortunately, Olsen's Scandinavian Foods is still there, because you never know when you're going to get a hankering for some homemade pickled herring.

    I don't get to Ballard very often during business hours, but when I do, I try to make a point of vising Olsen's just to browse around the store, amuse myself at all the Norwegian packaging (most of the stuff comes from Norway), and maybe pick up an item or two. I think the previous time I was there, one of the Endresen sisters was working the register, because she very politely translated the instructions on the back of a package of asparagus soup for me. I would have waved her off and saved her the trouble, except I didn't know what vann was. (I now know that it is vatten = water.)

  • The Old New Thing

    Volunteers help save fruit from home fruit trees from going to waste

    • 8 Comments

    It's the season where people with fruit trees in their yard are drowning in fresh fruit, be they pears, apples, plums, whatever. It's not long before you find yourself desperately looking for people to give it away to, having pretty much run out of things you can make plums into.

    This is where Community Fruit Tree Harvest steps in. (Coverage in The Seattle Times and The Seattle Post-Intelligencer. There's also Lettuce Link for donating produce from your home garden.)

    The volunteers at Community Fruit Tree Harvest will visit your house and pick the fruit from your tree, donating it to local food banks. Everybody wins: You don't have to deal with all the extra fruit, the food banks get fresh fruit, nothing goes to waste. (This is one of those "Why didn't somebody think of this sooner?" type of programs.) Contact telephone numbers are on the web pages. It appears that they currently cover the Wallingford, Phinney Ridge, and Green Lake neighborhoods.

  • The Old New Thing

    The Minimalist Jukebox Festival

    • 8 Comments

    Last year, NPR covered The Minimalist Jukebox Festival, a week-long exploration of the school of minimalist music. The NPR story includes a clip of my favorite minimalist work: Music for 18 Musicians, as well as a telling of the classic minimalism knock-knock joke.

    I remember reading somewhere that the world premiere of Music for 18 Musicians was performed by an ensemble of only seventeen musicians by doubling up a vocalist with an instrumental line. This was done to reduce the cost of travel. If true, it would make for another one of those "Unfair trivia questions" like "How many years did the Hundred Years' War last?"

    One last story about 18 Musicians before I let you go. One of the managers in my group needed an audio CD to demonstrate some feature or other, so he came into my office and borrowed my copy of 18 Musicians, unaware of what lay in store. When he returned the CD afterwards, he told me that when he popped in the CD, he thought it was skipping, since the opening of the piece consists of a single note repeated. That's what you get when you borrow a CD of minimalism...

  • The Old New Thing

    The Acorn Wand, key to a magical puzzle hunt

    • 8 Comments

    Puzzle hunts are a popular pastime at Microsoft. For the Microsoft Intern Puzzleday 2007, the puzzle design team decided upon a Harry Potter theme. Competitors ("students") formed teams ("study groups") as they attended classes at the Hogwarts campus at Microsoft. Of course, since this is Harry Potter, you need a magic wand, so the puzzle design team made a bunch of functional magic wands.

    Some members of the puzzle design team had attended Hogwarts and the Draconian Prophecy and came back raving about these amazing magic wands. The wand designer (who goes by the name Acorn) advised the puzzle design team on how to build their own wands, and they ordered custom circuit boards, soldered the components, assembled the plastic enclosures, and programmed the wands to recognize the puzzle spells.

    Solving each puzzle revealed a spell in the form of a series of wand motions. The wand itself contained an accelererometer and supporting firmware to recognize the motions and determine which (if any) spell was cast. After performing a spell, you shook the wand back and forth, and the persistence of vision effect permitted the wand to display a short message. (As an added bonus, the puzzle design team added a lumos spell which lit the tip of the wand for 30 seconds.)

    Pretty neat if you ask me.

  • The Old New Thing

    Why do we even have the DefWindowProc function?

    • 8 Comments

    Some time ago, I looked at two ways of reimplementing the dialog procedure (method 1, method 2). Commenter "8" wondered why we have a DefWindowProc function at all. Couldn't window procedures have followed the dialog box model, where they simply return FALSE to indicate that they want default processing to occur? Then there would be no need to export the DefWindowProc function.

    This overlooks one key pattern for derived classes: Using the base class as a subroutine. That pattern is what prompted people to ask for dialog procedures that acted like window procedures. If you use the "Return FALSE to get default behavior" pattern, window procedures would go something like this:

    BOOL DialogLikeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
     switch (uMsg) {
     ... handle messages and return TRUE ...
     }
     // We didn't have any special processing; do the default thing
     return FALSE;
    }
    

    Similarly, subclassing in this hypothetical world would go like this:

    BOOL DialogLikeSubclass(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
     switch (uMsg) {
     ... handle messages and return TRUE ...
     }
     // We didn't have any special processing; let the base class try
     CallDialogLikeWindowProc(PrevDialogLikeWndProc, hwnd, uMsg, wParam, lParam);
    }
    

    This works as long as what you want to do is override the base class behavior entirely. But what if you just want to augment it? Calling the previous window procedure is analogous to calling the base class implementation from a derived class, and doing so is quite common in object-oriented programming, where you want the derived class to behave "mostly" like the base class. Consider, for example, the case where we want to allow the user to drag a window by grabbing anywhere in the client area:

    LRESULT CALLBACK CaptionDragWndProc(
        HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
     LRESULT lres;
    
     switch (uMsg) {
     case WM_NCHITTEST:
      lres = DefWindowProc(hwnd, uMsg, wParam, lParam);
      if (lres == HTCLIENT) lres = HTCAPTION;
      return lres;
     ...
     }
     return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
    

    We want our hit-testing to behave just like normal, with the only exception that clicks in the client area should be treated as clicks on the caption. With the DefWindowProc model, we can do this by calling DefWindowProc to do the default processing, and then modifying the result on the back end. If we had use the dialog-box-like model, there would have been no way to call the "default handler" as a subroutine in order to make it to the heavy lifting. We would be forced to do all the work or none of it.

    Another avenue that an explicit DefWindowProc function opens up is modifying messages before they reach the default handler. For example, suppose you have a read-only edit control, but you want it to look like a normal edit control instead of getting the static look. You can do this by modifying the message that you pass to DefWindowProc:

    ...
     case WM_CTLCOLORSTATIC:
      if (GET_WM_CTLCOLOR_HWND(wParam, lParam) == m_hwndEdit)
      {
       // give it the "edit" look
       return DefWindowProc(hwnd, WM_CTLCOLOREDIT, wParam, lParam);
      }
      ...
    

    Another common operation is changing one color attribute of an edit control while leaving the others intact. For this, you can use DefWindowProc as a subroutine and then tweak the one attribute you want to customize.

     case WM_CTLCOLORSTATIC:
      if (GET_WM_CTLCOLOR_HWND(wParam, lParam) == m_hwndDanger)
      {
       // Start with the default color attributes
       LRESULT lres = DefWindowProc(hwnd, uMsg, wParam, lParam);
       // Change text color to red; leave everything else the same
       SetTextColor(GET_WM_CTLCOLOR_HDC(wParam, lParam), RGB(255,0,0));
       return lres;
      }
      ...
    

    Getting these types of operations to work with the dialog box model would be a significantly trickier undertaking.

Page 377 of 444 (4,431 items) «375376377378379»