News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Dynamic Linking

Started by Twister, July 07, 2010, 07:28:05 AM

Previous topic - Next topic

jj2007

Quote from: gwapo on July 08, 2010, 09:15:20 AM
Quote from: jj2007 on July 08, 2010, 05:46:58 AM
Quote from: redskull on July 07, 2010, 11:12:40 PM
In the Microsoft parlance, there is "load-time dynamic linking"
Red, now you make me curious. If I understand Microsoft correctly, you could use dll functions 'directly' as in static linking. How would that look like in Masm?
::)

JJ, I'm not sure with MASM, but "load-time dynamic linking" is a common feature of HLL compilers where they insert stubs with series of LoadLibrary/GetProcAddress/FreeLibrary calls as opposed to hard-wired DLL/functions into import table. Load-time and run-time dynamic linking are exactly the same, except that in load-time dynamic linking, the compiler will do all the management/resolving/releasing for you.

That makes sense, thank you.

redskull

It's been awhile, so I'm probably rusty, but I think load-time linking goes something like this:
   
    1) The linker statically links "stub" function; that is, it actually inserts code into your EXE.
    2) Your CALL instructions are hard-coded to call those stub functions
    3) The stub function is simply an indirect JMP, in the form JMP [address]
    4) This address points to a spot in the PE header import table, which is basically left "blank" when you link.
    5) During the loading process, the OS hunts down and loads the functions you need
    6) It fills in those blanks in the PE Header with the actuall addressess of the functions
    7) You call the stub, the stub jumps to the address specified in the PE header, which is the function you want

-r

Strange women, lying in ponds, distributing swords, is no basis for a system of government

jj2007

Red, that sounds suspiciously like what happens when we "statically" link a crt_ function.

tenkey

Quote from: dedndave on July 07, 2010, 09:08:17 AM
well - it shows you how to use REGSVR32 to register a DLL
REGSVR32 /? will also get you there

regsvr32 only works with COM DLLs. That includes ActiveX, OCX and similar DLLs.
If you build a bare-bones DLL (meaning you have none of the required COM APIs), it just won't work.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

redskull

Quote from: jj2007 on July 08, 2010, 04:19:38 PM
Red, that sounds suspiciously like what happens when we "statically" link a crt_ function.

I don't do much with C functions in assembly, but IIRC there are two different versions; the normal CRT functions can be load-time dynamically linked, just like any other API function (which use the process above), but there's also a "static" version of the runtime which can be linked old-school style (that is, copied into your EXE verbatim).  But I could be wrong on all counts, as niether is my area of experitise.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government