<< >> Title Contents Index


Extending MathViews with DLLs


MathViews can be extended with user defined DLLs. The MathViews graphics engine, MATHSRV2.DLL, and the DDE engine, MATHVDDE.DLL, are examples of such extensions to the MathViews kernel, MATHSRV1.DLL.

The MathViews DLL interface allows you to add your own functions to MathViews and/or use MathViews as the controlling program in your application. You can use any compiler which produces Windows DLLs.

The user defined functions will be called with the same syntax as M-file functions, with parameters (variables, intermediate results) passed to and from the function via the interface described later. The functions can use a system of callbacks in order to take advantage of MathViews kernel capabilities.

Managing DLLs from MathViews:

In order to support DLL interface, the MathViews kernel supports the following underscore commands.

_loaddll dllname Load dllname.dll, making the functions it implements accessible to the MathViews user. _cleardll dllname Clear dllname and remove the functions it implements from MathViews' tables. _list(1) List all the DLLs currently loaded in MathViews. _list(1,'dllname') List all the functions that a loaded dllname.dll implements.

Creating MathViews DLLs

MathViews DLLs can be written using any language that supports Windows DLL. MathViews DLLs must export the following functions. Refer to the DLLINTER.h header file in the INCLUDE directory for definitions of all structures.

InitMathViewsDll

This function is called when MathViews is executing a _loaddll command.

int FAR PASCAL _export InitMathViewsDll(

MV_INTERFACE * mv,

char ***Names)

mv a pointer to an interface structure, containing information about MathViews, which the DLL needs for all subsequent callbacks. Names points to the variable in MathViews in which the DLL must store another pointer, which in turn points to the character array containing the DLL-defined function list. The sequence in which the function names are given determines the index MathViews will pass to the DLL when the functions are called.

ExecMathViewsDll

This function is called when MathViews is executing any of the DLL-defined functions.

int FAR PASCAL _export ExecMathViewsDll (

void * program,

int type,

int * nout,

Datum ** dat_out,

int nin,

Datum ** dat_in)

program a pointer, which is unique to each instance of MathViews, and which matches the pointer passed in the Interface structurewhen a call was made to InitMathViewsDll.

type the index of the DLL-defined function in the Names list specified by the DLL when handling InitMathViewsDll.

*nout a pointer to the number of output parameters. MathViews uses (*nout) to communicate to the DLL the number of return variables specified by the user. The DLL can change it to the number of actual values it returns.

dat_out a pointer to an array of output values. Initially the array contains (*nout) data of type UNDEF. The DLL should use them for its actual return values, or create more if needed, and store them in dat_out array.

nin the number of input parameters given by the user.

dat_in a pointer to an array of nin input parameters.

AbortMathViewsDll

This function is called if the user aborts MathViews while executing any of the DLL-defined functions. (This can happen only if that DDL-defined function has called MVYield.)

int FAR PASCAL _export AbortMathViewsDll

(void * program)

CloseMathViewsDll

This function is called when MathViews is executing _cleardll or the MathViews application is being closed.

int FAR PASCAL _export CloseMathViewsDll

(void * program)

Calling MathViews from the DLL

The DLL can use MathViews services by executing callbacks, that is, calling MathViews functions by their pointers.

A list of such pointers is passed in the Interface structure on a call to InitMathViewsDll. All callbacks must pass a pointer, p, unique to each instance of MathViews, which was previously passed to the DLL in the Interface structure.

Refer to the DLLINTER.h header file in the INCLUDE directory for definitions of all structures.

MVNewDatum

Create a new Datum with type UNDEF.

Datum * MVNewDatum

(void * p)

return value the pointer to the new Datum.

MVDelDatum

Delete a Datum.

void MVDelDatum (

void * p,

Datum * d)

d pointer to the Datum to be deleted. The Datum must be previously allocated with a call to MVNewDatum.

MVNewArray

Create a new real or complex AllArray, with a given number of rows and columns.

Note

The array is stored column-wise.

AllArray * MVNewArray (

void * p,

int type, int m,

int n)

type REAL_TYPE if array should be real, COMPLEX_TYPE otherwise.

m the desired number of rows.

n the desired number of columns.

return value a pointer to the new array.

MVDelArray

Delete an AllArray.

void MVDelArray (

void * p,

AllArray * a)

a a pointer to the array to be deleted.

MVGetGlobal

Get the value of a MathViews variable.

Datum * MVGetGlobal (

void * p,

char * VarName)

VarName the name of the variable.

return value a pointer to the Datum with the variable's value.

MVSetGlobal

Set the value of a MathViews variable.

void MVSetGlobal (

void * p,

char * VarName,

Datum * value)

VarName the name of the variable.

value pointer to the Datum containing the value of the variable.

MVFeval

Evaluate a MathViews function (such as sin, max, +, ...)

Caution

This function is very powerful. It should be used carefully, because it can damage the MathViews internal stackwith unpredictable results.

void MVFeval (

void * p,

char * func, int * nout,

Datum ** dat_out,

int nin, Datum * dat_out)

func the function to be evaluated.

nout a pointer to the number of output parameters the DLL expects.

dat_out a pointer to an array of return values, which MathViews will supply upon completion.

nin number of input parameters the DLL sends MathViews.

dat_in a Datum array containing nin input values.

MVEval

Evaluate a string expression as though it were typed by the MathViews user.

Datum * MVEval

(void * p, char * expr)

expr the expression to be evaluated.

return value the result of the evaluation, if there is one.

MVArrayInfo

Get information about type, size and data of an array.

void MVArrayInfo (

void * p,

AllArray * a,

double ** pval,

int * ptype,

int * pm, int * pn)

a a pointer to the AllArray to be analyzed. (input)

pval pval is a pointer that points to a Mathviews-supplied data pointer. (output)

Note

The array is stored column-wise.

ptype a pointer to the array type. The type can be either REAL_TYPE or COMPLEX_TYPE. (output)

pm a pointer to the number of rows supplied by MathViews. (output)

pn a pointer to the number of columns supplied by MathViews. (output)

MVPrint

Display a message on MathViews' Output window.

void MVPrint

(void * p, char * message)

message the text to be displayed.

MVError

Notify MathViews of an error condition.

void MVError

(void * p, int code, char * message)

code a valid MathViews error code, defining a specific error message. (A value of 4 defines a blank. If 4 is used, only the text in message will be displayed.)

message extra text to be added to the error message. (If code is less than zero, the message will be displayed, text defined by abs(code).

MVYield

Yield control to Windows, so that all pending messages can be processed. MathViews can send the DLL an abort request. Caution: be sure to yield control only in places where abort cannot create problems.

void MVYield

(void * p)

References

Maximizing Windows

Jim Boyce

Dynamic Data Exchange

New Writers Publishing

Windows Software Development Kit

Dynamic Data Exchange

Microsoft Corporation

Programming Windows

Charles Petzold

Microsoft Press


<< >> Title Contents Index