Re: Dynamic DLL Loading or Static ?

From: Peter Haas (newsgroupfeedback_at_pjh2.de)
Date: 11/15/03


Date: Sat, 15 Nov 2003 16:09:26 +0100

Hi Andrew,

Andrew Jameson wrote in <3fb614a9$1@newsgroups.borland.com>:
> Loading DLL's ... can someone just give me a good reason for dynamically
> loading them ? (I usually do but I'm not sure why I do !).

First a comment to the used terms. Usually the process is named linking.
A DLL is dynamic linked always: DLL = Dynamic Link Library. The correct
terms are load-time dynamic linking and run-time dynamic linking.

Static linking is e.g. using $L with a lib file.

> To be very much more specific ... I'm using BASS.dll (a 3D Audio DLL).
> I'm experiencing a very, very rare crash on XP systems when I
> initialize this DLL and I'm loading it dynamically. I was wondering
> whether it might be more stable if used static loading.

I can not answer this, I guess, this is dependent of the specific DLL.
>From my sight there should not be any difference, however I know a
example, where a DLL crash always with load-time dynamic linking and
work without problems with run-time dynamic linking. But this was the
only exception, I use load-time dynamic linking with many other DLLs
without a problem.

> Now the other area that I'm not clear on ... a user has Bass.dll (version
> 1.8) in their System folder and I'm relying on Bass.dll(version 2.0) which
> is in my exe folder. With dynamic loading, I'm making a specific reference
> to the file ... what happens in the static load when the user's got 1.8
> loaded ? ( I guess maybe I'm answering my own question ?).

There is a search order to find a DLL with relative path:
1. The directory from which the application loaded.
2. The current directory.
3. The system directory. (GetSystemDirectory)
4. The 16-bit system directory. (not Win9x, WinME)
5. The Windows directory. (GetWindowsDirectory)
6. The directories that are listed in the PATH environment variable.

On WinXP and later:
if HKLM\System\CurrentControlSet\Control\Session
Manager\SafeDllSearchMode is 1 the Sequence is 1, 3, 4, 5, 2, 6.
This is the default value for WinXP SP1 and WinSrv03.

You can change 2. with SetDllDirectory instead of SetCurrentDirectory
without changing the current directory. This API function exists in
WinXP SP1 and WinSrv03.

On Win2k or later:
If there exists a redirection file, the loader ignore any absolute path
values and load the DLL from the application path. A redirection file
have the format appname.local, the contents will be ignored.
Example: Projects.exe -> Project1.exe.local

With other word, it is extrem likely, that the application load the
version 2.0.

Maybe a other application use the version 1.8 at the same time and both
use same resources, what could cause problems.

Bye Peter.

-- 
JEDI+ API, the active JEDI Header Conversions Project:
http://jediplus.pjh2.de


Relevant Pages

  • Re: HLA stdlib v2.3 is now available
    ... dynamic linking on modern operating systems to save on resources. ... the whole thing into a DLL and then *any* assembler ... all the apps), but how many assembly apps does the average person run ... statically link in all the library code you use so your application is ...
    (alt.lang.asm)
  • Re: Dynamic DLL Loading or Static ?
    ... Loading it on demand the cuts down on load time for the app and on memory foot ... the DLL contains functionality that depends on specific platform features. ... There are two areas where static and dynamic loading differ. ... If you use static loading the DLL will be loaded and its Initialization ...
    (borland.public.delphi.nativeapi)
  • Re: Network Drive Issue
    ... > CHKDSK isn't sufficient to determin the heath of the drive. ... This is related to some network device driver ... renamed to disable it in VS 2005 due to slow and long delay loading ... the last DLL loaded is FEACP.DLL as well. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Manifest Requires Win2K Compatibility?
    ... You need to call InitCommonControlsEx() in a controlled manner in order to load the new version Common Controls before the VB6 runtime gets the chance to force loading of the older version DLL. ... Once VBRUN has made this call, the system won't try to handle DLL loading failures - expecting the "I'm so smart" VBRUN to handle them. ...
    (microsoft.public.vb.general.discussion)
  • Re: c code reusability
    ... disk space and computer memory are relatively cheap. ... of dynamic linking, ... The average size of a loaded DLL is 558 KB. ...
    (comp.lang.c)

Loading