• The Old New Thing

    The ways people mess up IUnknown::QueryInterface

    • 33 Comments

    When you're dealing with application compatibility, you discover all sorts of things that worked only by accident. Today, I'll talk about some of the "creative" ways people mess up the IUnknown::QueryInterface method.

    Now, you'd think, "This interface is so critical to COM, how could anybody possible mess it up?"

    Forgetting to respond to IUnknown.

    Sometimes you get so excited about responding to all these great interfaces that you forget to respond to IUnknown itself. We have found objects where

    IShellFolder *psf = some object;
    IUnknown *punk;
    psf->QueryInterface(IID_IUnknown, (void**)&punk);
    
    fails with E_NOINTERFACE!

    Forgetting to respond to your own interface.

    There are some methods which return an object with a specific interface. And if you query that object for its own interface, its sole reason for existing, it says "Huh?"

    IShellFolder *psf = some object;
    IEnumIDList *peidl, *peidl2;
    psf->EnumObjects(..., &peidl);
    peidl->QueryInterface(IID_IEnumIDList, (void**)&peidl2);
    

    There are some objects which return E_NOINTERFACE to the QueryInterface call, even though you're asking the object for itself! "Sorry, I don't exist," it seems they're trying to say.

    Forgetting to respond to base interfaces.

    When you implement a derived interface, you implicitly implement the base interfaces, so don't forget to respond to them, too.

    IShellView *psv = some object;
    IOleView *pow;
    psv->QueryInterface(IID_IOleView, (void**)&pow);
    
    Some objects forget and the QueryInterface fails with E_NOINTERFACE.

    Requiring a secret knock.

    In principle, the following two code fragments are equivalent:

    IShellFolder *psf;
    IUnknown *punk;
    CoCreateInstance(CLSID_xyz, ..., IID_IShellFolder, (void**)&psf);
    psf->QueryInterface(IID_IUnknown, (void**)&punk);
    
    CoCreateInstance(CLSID_xyz, ..., IID_IUnknown, (void**)&punk);
    punk->QueryInterface(IID_IShellFolder, (void**)&psf);
    

    In reality, some implementations mess up and fail the second call to CoCreateInstance. The only way to create the object successfully is to create it with the IShellFolder interface.

    Forgetting to say "no" properly.

    One of the rules for saying "no" is that you have to set the output pointer to NULL before returning. Some people forget to do that.

    IMumble *pmbl;
    punk->QueryInterface(IID_IMumble, (void**)&pmbl);
    

    If the QueryInterface succeeds, then pmbl must be non-NULL on return. If it fails, then pmbl must be NULL on return.

    The shell has to be compatible with all these buggy objects because if it weren't, customers would get upset and the press would have a field day. Some of the offenders are big-name programs. If they broke, people would report, "Don't upgrade to Windows XYZ, it's not compatible with <big-name program>." Conspiracy-minded folks would shout, "Microsoft intentionally broke <big-name program>! Proof of unfair business tactics!"

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

  • The Old New Thing

    Yahoo's privacy policy regarding web bugs

    • 10 Comments

    Here's Yahoo's privacy policy regarding so-called web bugs (or as they call them "web beacons") - these are the little 1x1 images that web sites use to keep track of where you're going.

    Halfway down the page (at least as of the time I wrote this, which is not the same as the time this gets posted since I write stuff in advance...) in the section "Outside the Yahoo! Network" there is a link to opt out of sharing the information with companies outside the Yahoo! Network.

    Maybe it's time to start surfing with images off again, or perhaps somebody can write a plug-in that blocks all 1x1 images.

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

  • The Old New Thing

    Swedish spicy food

    • 3 Comments

    My friend Jonathan is acting as my host in Uppsala, and he was responsible for preparing dinner for a staff party at his nation. He chose curry. The same thing he chose the last time he was responsible for preparing dinner for a party.

    The last time, one of the attendees ceremonially dumped the curry into the trash because it was "inedible". Translation: Too spicy.

    So this time he tried to tone it down. But by the time it came to taste-test the curry, it was already too hot. (Not hot at all by Thai standards. But this is Sweden we're talking about.)

    But apparently this time the Swedes have become accustomed to slightly spicier food because nobody complained.

    At this party there was a lot of singing (from the official club song book), banging on tables, and lots and lots of drinking. Beer, wine, sangria, schnapps, whatever. Some of the students from the U.S. taught the Swedes how to play paddle-less beer pong, which was a hit because, well, it involves drinking.

    College students + alcohol + Sweden. You do the math.

  • The Old New Thing

    URLs too small? Here comes hugeurl.com

    • 7 Comments

    Sure, everybody knows about little tinyurl.com, handing out short URLs for large unwieldy ones.

    But nobody pays any attention to tinyurl.com's arch-nemesis: www.hugeurl.com, or as they like to call themselves,
    http://www.hugeurl.com/?ZWY3ZTE0NWFmOTg5ZDU2M2QxYWI3ZTNhMGJj
    ZjlhNGMmMTImVm0wd2QyUXlVW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xUXhXWGhqUld4VllrWmFjRlpxVG05a2JGcEhW
    bTA1VWsxWFVucFdNV2h2V1ZaS1JsTnRSbGRpV0U0MFZHdGFXbVZIUmtoUFYy
    aHBVbGhCZDFac1pEUmpNV1IwVTJ0b2FGSnNTbGhVVmxwM1YwWnJlRmRyZEd0
    U2EzQjZWa2R6TVZZeVNsbFpNMmhYVFc1b1dGWnFSbEpsUm1SWldrVTFXRkpZ
    UWxsWFZtUjZUVlpzVjFWc1dsaGliVkpZVlcxNGQyVkdWblJOVldSWFRVUkdl
    VlJzVm05V01VbzJVbXRvVjFaRldreFdha3BQVW14YWMxcEhiRk5OVlZZelZt
    eGFVMUl4YkZkWGJrcE9WbXh3V0ZsWWNGZFdSbFp5Vm10YVQxVlVNRGs9
    .

    "Enlarge your URLs without a prescription."

    Via Techdirt.

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

  • The Old New Thing

    Regular expressions and the dreaded *? operator

    • 10 Comments

    The regular expression *? operator means "Match as few characters as necessary to make this pattern succeed." But look at what happens when you mix it up a bit:

    ".*?"

    This pattern matches a quoted string containing no embedded quotes. This works because the first quotation mark starts the string, the .*? gobbles up everything in between, and then the second quotation mark eats the close-quote.

    (Note how this differs from ".*", which uses a greedy match. This time, the .* operator is perfectly happy to gobble up quotation marks, as long as it leaves one to match the second quotation mark in the pattern.)

    Okay, great, now let's make a small change to the above pattern:

    ".*?">

    All I did was stick a > at the end of the pattern. This would therefore match a quoted string (containing no quotation marks) followed by a > character, right?

    Wrong.

    There's nothing in .*? that says "no quotation marks allowed". It just says "Don't match more than you need to." But there are strings where it needs to match a quotation mark. Consider:

    " hello"world " >
    " .*? " >

    Notice that here, the .*? pattern matched the inner quotation mark because that was the only way to make the pattern match successfully. ("I wouldn't have done it, but you forced me!")

    Even smart people make this mistake.

    If you really don't want quotation marks to match the .*? then you need to say so.

    "[^"]*">

    This means "Match a quotation mark, then zero or more characters that aren't quotation marks, then another quotation mark, and then a greater-than."

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

  • The Old New Thing

    The SAS in-flight safety video

    • 13 Comments

    Each time I see the SAS in-flight safety video, I am amused by the story they tell about each of their "characters".

    The safety video features four groups of travellers, a man and a young girl, a retired couple, a (very Scandinavian-looking) businesswoman, and a (vaguely Hispanic) young man.

    Each procedure is illustrated one of the four travelling groups. How to buckle your seat belt is illustrated by the man and young girl; the girl can't figure out how the buckle works. (Unbuckling is demonstrated by the retired gentleman.)

    When it's time to turn off electronic devices, a flight attendant politely asks the businesswoman to put away her laptop computer.

    When passengers are reminded that smoking is not permitted, the single guy frustratedly puts his pack of cigarettes away.

    The retired gentleman has to be reminded to return his seat to the upright position.

    The young girl takes a look at the flight safety summary card, but holds it upside-down.

    Okay, so what have we learned: Young girls are unbelievably stupid. I mean, sure maybe she's too young to read, but certainly she should know how to hold the (pictographic) safety card right-side up, no? Watch out for those Hispanic guys, they want to smoke.

    After landing, we see each of the travelling groups as they get off the plane. The retired couple light up with joy as they hug their adult children who came to meet them at the airport. The businesswoman meets her business partner with a friendly handshake. Mom welcomes the man and daughter with hugs and kisses. And the single guy just wanders off on his own.

    He's probably looking for a smoking area.

    The other thing I find amusing about the safety video is that after it is completed in English, the video is played a second time (heavily abbreviated) with Danish subtitles. "Okay, those slow Americans had to get the long version. Now here's the quick version for you clever Danes."

  • The Old New Thing

    Some files come up strange in Notepad

    • 29 Comments

    David Cumps discovered that certain text files come up strange in Notepad.

    The reason is that Notepad has to edit files in a variety of encodings, and when its back against the wall, sometimes it's forced to guess.

    Here's the file "Hello" in various encodings:

    48 65 6C 6C 6F

    This is the traditional ANSI encoding.

    48 00 65 00 6C 00 6C 00 6F 00

    This is the Unicode (little-endian) encoding with no BOM.

    FF FE 48 00 65 00 6C 00 6C 00 6F 00

    This is the Unicode (little-endian) encoding with BOM. The BOM (FF FE) serves two purposes: First, it tags the file as a Unicode document, and second, the order in which the two bytes appear indicate that the file is little-endian.

    00 48 00 65 00 6C 00 6C 00 6F

    This is the Unicode (big-endian) encoding with no BOM. Notepad does not support this encoding.

    FE FF 00 48 00 65 00 6C 00 6C 00 6F

    This is the Unicode (big-endian) encoding with BOM. Notice that this BOM is in the opposite order from the little-endian BOM.

    EF BB BF 48 65 6C 6C 6F

    This is UTF-8 encoding. The first three bytes are the UTF-8 encoding of the BOM.

    2B 2F 76 38 2D 48 65 6C 6C 6F

    This is UTF-7 encoding. The first five bytes are the UTF-7 encoding of the BOM. Notepad doesn't support this encoding.

    Notice that the UTF7 BOM encoding is just the ASCII string "+/v8-", which is difficult to distinguish from just a regular file that happens to begin with those five characters (as odd as they may be).

    The encodings that do not have special prefixes and which are still supported by Notepad are the traditional ANSI encoding (i.e., "plain ASCII") and the Unicode (little-endian) encoding with no BOM. When faced with a file that lacks a special prefix, Notepad is forced to guess which of those two encodings the file actually uses. The function that does this work is IsTextUnicode, which studies a chunk of bytes and does some statistical analysis to come up with a guess.

    And as the documentation notes, "Absolute certainty is not guaranteed." Short strings are most likely to be misdetected.

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

  • The Old New Thing

    Out of the deep fryer

    • 13 Comments

    McDonalds anonunced that it would no longer offer "Super Size" on its menu. The ostensible reason was that the addition of newer healthier options didn't leave room on the menu for "Super Size".

    This was of course laughable on its face.

    Now it's even more laughable, because it turns out that the so-called "healthy" options are even fattier than the burgers. You can see for yourself on McDonalds' own Interactive Nutrition Counter. A Caesar Salad with Chicken Premiere contains 18.4 grams of fat, compared to 11.5 grams of fat in a cheeseburger.

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

  • The Old New Thing

    @-notation was never legal in HTTP URLs anyway

    • 21 Comments

    Some people are in an uproar over IE's dropping of support for @ notation in HTTP URLs. What people fail to note is that The @ notation was never legal for HTTP URLs in the first place. If you go to RFC 1738 section 3.3 (HTTP), it explicitly states:

    An HTTP URL takes the form:

          http://<host>:<port>/<path>?<searchpart>
    

    where <host> and <port> are as described in Section 3.1. If :<port> is omitted, the port defaults to 80. No user name or password is allowed.

    (Emphasis mine.)

    So there are now three sides to the argument:

    • "I want Internet Explorer to be backwards-compatible with my invalid URLs." (These people want the @-syntax retained.)
    • "I want Internet Explorer to be more secure." (These people want the @-syntax removed.)
    • "I want Internet Explorer to be more standards-compliant." (These people also want the @-syntax removed.)

    Personally I think dropping support for @-notation was the right thing to do.

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

  • The Old New Thing

    the qUirKY jaPan HomEPage

    • 2 Comments

    The weird stuff about Japan you were afraid to ask about. The Seldom-Asked Questions are interesting, but what I find the most fascinating is the pictures of various Japanese subcultures.

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

Page 404 of 434 (4,335 items) «402403404405406»