dllimport

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • George3

    dllimport


    Hello everyone,




    For dllimport KB from Microsoft,







    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



    --
    George3
    ------------------------------------------------------------------------
    Posted via http://www.codecomments.com
    ------------------------------------------------------------------------

  • William DePalo [MVP VC++]

    #2
    Re: dllimport

    "George3" <George3.34xh1u @mail.codecomme nts.comwrote in message
    news:George3.34 xh1u@mail.codec omments.com...
    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


    Comment

    Working...