Visual C++ and MFC Fundamentals Chapter 21: Tree and List Controls
Once again, you can use the dll and lib files in the client applications of your DLL, as we
did already. If you do not want to use the definition file, you must provide a mechanism
for a client application to locate the function that is included in your DLL. This time also,
there are different ways you can do this. When a client application wants to use a
function, it can declare the function in the file that will call the function. The declaration
is done as a normal C++ function declaration. The function must be listed as it appears in
the DLL. This is why you should (honestly you must) always provide documentation for
your DLL: other people or companies should spend time predicting or guessing what
your DLL is used for or what it contains. In the following example, a function called
Number() is called from main(). The function is only declared but it is not defined
because this was already taken care of in a DLL:
#include <iostream>
using namespace std;
double Number();
int main()
{
double Nbr = Number();
cout << "Number: " << Nbr << endl;
return 0;
}
Another technique consists of including the header file that contains the function
definitions from the DLL. This means that, besides the dll and the lib files, if you
distribute your library, you must also distribute the header file (provided you are not
distributing the def file, although you can distribute both).
Practical Learning: Using a Module Definition DLL
- To start a new application, display the New Project dialog box and select MFC
application - In the Name edit box, type MOIDefTest and press Enter
- In the MFC Application Wizard, create the application as Dialog Based without an
About Box and set the Dialog Title to DLL Definition File Test - Click Finish
- Open Windows Explorer or My Computer. Locate the folder that contains the
MomentInertia project - Select and copy both the MomentInertia.dll and the MomentInertia.lib files
- Locate the folder that contains the current new project then paste the dll and the lib
files - Back in MSVC, on the main menu, click Project -> Add Existing Item...
- In the Add Existing Item dialog box, change the Files of Type to All Files
- In the list of files, click MomentInertia.lib
- Click Open
- Delete the TODO line on the dialog box. Add a new button. Change its Caption to
Moment Of Inertia - Double-click the new button to initiate its BN_CLICKED message