Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Index Visual C++ and MFC Fundamentals


22.4.2..Fundamentals of a DLL......................................................................


We have mentioned that a DLL is created as a project that contains at least one source
file and this source file should present an entry-point. After creating the DLL, you will
build and distribute it so other programs can use it. When building it, you must create a
library file that will accompany the DLL. This library file will be used by other programs
to import what is available in the DLL:

When the import library is created, it contains information about where each available
function is included in the DLL and can locate it. When an application needs to use a
function contained in the DLL, it presents its request to the import library. The import
library checks the DLL for that function. If the function exists, the client program can use
it. If it does not, the library communicates this to the application and the application
presents an error.

Normally, the import library is created when building the DLL but you must provide a
mechanism for the compiler to create it. There are two main ways you do this. You can
use a calling convention that allows the compiler to detect what function will be
accessible to the clients of the DLL. In this case, each one of these functions will start
with the _declspec modifier. When creating the DLL, the _declspec modifier must take
as argument the dllexport keyword.

The functions do not have to be included in the main file that contains the entry-point; it
may simply be convenient to do it that way.

Practical Learning: Creating a DLL



  1. To start a new project, on the main menu, click File -> Project...

  2. In the New Project dialog box, in the Project Type list, select Visual C++. In the
    Templates list, click Win32 Project

  3. In the Name edit box, type MomentOfInertia


DLL

Import
Library

Client
Application
Free download pdf