VC++, MFC - Explicit and Implicit Dll Loading

The DLL file gets loaded into memory as soon as we execute the client program.

This is known as Implicit Linking. For the implicit linking to take place the dynamic link library must have an extension ‘.dll’. If implicitly linked, the DLL is not removed from memory unless our application is terminated. However, if there are other applications in memory that are using the DLL, it is not removed from memory till the last of these applications is terminated. If we want, we can defer the loading of the DLL till the time a call to the exported function in the DLL is not made. This is known as Explicit Linking. Explicit linking is more appropriate for interpreted languages such as Visual Basic, but we can use it from C++ if we need to. In explicit linking we don’t use the ‘.lib’ file. Instead we call the Win32 LoadLibrary( ) function, specifying the DLL’s pathname as a parameter. The LoadLibrary( ) function returns an HINSTANCE parameter. This parameter is used in a call to the GetProcAddress( ) function to fetch the address of the function to be called. This address is a pointer to a function. Through this pointer the function is finally called.