March, 2009

  • The Old New Thing

    Sometimes people don't even read what they're typing


    As an even more extreme case of people seeing something, confirming that they see it, but not actually reading it is someone who sees something, types it into an email message, yet still doesn't read it.

    Subject: "Invoke or BeginInvoke cannot be called on a control until the window handle has been created." exception crashes our program

    I'm looking for guidance on why this exception is thrown and how I can avoid it. Here's a sketch of what we're doing:

    void DoStuff() {                                                              
      try {                
        // attempt operation X, which throws an exception when it fails
      } catch {                
        this.BeginInvoke(new ShowErrorDelegate(this.OnShowError), null);

    If operation X fails, the catch clause runs, but it throws the exception "Invoke or BeginInvoke cannot be called on a control until the window handle has been created." Why is it happening? It's crashing our program. Right now, we're working around it by wrapping the BeginInvoke inside its own try/catch, but we'd like to understand why the exception is occurring in the first place and how we can avoid it.

    Now, I don't know much about WinForms, so I could be way off base here, but perhaps the problem is that you're calling BeginInvoke on a control before its window handle has been created. I'm just basing that on the text that you typed into the subject line and again into the message text. The workaround therefore is to make sure the window handle has been created before calling BeginInvoke. (You can imagine any number of ways of ensuring this.)

    Though I do admire the approach of "We don't know what's going on, so we'll just wrap it inside an exception handler and pretend it didn't happen."

  • The Old New Thing

    The house no-electronics zone


    In my house, I have designated two rooms as the no-electronics zone. No use of electronic gadgets is allowed. No television, laptops, PDAs, cell phones, handheld video games, you get the idea. The purpose of this section of the house is to interact with other people face-to-face.

    Now, exceptions have been made for extenuating circumstances. For example, when some of my friends were without electricity due to a power outage, I invited them to my house, and they were permitted to use their laptops in what would normally be the no-electronics zone.

    But those are the exceptions. So if you come to my house, remember: The living room and dining room form a no-electronics zone.

    [Update 1pm] Return of the nitpicker's corner: Once again, people get distracted by the minutiae and miss the point of the rule. The purpose of the rule is to encourage face-to-face interaction and to discourage activities which cause people to withdraw from each other.

    By electronic devices, I mean televisions, laptops, PDAs, cell phones, handheld video games, you get the idea. Digital watches, clocks, and lamps are acceptable, provided they do not prevent you from interacting with others. Checking the time is okay; playing Space Invaders on your digital watch is not. Digital cameras are acceptable if they are being used to take or share pictures. But sitting there sifting through pictures without talking to anyone is not.

    If Professor Stephen Hawking comes to visit, his electronic devices are being used to interact with other people and are therefore acceptable.

    I didn't feel the need to apply these common-sense rules to the basic principle, assuming that my readers understood the point I was making and didn't need a legalistic breakdown of what is and is not acceptable.

  • The Old New Thing

    Why don't the favorites I copy into the common Favorites directory show up in the Favorites menu of all users?


    The Favorites menu in Internet Explorer shows the user's favorites. And stuff in the %ALLUSERSPROFILE% is visible to all users. Therefore, Internet shortcuts placed into the %ALLUSERSPROFILE%\Favorites directory should show up on the Favorites menu of all users, right? So why doesn't it work?

    Because features don't exist by default.

    It's true that there are a few highly-visible cases where the items shown to the user are a combination of files from the %USERPROFILE% and the %ALLUSERSPROFILE%, the most commonly encountered ones being the desktop and the Start menu. But that doesn't happy as a result of magic. Somebody had to sit down and hook them up.

    Even the highly visible cases show that the behavior is implemented on a case-by-case basis. For example, the Music folder does not show the items in the all-users version of the Music directory; there is just a shortcut that takes you there. Similarly, items in the all-users Documents folder do not show up in every user's Documents folder; instead there is a separate Shared Documents folder.

    Each of those cases had to be hooked up separately, and most of them are not hooked up at all.

    Now, the common Favorites folder may be a tempting target, seeing as the shell team even defined a CSIDL value for it, but it's just another example of something that never got hooked up but whose vestiges didn't get completely cleaned up either.

  • The Old New Thing

    Totally Recall: The meal


    At lunch, we got the crazy idea of putting together a meal menu consisting entirely of foods which had been the subject of highly-publicized product recalls. And of course, we gave it a name consisting of a really bad pun: Totally Recall.


    Green leaf lettuce with tomatoes, green onions, and jalapeno peppers.

    Main course

    Swimming Rama: Spinach with peanut sauce and stir-fried beef.


    Odwalla juice.


    ? Suggestions welcome. (White Rabbit candies?)

    And if you don't like this meal, you can just go to the Jack in the Box restaurant down the street.

  • The Old New Thing

    Why doesn't the MoveWindow function generate the WM_GETMINMAXINFO message?


    Commenter Phil Quirk asks why calling MoveWindow does not result in a WM_GETMINMAXINFO message being sent to validate the moved window size.

    Well, because you moved it after all. You're being trusted to respect your own rules. After all, if you didn't want the window to be wider than 200 pixels, you shouldn't have passed nWidth=300, right?

    The WM_GETMINMAXINFO message is for obtaining minimum and maximum sizing information when the sizes were chosen by a means outside the application's control, such as when you said "I'll let you choose the window size (CW_USEDEFAULT)" or when the user grabbed the corner of the window and started dragging it around. But if you yourself changed the window size, then the window manager assumes that you know what you're doing.

    If you don't trust yourself to follow your own rules, you can intercept the attempt to change the window size by handling the WM_WINDOWPOSCHANGING message.

  • The Old New Thing

    Why is the Win32 epoch January 1, 1601?


    Public Service Announcement: This weekend marks the start of Daylight Saving Time in most parts of the United States.

    The FILETIME structure records time in the form of 100-nanosecond intervals since January 1, 1601. Why was that date chosen?

    The Gregorian calendar operates on a 400-year cycle, and 1601 is the first year of the cycle that was active at the time Windows NT was being designed. In other words, it was chosen to make the math come out nicely.

    I actually have the email from Dave Cutler confirming this.

  • The Old New Thing

    Race you to the top: The Empire State Building Run-Up


    The winner completes the race in just ten minutes and seven seconds, but the vertical climb is a killer: Straight up the 1576 steps of the Empire State Building to the Observation deck. (When I visit the Observation Deck of the Empire State Building, I use the elevator.)

    And when it's over, everybody goes to work.

    What else am I going to do, like go celebrate? Am I going to go have martinis at 11:30 in the morning? No, you slink into work and you sit at your desk, and you work all day, and when you're done you stand up and your back is stiff, and you call your wife, and you get yelled at, and you go home to your three kids. Just like another day.
  • The Old New Thing

    Fixups are not the same as rewriting code, they're just fixups


    Classically speaking, a linker cannot rewrite the code the compiler generated; its job is merely to resolve symbols. Of course, resolving symbols means that references to those symbols in the code generated by the compiler turn from "I don't know" to "Here it is." Somebody named George appeared to be confused by this, believing that all changes by the linker counted as "rewriting code."

    Obviously if the linker weren't allowed to change anything at all, there wouldn't be much point to having a linker. For example, you wouldn't be able to access functions or variables in a separate compilation unit (for example, from a library) because the compiler doesn't know what the final address is; that's what the linker is supposed to figure out. (Indeed, if function-level linking is enabled, then even calls within a compilation unit are left as insert address here.) The linker resolves symbols and patches up code references that used to say insert address here so that they contain the actual address.

    I think George took my statement a bit too literally. The linker can't change a direct call to an indirect call; that's not something that the compiler told the linker how to do. All the linker can do is patch up insert address here fixups. It can't say "Oh, I'm going to take your two mov instructions and reverse the destination registers, and then flip the arguments to the subsequent sub instruction." (I'm talking about classical linking; the introduction of link-time code generation further blurs the line between the compiler and the linker.)

    George also made the common mistake not only of calling this Web site a "document from MSDN" but also applying the same description to a Microsoft Systems Journal article from 1997. The back issues of MSJ are included in MSDN as a courtesy. Neither the back issues nor the contents of this Web site are under MSDN editorial control.

  • The Old New Thing

    Microspeak: Year-over-year


    In economics, the attributive adjective year-over-year means compared to the same time last year. Examples: "Year-over-year sales show a marked improvement." "Expenses continue to fall year over year." (The hyphens disappear when the adjective is used predicatively.)

    I have only one citation, but it appears that the term has broadened its meaning inside Microsoft and is now merely a synonym for annual or year after year.

    We hold decision-makers accountable year over year for carrying out their plan.

    There is no obvious compared to the same time last year going on here. It's not like you are 15% more accountable this year than you were last year. Rather, the sentence merely says that reviewing how well the decision-makers are carrying out the plan takes place every year. (It may not be clear from the sentence above that that's what the sentence means, but it's clearer in the context of the entire document from which the sentence was extracted.)

  • The Old New Thing

    If Twitter is micro-blogging, then is what I'm doing macro-tweeting?


    Here are a collection of brief messages not worthy of a full blog entry. I think I'm going to call it macro-tweeting.

    • Went to pick up my new suit, only to discover that instead of altering it, the store returned the suit to inventory.
      • @raymond: Customer service fail!
      • @raymond: Hey, at least they didn't charge you a restocking fee!
      • @ian: Got re-fitted. Clerk: "How do I ring this up?" Salesman: "You don't. He already paid for it."
    • Silver lining: Found my long-lost camera recharger while organizing documents for my IRS compliance examination.
    • Current record against Chilly Hilly: 2 wins, 1 loss.
    • Learned another Chinese word. Only 2960 to go. Should be ready for basic conversation around 2097.
    • Unpacking a blender.
      • @raymond: Makin' smoothies, eh?
    • Less impressed with friend's 10,000-BTU hotpot burner, now that I found the sticker on my own El Lame-O burner that reads 9,925.
    • Got schooled in dumpling-making.
    • If, at the dinner table, a four-year-old offers to play the game Guess what's in my mouth, you should decline.

Page 3 of 4 (33 items) 1234