The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

Jul 26, 2006
Post comments count 0
Post likes count 0

Real Madrid (i.e., proper football) comes to Seattle

Raymond Chen

Hot off the presses. Real Madrid (with David Beckham, Ronaldo, and other stars) will play an exhibition match against D. C. United in Seah^H^H^H^HQuest Field on Wednesday, August 9th. I wonder if it'll be anything like the last soccer match I saw. At least let's hope they're ready to play instead of having tired themselves out playing video games. Tickets go on sale today.

Jul 26, 2006
Post comments count 0
Post likes count 1

What happens when you get dllimport wrong?

Raymond Chen

Now that we've learned what the declaration specifier does, what if you get it wrong? If you forget to declare a function as , then you're basically making the compiler act like a naive compiler that doesn't understand . When the linker goes to resolve the external reference for the function, it will use the stub from the import library, and everything will work as before. You do miss out on the optimization that enables, but the code will still run. You're just running in naive mode. (There are still some header files in the Platform SDK that neglect to use the declaration specifier. As a result, anybody wh...

Jul 25, 2006
Post comments count 0
Post likes count 0

If you know German, the world is, well, slightly more confusing

Raymond Chen

While it may be true that if you know Swedish, the world is funnier, I have to admit that my knowledge of German only served to create momentary confusion. When I saw the headline that the head of BetonSports was arrested, I thought to myself, "Who the heck would have a web site devoted to sports in concrete?" That's because the German word Beton means "concrete" (the construction material) in English, and the German word Sport means the same as in English. It took me a few moments to realize that the company's name is "Bet on Sports".

Jul 25, 2006
Post comments count 0
Post likes count 0

Issues related to forcing a stub to be created for an imported function

Raymond Chen

I noted last time that you can concoct situations that force the creation of a stub for an imported function. For example, if you declare a global function pointer variable: then the C compiler is forced to generate the stub and assign the address of the stub to the variable. That's the best it can do, since the loader will patch up only the imported function address table; it won't patch up anything else in the data segment. The C++ compiler, on the other hand, can take advantage of some C++ magic and secretly generate a "pseudo global constructor" (I just made up that term so don't go around using it li...

Jul 24, 2006
Post comments count 0
Post likes count 0

Raise la lanterne rouge

Raymond Chen

Sure, everybody knows that Floyd Landis won this year's Tour de France. But what about the guy who came in last? While the race leader wears the maillot jaune (yellow jersey), the person at the bottom of the pack is saddled with the lanterne rouge (red lantern), after the lamp that hangs on the back of a train. This year's "winner" is Wim Vansevenant, who at least appears to be a good sport about it. Lanterne rouge is not a position you go for. It comes for you. (It also amuses me that there's even a Tour de France Lanterne Rouge blog which keeps track of who is "pulling up the rear" throughout the race.) N...

Jul 24, 2006
Post comments count 0
Post likes count 0

How a less naive compiler calls an imported function

Raymond Chen

If a function is declared with the declaration specifier, this instructs the Visual Studio C/C++ compiler that the function in question is an imported function rather than a normal function with external linkage. With this additional information, the compiler generates slightly different code when it needs to reference an imported function, since the compiler is aware of the special way imported functions are implemented. First, there is no need for the stub function any more, because the compiler can generate the special instruction inline. Furthermore, the compiler knows that the address of an imported fun...

Jul 21, 2006
Post comments count 0
Post likes count 0

Floyd Landis stuns everybody on stage 17; Raymond less impressive

Raymond Chen

Wow. I delayed my departure for work Thursday morning until the results were in. And then I was inspired by Floyd's fantastic performance to kick it up a notch on one of the hills on my route, only to find about two thirds of the way up that there's a reason I don't normally go up the hill that fast... (On an unrelated note, a mini-van tried to run me off the road while I was heading up that hill. They pulled up next to me and then started a right turn. Fortunately I was able to escape to the right.) Okay, well, attacking that hill wasn't such a great idea now, was it. I decided to continue with an alternate r...

Jul 21, 2006
Post comments count 0
Post likes count 0

I didn't realize that it was International Group B Strep Awareness Month

Raymond Chen

I guess they're not doing a particularly good job of creating awareness because it wasn't until I consulted the 2006 National Health Observances calendar that the month of July is International Group B Strep Awareness Month. For some reason, July and August are pretty light on the health observances calendar. Maybe because people are on summer vacation. Who decides whether a particular health observance merits a day, a week, or a month? You'd think they'd save the months for the really big issues, seeing as there are only twelve of them. And for some reason, ultraviolet radiation gets two months. May is Ultrav...

Jul 21, 2006
Post comments count 0
Post likes count 0

Calling an imported function, the naive way

Raymond Chen

An import library resolves symbols for imported functions, but it isn't consulted until the link phase. Let's consider a naive implementation where the compiler is blissfully unaware of the existence of imported functions. In the 16-bit world, this caused no difficulty at all. The compiler generated a far call instruction and left an external record in the object file indicating that the address of the function should be filled in by the linker. At that time, the linker realizes that the external symbol corresponds to an imported function, so it takes all the call targets, threads them together, and creates an ...