Delphi link to windows dll statically or dynamically -
i aware implicitly linking libraries @ load time can lead performance increases , such wondering if practice link in way @ compile time increasing executable size (admittedly marginal) compared linking explicitly @ runtime. question when linking against microsoft windows dll files located in system32, 'better' link @ load time can libraries present or follow explicit approach?
language used delphi (pascal) , library in question wtsapi32.dll - terminal services.
edit: pointed out - choice of language incorrect , has been amended. also, due having every extensively linked libraries in unix, comments executable size can omitted, believed @ time in fact referring static linking bundles library code executable , realise impossible when using dll files (duh!). all.
the 2 forms of dll linking perhaps better named implicit , explicit. implicit linking refer static linking. , explicit linking refer runtime linking
for implicit linking linker writes entries import table of executable file. import table metadata used loader resolve dll imports @ module load time. stub function included each implicit import few bytes in size. executable size implications of implicit linking negligible.
with explicit linking imported function's address resolved call getprocaddress. call made when programmer chooses. if dll or function cannot resolved, programmer can code fall behaviour. there size implications explicit linking estimate similar implicit linking. if function address evaluated once , remembered between calls performance characteristics similar implicit linking.
my advice follows:
- prefer implicit linking. more convenient code.
- if dll may not present, use explicit linking.
- if dll must loaded using full path, use explicit linking.
- if want unload dll during program execution, use explicit linking.
you mention windows dlls. can safely assume present. don't try code allow program run in case user32.dll missing. functions may not present in older versions of windows. if support older versions you'll need use explicit linking , provide fallback. decide version support , use msdn sure function available on minimum supported platform.
Comments
Post a Comment