          
             HOW DO I USE CLIPS WITH OTHER WINDOWS 3.1 APPLICATIONS?

There are three ways to use CLIPS within other applications, Embedding CLIPS 
into your Windows application, Creating CLIPS as a DLL, or using Dynamic Data 
Exchange.

The first two methods offer several challenges. Embedding CLIPS within your 
existing application requires that you tailor CLIPS (SETUP.H) and your 
application code to fit within 64K of static data. To date we have had little 
experience in this area. The CLIPS 6.0 application alone is very close to the 
64K data limit.

Several people have created a CLIPS version of a Dynamic Link Library or DLL 
for version 5.1. A DLL for CLIPS 5.1 is available by anonymous ftp from 
ftp.ensmp.fr in the directory /pub/clips/incoming. The Software Technology 
Branch is looking into the possibility of creating a DLL version of CLIPS 6.0 
in the future.

The last option, using Dynamic Data Exchange Management Library or DDEML, is 
an area where we have had some experience and success. As I mentioned before, 
CLIPS 6.0 approaches the limits of the 64K of static data allowed to programs 
in the Large Memory Model. We have faced this problem when we created the 
Windows interface for CLIPS 6.0. The way we solved our problem was to create 
two separate applications (Interface & Editor) which worked together to form 
the complete CLIPS interface.

In the interface directory C:\CLIPS\SOURCE\INTRFACE there is a file called 
CLIPSDDE.C. This file is used to setup the CLIPS application as a Server. In 
the editor directory C:\CLIPS\SOURCE\EDITOR there is a file called IDE_DDE.C 
which is used to set up the editor as a client application. The two files 
setup a protocol which enables the editor application to communicate with the 
CLIPS kernel via the Dynamic Data Exchange Management Library package.

In the editor application the "Load Current Selection", "Load Entire Buffer", 
and "Batch Selection" options communicate to CLIPS via a one way transmission. 
The editor wraps up the data, opens a specific conversation topic, and 
transmits the information to CLIPS before the link is terminated. CLIPS gets 
an event that the client wishes to communicate information, and checks the 
conversation topic (LOAD or BATCH). CLIPS then gets the data and processes it 
appropriately before terminating the conversation. Although this scenario 
works for the editor example it far from complete to be used with an 
application which needs two way communication.

In the editor example we also have a requirement for two way communication.
Under the HELP menu there is an option to complete a partial CLIPS command. 
The editor needs to capture the partial string, open up a conversation link, 
transmit the information and wait for CLIPS to send back the completed string. 
The way that this is accomplished is the editor creates a "Command Complete" 
conversation topic and sends CLIPS the data. The editor then goes into a loop 
requesting data from CLIPS until CLIPS returns a result. The net result is the 
editor application blocks all processing until CLIPS completes. This is an 
effective method for some two way communication.

Some applications may have a need to go off and do some processing while CLIPS 
is executing. We have accomplished this using CLIPS user defined functions and 
Window timers which activate every so often to query CLIPS for data. The user 
defined functions are intended to be the vehicle for linking data between the 
CLIPS rules and the user's application via the DDEML connection. The user 
needs to be responsible for implementing some from of handshaking or semaphore 
so data which CLIPS produces is not overwritten before the requesting 
application has had a chance to receive it.

I hope this information helps.

Chris Ortiz
CLIPS Development Team


References:

Volume II CLIPS Advanced Programmers Guide
  Section 3 - Integrating CLIPS with External Functions.
  Section 7 - I/O Router System

Volume III CLIPS CLIPS Reference Manual
  Section 2 - CLIPS Windows Interface

Microsoft Windows Software Development Kit
  Programmer's Reference, Volume 1: Overview
   Chapter 5 - Dynamic Data Exchange Management Library

Programming Windows - Charles Petzold
  Chapter 5 - The Timer
