What are some ways to use DLL libraries?

·

2 min read

DLL libraries are pre-compiled function libraries that will be loaded and unloaded from memory on runtime by demand. For them to be usable by an executable, they need to be linked to the executable at the linker time. They can be linked in two different ways in Windows machines: the Implicit way and the Explicit way.

The implicit is the most commonly used and easier one of the two. The implicit linking method loads the library into memory at the start of the runtime and keeps them loaded until the end of execution. One of the advantages of this method is that once the program starts running, there will not be a case where a function call would fail to find the function address. And yes, that can happen. On the other hand, if one of the libraries fails to load at the start of the runtime, the execution will terminate and return an error.

The explicit linking method works slightly differently. Instead of loading libraries at the start of the execution, they are loaded into memory when they are needed and unloaded when not needed. This approach has the advantage that executable programs will boot up faster compared to the implicitly linked counterparts. In the explicit method, libraries are loaded by threads. By default, failure to load a library does not terminate the executing program. On the other hand, if not handled properly, failure to call a function can crash the program. It is a double-edged sword sometimes.