Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Index Visual C++ and MFC Fundamentals


LPVOID lpReserved
)
{
return TRUE;
}

double MOIRectangle(double b, double h)
{
return b * h * h * h / 3;
}

double MOISemiCircle(double r)
{
const double PI = 3.14159;

return r * r * r * r * PI / 8;
}

double MOITriangle(double b, double h, int)
{
return b * h * h * h / 12;
}


  1. To create the DLL, on the main menu, click Build -> Build MomentOfInertia

  2. Open Windows Explorer and open the Debug folder of the current project. Notice
    that a file with dll extension and another file with lib extension have been created


22.4.3..Win32 DLL Test..................................................................................


Naturally you should test your DLL to make sure it behaves as expected, before
distributing it to other applications. For an application to be able to use the DLL, it must
be able to locate its dll and its lib files. The simplest way to do this is to simply copy and
paste these files in the client project. Some other times, the DLL and its library will need
to reside in the system directory. To make the DLL available to an application, you must
import the DLL into the application. Although there are various ways to do this, the
simplest consists of adding it to the project by using the main menu where you would
click Project -> Add Existing Item..., and selecting the lib file.

We mentioned that, when creating the DLL, you should use the _declspec(dllexport)
modifier for each function that will be accessed outside of the DLL. In the project that is
using the DLL, each function that will be accessed must be declared using the
_declspec(dllimport) modifier.

Practical Learning: Testing a DLL



  1. To start a new project, display the New Project dialog box

  2. In the Project Types, click Visual C++ Projects. In the Templates, click MFC
    Application

  3. In the Name edit box, type MOITest and press Enter

  4. In the MFC Application Wizard, create the application as Dialog Based without an
    About Box and set the Dialog Title to Moment Of Inertia DLL Test

  5. Click Finish

Free download pdf