October, 2006

  • The Old New Thing

    What does the letter "T" in LPTSTR stand for?


    The "T" in LPTSTR comes from the "T" in TCHAR. I don't know for certain, but it seems pretty likely that it stands for "text". By comparison, the "W" in WCHAR probably comes from the C language standard, where it stands for "wide".

  • The Old New Thing

    Raymond's excursions into East Asian pop music, episode 4: Yuki


    When my story left off, a colleague of mine had dedicated himself to finding some good Japanese pop music, and what he found was this music video of the song JOY by Japanese pop star Yuki Isoya, who performs under the stage name YUKI.

    The video was mesmerizing. The Flash Gordon extras. The dance steps. The blinking. The hyperventilating. (Though I don't think the blue dress suits her; she's not a teenager any more.) But the best part is the retransition from the middle section. After the wiggling fingers, she just leans into the big note and swings her arms in, well, joy. I have no idea what she's saying, but somehow that doesn't matter.

    My colleague became obsessed with his own discovery, buying all of Yuki's solo albums. Apparently, he's in good company; she seems to be quite popular. The JOY video won the Japanese Space Shower Music Video Awards prize for Best Video of 2006.

    During my tourist day in San Francisco earlier this year, I stopped by Japantown and bought two CDs. One was the album JOY. Would the other songs on the album be as infectious as its title track? Fortunately, I was not disappointed. They're all great.

    The other album I bought was Katamari Fortissimo Damacy (塊フォルテッシモ魂), the soundtrack to the video game Katamari Damacy, thereby bringing the story full circle.

  • The Old New Thing

    640 x 480 is still not dead


    Windows still has to worry about displays running at 640×480 resolution. Even though the default minimum resolution was bumped up to 800×600 for Windows XP, there are still 640×480 devices out there, typically tiny monitors on servers. One common set-up is to have a bank of tiny little monitors, each corresponding to one server in a cluster, with one large monitor that can "tap into" any of the tiny monitors for a closer look. Even though these servers typically are managed via remote administration, keeping actual monitors available acts as a safety net when remote administration proves insufficient, for example, if there is a networking problem.

    I don't know what the minimum video requirements will be for Vista, but I doubt they'll really affect these types of machines. These server monitors are not interested in any fancy new video features like Aero Glass or desktop composition.

    Running at 640×480 is not just for these server monitors, though. I believe Safe Mode runs at 640×480, so Explorer still needs to be usable at that resolution. This has design consequences, for it means that every component of the interface that a user might need when in Safe Mode (such as the Start menu, Explorer windows, Add or Remove Programs, possibly Windows Update I'm not sure) needs to remain usable under such low resolutions. For the Start menu, for example, this means making sure that the default Start menu will still fit on the screen even at 640×480.

    You might respond, "Well, that's stupid, letting this 640×480 limitation cramp your design. You should design for a high-resolution display, say something that is 1024×768 or greater, and have a special 'Safe Mode' version of the interface that runs in 640×480 for the cases where you have to squeeze into a smaller space."

    This approach has two drawbacks. First, it means that there are two versions of the user interface that have to be designed, implemented, and tested. The amount of work is disproportional to the benefit, since Safe Mode is used less than one tenth of one percent of the time (and that's probably grossly over-estimating). If you were in a position to decide where user interface resources should be spent, would you spend it on a special Safe Mode interface, or would you rather spend it on making the Aero interface even more solid?

    The second problem with a special Safe Mode interface is that, well, it's a special Safe Mode interface. When the user boots into Safe Mode, they're already anxious. Their computer doesn't work; they're trying to fix it. And then they boot up and are faced with a new interface that they're not familiar with. This doesn't do much to calm their anxiety.

  • The Old New Thing

    Why do I see the same fake names in Microsoft samples over and over?


    If you see a fake name in a Microsoft sample web site, sample code, or sample documentation, you'll probably find that it's usually one from a small set of names. A sample corporation is typically called Contoso or Fabrikam. A sample store is typically Wingtip Toys. (For a few weeks, they used Wingtip Toys on Windows Live Local.) A sample bank is Woodgrove Bank. And a sample software company is Litware, Inc. (There are other fake names, but these are the ones you're most likely to see.)

    Where did these fake names come from?

    The Trademark Group in Microsoft's legal department.

    The Trademark Group performed background checks on these names and cleared them for use as fictitious entities by Microsoft samples and documentation. The web sites for all of these "companies" redirect to the main Microsoft home page. Having a pool of "standard fake names" means that Microsoft samples and documentation don't run into the problem of a fake URL turning into a porn site.

  • The Old New Thing

    Shifting fortunes at Airbus over the A380


    The Airbus A380 will be the largest-capacity commercial passenger plane, once they get around to making them. Now two years behind schedule, the A380 is not making life any easier for their parent company EADS. And in this two-player world, bad news for Airbus means good news for Boeing.

    As a Seattleite, I naturally root for Boeing over Airbus. After all, Boeing started here (even if they did move to Chicago a few years ago), and many people forget that they are easily the largest single technology company in the Seattle area, with twice as many local employees as Microsoft.

  • The Old New Thing

    How do I prevent multi-line edit controls from eating the Enter key?


    You might decide to put a multi-line edit control in a dialog box, not because you want the user to input multi-line data, but because it's a convenient way to display multi-line text. When you do that, you may notice that the Enter key does not invoke the default dialog button, as you might normally expect. That's because the multi-line edit control tells the dialog manager that it wants the Enter key. So how do you tell the multi-line edit control to stop doing that and let the Enter key do its normal thing?

    You already know the answer to this. As we saw quite some time ago, a control responds to the WM_GETDLGCODE message to influence the behavior of the dialog manager. In this case, the edit control is returning DLGC_WANTMESSAGE in response to the keyboard Enter key. What you want to do is prevent this from happening. You want to change the value that the edit control returns to the WM_GETDLGCODE.

    Since there is no existing window style to specify this behavior, you're left with subclassing the control and removing the DLGC_WANTMESSAGE code if the message is the Enter key.

  • The Old New Thing

    Proto-Microspeak: The goat rodeo


    Somebody at a meeting two years ago used the term "goat rodeo" to describe a completely confused situation. The term stuck with me as a really funny folksy analogy. It's not official Microspeak, but who knows, it may someday gain currency. I certainly enjoy saying it.

    "Goat rodeo."

    "Goat rodeo."

    "Goat rodeo."

    (Some earlier Microspeak entries: schedule chicken, baking.)

  • The Old New Thing

    When something is available for the user, which user are we talking about?


    Some people have taken issue with the term WM_USER for the name of the base of the message range that is the province of the window class implementor. (Refresher for those who forget which messages belong to whom.) The complaint is that the user can't use them since they belong to the window class.

    Aha, but the real question is, "Who is the user?" In other words, when we say "user-defined", who is the user that's doing the defining? There are four components involved here, and each one gets its own message range.

    • The window manager gets the messages below WM_USER.
    • The class implementor gets the messages from WM_USER to WM_APP-1.
    • The application (more specifically, the code that creates the window) gets the messages from WM_APP to MAXINTATOM-1.
    • Everybody else gets the messages from MAXINTATOM to MAXWORD (via RegisterWindowMessage).

    Who is the user?

    It depends on your point of view. From the window manager's point of view, the class implementor is the user, since that's the code that is using the window manager.

    From the class implementor's point of view, it is the application that creates the window that is the user, since that's the code that is using the window class.

    And from the application's point of view, it's all that outside code that is the user, since that's the code that is using the application.

    Conversely, you can look "up" the list and observe that from each component's point of view, the messages that belong to the components above it are "reserved". From the class implementor's point of view, the window manager messages are reserved. From the application's point of view, the class implementor's messages are reserved. And from the outsider's point of view, the application's messages are reserved.

    Let's use one of those generic box diagrams.


    Each box considers the messages that belong to its inner boxes as reserved; conversely, each inner box considers the next outer box as its "user".

    Since the winuser.h header file was written by the window manager team, it's not surprising that they look at the world from the window manager's point of view. Therefore, everything outside the window manager is "user-defined" and everything inside the window manager is "reserved".

    Of course, if you look at things from the point of view of the class implementor, then the context of the words "reserved" and "user" changes. You can see this, for example, in the dialog box constant DWLP_USER, which is the index of window bytes that can be used by the "user" of the dialog box; i.e., by the application's dialog procedure.

  • The Old New Thing

    How Raymond learns languages (and why it's not working)


    Whenever I wander into the subject of languages here, a commenter will ask me what my language-acquisition technique is. I have refrained from describing it since it is very peculiar to my way of learning, and I doubt it will work for most people. But since people seem to be interested, here it is.

    I like to learn a language by learning its rules first, then converting the rules to instinct while picking up vocabulary. This is backwards from how children learn a language, which is entirely instinctual and heavy on vocabulary acquisition with the rules coming only much later when they reach school and need to fine-tune their skills.

    First, sign up for a language class. In addition to providing a structured environment for learning, it'll be the only place to get pronunciation practice without having to impose on friends and relatives. It also forces you to keep up. You might skip a week if you're just meeting with a friend, but you're not going to skip a week if you are attending a class, because the class is just going to keep going without you.

    Next, get a pocket grammar book. I picked up my Swedish grammar book for $2 at a used bookstore. It's called Simplified Swedish Grammar by Edwin J. Vickner, published by Augustana Book Concern in 1934. (That's right, 1934. Which means that it covers aspects of Swedish grammar that are now obsolete, such as plural forms of verbs like "Vi skrevo".) Read the grammar book and try to digest it. You don't have to get every last detail, but you should at least get the basic structure of the language. Don't worry so much about the fine points of adjective and verb endings, but do know how the past tense is formed, and learn the structural elements of the language like word order, prepositions, and conjunctions. The goal here is to learn enough so you can follow a sentence even if you don't know what all of the words mean.

    After a few weeks of the language class, you'll have a rough feel for the language. Get some children's books and try to work your way through them.

    Find the news for dummies and listen to it every day. It will be rough going at first. I remember when I started listening to Klartext, I had to concentrate really hard to understand just fragments of the first news story, at which point I was too tired to deal with the rest of the program. I would still listen to it, though, just to get a sense for the flow of the language, even though I wasn't trying to understand what they were saying. (Note: Proceeding with this step too soon will not accomplish anything. All you'll hear is gibberish.) Knowing the basic structure of the language will make it easier to understand the news for dummies. You can get by without the right adjective endings, but if you can't find the verb in a sentence, you're going to be in trouble.

    If you can find a transcript of the news for dummies, use it. It will make it much easier to follow along (assuming a language whose spelling is phonetic or nearly so), and it will also help train your ear to recognize the language as it is actually spoken, as opposed to how it is officially spoken, because there are many pronunciation rules that are simply invisible to native speakers. (For example, officially, the English word "what" has a "t" at the end, but in practice, the "t" often turns into a "d" or a glottal stop or vanishes entirely. Meanwhile, the leading consonant is often pronounced as a "w" instead of a "wh". As another example, the word "news" can be pronounced as "nooz" or "nyooz" or "neeooz", and most native speakers don't even realize that there's a difference.)

    As you become more comfortable with the sound of the language, go back and re-read the grammar points you skipped over, like the adjective endings. Learn the charts and listen for them in the news for dummies. Hopefully the audio reinforcement will help you develop an ear for them and eventually be able to use them properly without having to consciously refer to those charts. The goal is not to rely on the charts but rather to say the right thing because that's how you've always heard it said. But the charts are there when your instinct fails you.

    Listening is also the only way you will pick up "unwritten rules" such as the motion of weak pronouns in Swedish and German, which I picked up a sense for despite it being covered by no grammar book I own. (Though it is covered by the amazingly detailed Igloo Swedish Grammar page where it is given the name Long Object Shift.)

    You should also read the news. (This was a lot harder to find back in the pre-Internet days, but now it's ridiculously easy.) Reading is easier than listening in many respects, because you can read as slowly as you want, and all the word endings are right there in front of you. No matter how many different ways there are of saying "what", there is only one way of spelling it. Be careful, however, because the language of the news is typically more formal than everyday conversation. (And the language of headlines is even stranger. In English, German, and Swedish, for example, headlines tend to omit articles and helping verbs. "Ball hit into pond" is a valid headline but an awful English sentence.)

    If you do all this, you'll be far ahead of the class you signed up for. By the time they start learning noun plurals, you've already internalized the rules for formation of the past tense of regular verbs. (But still show up for class, for you can use the class to fill in gaps in your knowledge.)

    Anyway, that's how I taught myself Swedish in six months. Maybe it'll work for you, but probably not.

    Actually, I'm having much difficulty applying this technique to Mandarin Chinese because the language doesn't fall into the neat grammatical patterns of Western languages. I have yet to find a Chinese grammar book that takes a structural approach. I also haven't been able to find Mandarin Chinese news for dummies. I vaguely recall that VOA or some similar organization had a special version of the news in Mandarin Chinese, not for Chinese listeners, but for American servicemen who are studying Mandarin Chinese. But I can't find it.

    And I don't get much help from my parents. I remember asking my mother a question about word order, and she said, "Oh, there aren't any rules like that. You just say what makes sense." Well, yeah, you say what makes sense assuming you already know the language...

    I replied, "Oh, so I can say this," and spoke a sentence where I used both a time and place, and I think I put the time first.

    "Oh, no, you have to say it this way," and she restated the sentence with the place first.

    "Ah, so there are rules on word order after all," I pointed out.

    "Oh, yeah, I guess so. But I don't know what they are."

    Native speakers are not always the best choice for learning the grammar of a language because they don't understand their language formally, only instinctively. Consider the four sentences below.

    I took the ball home. I took it home.
    I took home the ball. I took home it.

    That last box is crossed out because "it" is acting as a weak pronoun and must remain close to the verb. Good luck finding a native English speaker who can explain weak pronouns. (Heck, good luck finding one who can explain what a finite verb is!)

    On other language topics:

    Commenter Michael Puff notes that in Germany, as a rule, hotel employees should speak English. While they may be true in general, the off-hours staff at the small hotel I stayed at in Munich a few years ago were clearly not comfortable with English. They seemed relieved that I was able to speak with them in (bad) German. And my friend who went on a vacation in Germany thought Michael's remark was just a cruel joke, for in her experience, practically nobody spoke English, not even in the cities. (She said that the hotel staff could usually speak "hotel English".)

    One of the places my friend and her husband visited during their stay in Munich was Das Deutsche Museum. I warned them about the mining exhibit (English), 900 meters of more than you really wanted to know about mining. I remember being absolutely drained by the experience, and I asked my friend what she thought. "It wasn't that bad. It goes a lot faster if you can't read German."

    Andreas Johansson points out that in Amsterdam, people will switch to English as soon as they recognize that you aren't Dutch. A different friend of mine lived in the Netherlands for a while and they way he described it, people "autodetected" the accent and instantly switched to English. His solution? Buy a one-way train ticket to a small town, have lunch there, explore the local attractions (maybe a small museum or something), then buy a return ticket. In the small towns, people are less likely to speak English, which forced my friend to carry out these simple transactions (ordering lunch, taking a museum tour, buying a train ticket) in Dutch.

    I don't like to talk about stuff like my family's native language because it leads to additions in Wikipedia that give it a creepy stalker-like feel. "He can often be found in the Tully's on 152nd St, typically on Wednesdays around 8pm, enjoying a venti no-whip mocha with vanilla. He tends to sit at the table near the fireplace facing away from the door."

    Note also that the picture of me in the Wikipedia article claims "The copyright holder allows anyone to use it for any purpose," and "Free to use as per http://channel9.msdn.com/termsofuse.aspx". I don't know how they came to that conclusion, because if you actually read the terms of use, you'll see that it says that it is permissible to use Documents "provided that (1) the below copyright notice appears in all copies" (no such copyright notice appears in the Wikipedia entry), and "(2) use of such Documents from the Services ... will not be copied or posted on any network computer or broadcast in any media" (I think Wikipedia counts as "posted on a network computer"). And then there's the clause, "No logo, graphic, sound or image from any Microsoft Web site may be copied or retransmitted unless expressly permitted by Microsoft."

    Or maybe terms of use don't apply to Wikipedia.

  • The Old New Thing

    A very brief return to part 6 of Loading the Chinese/English dictionary


    Back in Part 6 of the first phase of the "Chinese/English dictionary" series (a series which I intend to get back to someday but somehow that day never arrives), I left an exercise related to the alignment member of the HEADER union.

    Alignment is one of those issues that people who grew up with a forgiving processor architecture tend to ignore. In this case, the WCHAR alignment member ensures that the total size of the HEADER union is suitably chosen so that a WCHAR can appear immediately after it. Since we're going to put characters immediately after the HEADER, we'd better make sure those characters are aligned. If not, then processors that are alignment-sensitive will raise a STATUS_DATATYPE_MISALIGNMENT exception, and even processors that are alignment-forgiving will suffer performance penalties when accessing unaligned data.

    There are many variations on the alignment trick, some of them more effective than others. A common variation is the one-element-array trick:

    struct HEADER {
     HEADER* m_phdrPrev;
     SIZE_T  m_cb;
     WCHAR   m_rgwchData[1];
    // you can also use "offsetof" if you included <stddef.h>
    #define HEADER_SIZE FIELD_OFFSET(HEADER, m_rgwchData)

    We would then use HEADER_SIZE instead of sizeof(HEADER). This technique does make it explicit that an array of WCHARs will come after the header, but it means that the code that wants to allocate a HEADER needs to be careful to use HEADER_SIZE instead of the more natural sizeof(HEADER).

    A common mistake is to use this incorrect definition for HEADER_SIZE:

    #define HEADER_SIZE (sizeof(HEADER) - sizeof(WCHAR)) // wrong

    This incorrect macro inadvertently commits the mistake it is trying to protect against! There might be (and indeed, will almost certainly be in this instance) structure padding after m_rgwchData, which this macro fails to take into account. On a 32-bit machine, there will likely be two bytes of padding after the m_rgwchData in order to bring the total structure size back to a value that permits another HEADER to appear directly after the previous one. In its excitement over dealing with internal padding, the above macro forgot to deal with trail padding!

    It is the "array of HEADERs" that makes the original union trick work. Since the compiler has to be prepared for the possibility of allocating an array of HEADERs, it must provide padding at the end of the HEADER to ensure that the next HEADER begins at a suitably-aligned boundary. Yes, the union trick can result in "excess padding", since the type used for alignment may have less stringent alignment requirements than the other members of the aggregate, but better to have too much than too little.

    Another minor point was brought up by commenter Dan McCarty: "Why is MIN_CBCHUNK set to 32,000 instead of 32K?" Notice that MIN_CBCHUNK is added to sizeof(HEADER) before it is rounded up. If the allocation granularity were 32768, then rounding up the sum to the nearest multiple would have taken us to 65536. Nothing wrong with that, but it means that our minimum chunk size is twice as big as the #define suggests. (Of course, since in practice the allocation granularity is 64KB, this distinction is only theoretical right now.)

Page 3 of 4 (36 items) 1234