The Old New Thing
Practical development throughout the evolution of Windows.
Latest posts
Index to the series on DLL imports and exports
For reference.
Names in the import library are decorated for a reason
When I wrote that the symbolic name for the imported function table entry for a function is called , the statement was "true enough" for the discussion at hand, but the reality is messier, and the reason for the messy reality is function name decoration. When a naive compiler generates a reference to a function, the reference is decorated in a manner consistent with its architecture, language, and calling convention. (Some time ago, I discussed some of the decorations you'll see on x86 systems.) For example, a naive call to the function results in the compiler generating code equivalent to (on an x86 system;...
Real Madrid (i.e., proper football) comes to Seattle
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.
What happens when you get dllimport wrong?
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...
If you know German, the world is, well, slightly more confusing
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".
Issues related to forcing a stub to be created for an imported function
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...
Raise la lanterne rouge
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...
How a less naive compiler calls an imported function
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...
Floyd Landis stuns everybody on stage 17; Raymond less impressive
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...