Creating And Testing The Customer Window DLL

Introduction

Our customer window dll is created by following the instructions from week 5. There are some things that are a bit different here. First the customer window has resources attached. It has a dialog box description and a message to export. Second, the program used to create the customer window also uses dlls for some of its functions. This means that we can either compile with dynamic or static linking. We will use dynamic linking since the customer dll, right-listbox dll, and bcw dll will all be used in other parts of this project so we don't want to duplicate the code.

Convert The Header

We will export the CustomerWindow class (but not the CustomerData dialog) so we must add the following to our header for that window. We don't have to export the CustomerData dialog since it will only be used in the CustomerWindow. Also notice that the customer header is loaded without any reference to the fact it is from a dll. Care must be taken that Customer.h did not define class as CUSTOMER_WINDOW_CLASS. Avoid redefining class by using the same names for your class macros. If you have warnings about redefinition of a class macro, change the name of that macro or you will have trouble.

#ifndef CUSTOMER_H
#include "customer.h"
#endif

#include "obsrdlla.rh"            // Definition of all resources.

#if defined(CUSTOMER_WINDOW_TESTDLL)
#define CUSTOMER_WINDOW_CLASS class
#elif defined (CUSTOMER_WINDOW_BUILDDLL)
#define CUSTOMER_WINDOW_CLASS class _export
#else 
#define CUSTOMER_WINDOW_CLASS class _import
#endif 

The other change in the header is to replace class in the definition of CustomerWindow with CUSTOMER_WINDOW_CLASS

CUSTOMER_WINDOW_CLASS CustomerList : public TDialog {
...

Change Includes

Define CUSTOMER_WINDOW_BUILDDLL whereever you have included the customer window header. There are two places where this occured cstmrlst.cpp and obsrdllw.h.

Comment Out the OwlMain

Comment out OwlMain. If you don't do this you will have problems later.

/*int OwlMain (int , char* [])
{
    try {
        ObserdllApp    app;
        return app.Run();
    }
    catch (xmsg& x) {
        ::MessageBox(0, x.why().c_str(), "Exception", MB_OK);
    }

    return -1;
}*/

Convert The Project Into a DLL

Convert the project to a dll, by deselecting the debug options using the projects edit local options menu. Then convert the project type to Dynamic Library (AppExpert) using Target Expert. Once this is complete you can build the project.

Create The lib File

Make a batch file that contains the following line.

implib obserdll.lib obserdll.dll

Execute this batch file to get a lib file.

Test Your DLL

Change The TWindow Header And cpp Files

You can test your dll, by creating a program that uses your CustomerWindow. This program may be the main program in your project. In our project the main program will use a standard TWindow with CustomerWindow and eventually OrderWindow. All we need to do is use AppExpert to create a new SDI project with TWindow main window. Add the customer list pointer and customer window pointer ot the TWindow header. Then add the SetupWindow function and the message handler for WM_DELETE_CUSTOMER just as we did in our original program.

Add lib And Rc Files to Project

This project uses both your lib file for customer and your lib file for CustomerWindow, make sure the files are in the directory with your new project and add them to the project. The dll files for each lib, plus the dll for right-button listbox must also be in the directory with your new project. Finally the rc file for CustomerWindow must be added to the new project. You do not have to move the file, simply refer to it in the directory of the CustomerWindow project.

Run Your Test

At this point you should be able to run your test. Click here for my version of the project so far.

Back to week 6.