How to Build a Stand Alone DLL

Introduction

If you want to distribute the code for a non-windows class as a dll, it is easier to use the new project method to create this dll. This time select the same options you would use for the EasyWin project, with the exception that you want to choose dynamic library as the type of project.

The Def File

The def file needed here can be model after the following:

LIBRARY        CUSTDLL

DESCRIPTION 'customer definitions - Copyright © B. W. Mielke 1998. All Rights Reserved.'

where the only requirement is that the name of the library (in this case CUSTDLL) be the same as the project name.

The Main File

The main file of this type of dll is standard boiler plate to which you add a few extras. First you must include the header for the class you want to export. This header must be proceeded by the definitions that build your classes as exportable classes. In this example the customer header includes darray.h and rcpointe.h. Both of these classes have been modified for dll use so we have to define the identifiers that indicate we are building a dll with these classes.

The Class Header

Just like the Windows dll, our class header has to be altered to make sure that the class is redefined as imported or exported depending on the use. To see the header for the customer class click here.

The Class cpp File

The classes cpp file needs only to be altered by the definition of the build identifiers before the class header is included. Click here to see the cpp file.

Creating the DLL

Creating one of these dll is very simple, you simply select build (or make) from the project menu. You don't even have to make the library, it is made as an automatic side effect. You can also use this technique to reduce the size of dlls created using AppExpert.

Using the DLL

If you have an application project that uses any of your Customer classes, just make a copy of all of the headers used in the dll project, the lib file and the dll file in the directory of the application project. Then add the lib node to your application project and use the headers as you would normally use them if you never knew about dlls. See week 6 of 266372 for the rest of this example.