So far, in order to use a library, whether static or
DLL, we made sure we new where the library was located. In fact, we kept
copying it in the directory where we created it and pasted in the
directory of the application that needed it. Suppose someone else or a
certain company created the library and distributed it, either with
Microsoft Windows or the DLL was installed with another application. To
use such a library, of course you can find it, copy it, and paste it in
the project where you want to use it. If many other programs are accessing
such a DLL, there would be no need to copy and paste it like that. These
types of DLL are installed in the Windows directory so any program that
needs them can access them from there.

As you can see, Microsoft Windows installed many DLLs
in the Windows or Windows\System32 directory. You too, when creating the
executable of your program, you can install the DLL there so you would
know with certainty where the DLL is located.

Practical Learning: Creating an MFC Static Library

To start a new application, open the New dialog box (File ->
New...) and, in the Projects property page, click Win32 Dynamic-Link
Libraries. In the Project Name box, type ExplicitDLL1 and press Enter

In the Win32 Dynamic-Link Library Step 1 of 1, make sure the An
Empty DLL Project radio button is selected.
Click Finish then click OK

To add a header file, on the main menu, click File -> New…

In the New dialog box and in the Files property page, click C/C++ Header File

To create the DLL, on the main menu, click Build -> Build
ExplicitDLL1.dll

Open Windows Explorer or My Computer and locate the folder that contains the
above ExplicitDLL1 project then open its Debug folder

Select and copy both the ExplicitDLL1.dll and the ExplicitDLL1.lib files

Paste them in your Windows\System32 folder

Explicit Loading a DLL

The technique of calling a DLL as we have proceeded so
far is referred to as implicit loading because we knew how we created the
DLL and we added it to the directory of the application we were creating.
This allowed us to add the DLL and its library file to the project and
freed us from remembering to call the DLL by its name. Another technique
consists of calling the DLL by its name. This is referred to as explicit
call because you specify the name of the DLL you need and you don't have
to copy and paste it in your directory and you don't have to add it to the
project.

To call a DLL explicitly,

You first call the LoadLibrary() function. Since/if creating
an MFC application, Microsoft recommends that you use the AfxLoadLibrary()
function

To use the function you need from the DLL, call the GetProcAddress()
function

When you have finished using the DLL, you can call the FreeLibrary()
function. This time too, Microsoft recommends using the AfxFreeLibrary()
function instead.

Practical Learning: Loading a DLL Explicitly

To start a new application, display the New dialog box and click the
Projects property page

Select MFC AppWizard (exe)

In the Name edit box, type ExplicitDLLTest1 and press Enter

In the MFC AppWizard Step 1, click Dialog Based and click Finish
then click OK

Delete the TODO line on the dialog box

Add an Edit Box control to the dialog box and change its ID to IDC_NUMBER

Add a new button. Change its ID to IDC_GET_NUMBER_BTN and
change its Caption to Get Number

Add a new Edit Box control and change its ID to IDC_GETNUMBER

Press Ctrl + W to open ClassWizard and click the Member Variables
property page

Add a CString Member Variable for the IDC_GETNUMBER control
and name it m_GetNumber

Add a CString Member Variable for the IDC_NUMBER control and
name it m_Number