OLE Bank-Server


This project contains an example program that demonstrates the use of dual COM interfaces and database access in Functional Developer. It is the server part of the OLE Bank Client/Server example. It uses the macros and utility functions provided by the OLE-Automation library, rather than the low-level Windows OLE API, to define and implement its objects. It uses the sql-odbc library to communicate with the database. And it uses the DUIM library to provide a simple user interface.

The OLE-Automation and sql-odbc libraries are documented in the Functional Developer "OLE, COM, ActiveX and DBMS" reference manual.

ODBC requirements

In order to run this example, you need to have ODBC version 3.0 (or higher) and an ODBC driver for Microsoft Access installed on the machine hosting the server application. You do not need a copy of Microsoft Access.

Both ODBC 3.x and the Microsoft Access driver are available free for download from the Microsoft Universal Data Access web site.

From the Downloads section, download the Microsoft Data Access Components, version 1.5c or higher, for your Windows platform. You do not need to download the full 6.4MB file -- mdacfull.exe, the MDAC 1.5c redistribution setup file, is only 3.4MB and contains everything you need.

This file installs ODBC 3.x and the Microsoft Access Driver, amongst other things.

This information may change in the future.

Registering the Database with ODBC

This example includes a sample bank database, bankDB.mdb, in the project directory (typically in C:\Program Files\Functional Objects\Dylan\Examples\ole\bank\server). Before we can access this database using ODBC, we need to register it under a data source name in the ODBC control panel. This installation step also tells ODBC which driver to use when connecting to the database.

  1. First, make sure the database is writable: find the bankDB.mdb file in an Explorer window, right-click on it, select Properties from the pop-up menu, and clear the Readonly attribute if it is checked.
  2. Open the ODBC control panel.
  3. Select the User DSN tab.
  4. Click Add...
  5. Select Microsoft Access Driver from the list of available drivers.
  6. Click Finish.
  7. In the Microsoft Access 97 setup dialog, enter the Data Source Name as "bankDB".
  8. Click Select to bring up a file dialog. Browse until you locate the bankDB.mdb file.
  9. Select bankDB.mbd from the list of available database files.
  10. Click OK to close the file dialog.
  11. Click OK to close the Microsoft Access 97 Setup dialog.
  12. Click OK to close the control panel.

Server registration and invocation

To build the server, open the bank-server project and press the "Build" button in the Project window.

This project can be built in either of two configurations. It can be built as an EXE file which can then be used as a local server, or it can be built as a DLL file which can then be used as an in-process server. The default is to build an EXE file. Use the "Target file" entry in the "Link" tab of the "Project > Settings..." dialog to switch between these two options.

In either case, in order for the server to work when started from a client program, all of the libraries used by the server need to either be in the same directory as the server executable, or else in a directory which is in the system PATH (not the individual user's PATH on NT). The simplest way to accomplish this is to use the "Project > Build Release" command to create a release directory. If you wish, you can move that directory to any location you want, but you must do so before you attempt to register the server.

Before you can use the server, you must register it and create its type library. How to do this depends on whether you have built a local (EXE) server or an in-process (DLL) server.

To register a local server, run it from a DOS command prompt like this:

bank-server.exe /regserver

This will make the type library, create the necessary entries in the Windows System Registry, and then terminate without creating any windows. The full pathname of the server is recorded, so you must unregister the server before you move or delete it. You can unregister it by doing:

bank-server.exe /unregserver

To register an in-process server, use the regsvr32 command line utility like this:

regsvr32 bank-server.dll

(The complete pathname will need to be given if the file is in a different directory that is not in the PATH.) This will cause the appropriate entries to be made in the Windows System Registry. (For use in a batch script, the "/s" option may be used to suppress the dialog box reporting completion.) The full pathname of the server is recorded, so you must unregister the server before you move or delete it. You can unregister it by doing:

regsvr32 /u bank-server.dll

This invokes the server to unregister itself, so won't work if the server has been deleted first.

After registering the server, you can run the bank-client example project to test it, as described in the client README file.

Program Internals

The server application is composed of the following parts:

server-library.dylan
library and module definitions.
server.dylan
server implementation
database.dylan
database support
server-frame.dylan
local server GUI
server-main.dylan
server initialization and main entry points.
project bank-interface
A subproject containing the definitions of all the COM interfaces used in this example. It is a separate project so that it can be shared with clients written in Dylan.