Modern C++ Lamentations

rjframe dlang at ryanjframe.com
Thu Jan 3 11:52:56 UTC 2019


On Tue, 01 Jan 2019 19:04:24 -0700, Jonathan M Davis wrote:

> From working with dlls with C++. With dlls on Windows, your program
> links
> against a static library associated with the dynamic library, and if any
> of the symbols are changed, the addresses change, and your program will
> be unable to load the newer version of the library without being rebuilt
> against the new version of the static library.

That's not necessarily true; Windows supports "implicit linking" and 
"explicit linking"; for implicit linking you do need to statically link 
against an import library, but for explicit linking you don't even need to 
know the DLL's name until runtime.

With explicit linking you load the library by calling LoadLibrary/
LoadLibraryEx, then call GetProcAddress with the name of your desired 
function to get the function pointer. If you watch the filesystem for the 
DLL to change, you could live-update by reloading the DLL (which you 
typically wouldn't do outside debugging or maybe if offering plugin 
support).

Most people just do implicit linking because it's less work. Any DLL can 
be loaded in both ways, though if there's a DllMain there may be problems 
if the library author doesn't support both methods; for implicit linking, 
DllMain is run before the program entry point, but for explicit linking 
its called by LoadLibrary in the context of the thread that calls it.

--Ryan


More information about the Digitalmars-d mailing list