|Date:||July 24, 2006 / year-entry #246|
|Summary:||If a function is declared with the dllimport 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...|
If a function is declared with the
First, there is no need for the stub function any more,
because the compiler can generate the special
mov ebx, [__imp__FunctionName] push 1 call ebx ; FunctionName(1) push 2 call ebx ; FunctionName(2)
(Note to crazy people:
This optimization means that you can run into problems
if you patch a module's import table once it has started
running, because the function pointer may have been
optimized into a register before you patched the import.
Consider, in the above example. that you patched the
Similarly, if your program tries to take the address of an imported
function that has been declared with the
As a result of this extra knowledge imparted to the compiler, the stub function is no longer needed; the compiler knows to go straight to the imported function address table.
Note that there are still occasional circumstances wherein you can induce the stub function to be created. We'll take a look at them (and related dangers) next time.
<-- Back to Old New Thing Archive Index