Explicit and Implicit DLL Linking



1) Steps for installing Firestarter (fire wall) on Ubuntu   

2) Artificial Project 1 Uninformed and Informed Search Algorithms.

3) Artificial Intelligence Project on Alpha Beta Pruning.

4) Artificial Intelligence

5) Computer Security ( Bell LaPadula Model)

6) Fun With Pointers in C++

7) Resume Builder

8) CS8803 AIA @ Georgia Institute of Technology

9) AIA Week 5

The discussion today is centered on a very interresting topic of explicit and implicit linking of DLL. So what exactly does explicit and implicit linking really mean?

Implicit: This is the easy one. Lets say we have a client application called X that needs to use functions that resides in a DLL Y. This is assuming that the functions defined in Y are exported and can be used. Before X can use the functions withen Y, it needs to have the actual DLL present, the corresponding header file and the corresponding .lib file. The .lib file is linked to the application X at compile time. The .lib has all the information that X requires about the location of the exported functions in Y. Futhermore, when the client application X loads up in the memory space for execution, at the same time the DLL gets loaded in the memory as well. 

If the DLL cannot be found, then the application will terminate. 

Explicit. This is more interesting and allows the user to notice what is actually happening.  The client application X, does not require the .lib of the DLL to be present. What the client code X does is that it uses the LoadLibrary(..), GetProcAddress(..) and the FreeLibrary(..) functions. 

LoadLibrary(..): This function loads the DLL. So the C++ code can look like the following. 



Once the DLL has been loaded, we are in a position to start using the functions defined withen the DLL. Now, this is performed by using the function GetProcAddress(..) and by using the concept of function pointers. For sake of the example, lets say that there is a function Add(int x,int y) withen my DLL that I wish to use. 


LPFNDLLFUNC1 lpfndllfunc1;


GetProcAddress(..) returns the address of the function Add that has been loaded in memory. This address has been casted to type LPFNDLLFUNC1. We are assuming that the type LPFNDLLFUNC1 is a pointer type, hence our pointer lpfndllfunc1 is now a function pointer pointing to the Add function. In order to use the function, all I do now is:

int result=lpfndllfunc1(5,4);

Simple right? ;-)

Finally when I am done using my DLL, I can call the FreeLibrary(..) i.e. 


so that my DLL can be taken off the memory.