dllimport

G

George3

Hello everyone,




For dllimport KB from Microsoft,



http://support.microsoft.com/kb/132044/en-us



It is mentioned,



--------------------
If 'func1' exists in another DLL, the linker can't resolve this
directly because it has no way of knowing what the address of 'func1'
is.
--------------------



My question is, if we are using implicit linking, the address of import
function should be in the import library (.lib file) of the DLL and
since the import library is as an input parameter to linker, the linker
should know the address at link time?




thanks in advance,
George
 
W

William DePalo [MVP VC++]

George3 said:
My question is, if we are using implicit linking, the address of import
function should be in the import library (.lib file) of the DLL and
since the import library is as an input parameter to linker, the linker
should know the address at link time?

No. The address at which the DLL is loaded can not be known with certainty
until the loader actually loads it.

It's more complicated than this, but the best case DLL linking works like
something like this:

1) the compiler and the linker know that a function exists in a DLL at build
time
2) the compiler replaces the code that "calls" the function in the DLL to
one which calls into a slot in the Import Address Table (IAT) in the image
being linked
3) The slots in the IAT specify the DLL name and the function name (or
ordinal number) in the DLL
4) at run time, the loader brings the DLLs into memory and then patches the
slots in the IAT with jump instructions to the imported functions

This scheme speeds loading by minimizing patching. That is, there may dozens
of places in an application where CreateWindow() in USER32.DLL is called yet
no matter how many there are, only one IAT slot needs to be patched at
runtime.

Regards,
Will
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top