beautypg.com

Excel:invoking crisp, Signals communications – Crunch CRiSP File Editor 6 User Manual

Page 86

background image

Page 86

Client Side operation

To make a client request, you need to create an IPC channel and specify the name of the service and topic
you wish to connect to. For example to connect to a WEB browser, you would use something like this:

int

ipc_id;

ipc_id = ipc_create(IPC_DDE, "NETSCAPE:WWW_OpenURL");

if (ipc_id >= 0) {

ipc_write(ipc_id, "http://www.crisp.com/");

}

If the specified service is not available then the ipc_create function will fail. Once the connection is open you
can use the ipc_write primitive to send commands to the remote server.

CRiSP DDE Server

CRiSP comes with an example macro, dde.cr, located in the CRiSP src\crunch directory which illustrates
the DDE mechanism and provides a useful mechanism within the editing environment.

This macro sets CRiSP up as a DDE server and allows you to send commands to CRiSP from other
programs and have CRiSP execute the commands as if you had typed them in to the Command: F10
macro prompt.

This feature is controlled by the CRiSP Server option in the Options

Startup menu.

CRiSP Sample source code

CRiSP comes with some sample source code to illustrate how to talk to a CRiSP DDE server (as
established by dde.cr). This code is located in the src\c\dde.c file and is a utility for talking to CRiSP from
the command line.

The tool allows you to specify, on the command line, one or more file names which are to be loaded into a
currently running CRiSP session. You can use a command line switch of +nn to indicate that the CRiSP is to
position the cursor on line nn of the next named file on the command line.

A precompiled binary is supplied in the bin.w32 directory for you to use.

{button See Also, ALink(ipc,,,)}

Using Excel to invoke CRiSP

You can use Excel or any other application which provides access to DDE in order to communicate with
CRiSP. This may not be the ideal way to communicate with CRiSP as their are real-time implications of
doing this: if CRiSP fails to respond in time for an application, it might time out. However, it can be very
useful for an application to be able to communicate with CRiSP, e.g. to pop up a file for
editing.

Excel:invoking CRiSP

This section shows how you can achieve this with Excel, as that is a popular application whose features and
mechanisms are shared with other Microsoft Office applications and for which the example is easy to
understand.

In order for Excel to communicate with CRiSP, you need to enable the CRiSP Server option available from
the Options

Startup menu. This causes CRiSP to create a service (CRISP) on startup ready to receive

messages from any application.

Excel provides a simple mechanism to invoke a DDE service using the format:

=SERVICE|COMMAND|item-name

In the case of CRISP, you would specify 'CRISP' for the service name, and 'command' for the command
name. The item-name field would correspond to the CRiSP macro you want to invoke, e.g. edit__file.

The return from this function is passed back to Excel, but the value may not be of any use - the value
depends on the macro you invoke, so you may need to write your own macro wrapper functions to pass
back meaningful status information.

Signals Communications

You can use the SIGUSR1 and SIGUSR2 signals under Unix to cause a callback routine to be called. This
use of signals is only available under Unix, since Windows does not support a useful signal based