My C Function

LRESULT MyCFunction(returnValue, argument1,...)

void * const returnValue;
const void * const argument1;
...

The type definition LRESULT appears in mcadincl.h. MyCFunction is the actual code which executes the user function. Mathcad arguments and a pointer to a return value are passed to this function. It puts the result of the calculation in the return value.

Parameter

Description

returnValue

Points to a COMPLEXARRAY, a COMPLEXSCALAR , or a MCSTRING structure where the function result is to be stored. If you are implementing a Mathcad user function that returns a scalar, returnValue is a pointer to a COMPLEXSCALAR structure, as implemented by the struct LPCOMPLEXSCALAR construct in the mcadincl.h file.

argument1

Points to a read-only COMPLEXARRAY, COMPLEXSCALAR, or MCSTRING structure where the first function argument is stored. If you are implementing a Mathcad user function that has a scalar as its first argument, argument1 is a pointer to a LPCCOMPLEXSCALAR structure as implemented in the mcadincl.h file.

...

If you are implementing a Mathcad user function that has more than one argument, your MyCFunction will have additional arguments, each of which must be one of the types defined above and in the mcadincl.h file. The additional arguments will be pointers to the read-only structures where the data for the corresponding Mathcad user function argument is stored.

Parameter Requirements

The arrays and scalars that you can pass in and out of a user DLL are always complex, and arrays are always two dimensional. So remember to specifically strip off the real and complex parts of any scalar input values using the ParamName->real and ParamName->imag constructs. Arrays are indexed by column, then row, as opposed to the order of indices inside Mathcad (by row, then column). All arrays are assumed to have two dimensions; to reference a vector, you will still need the first array index (column) set to 0, for example:

Before manipulating an array, you'll first need to strip off the ArrayName->hReal[col][row] or ArrayName->hImag[col][row] parts, as defined in mcadincl.h.

Return value

MyCFunction should return 0 to indicate an error-free return. To indicate an error MyCFunction should return an error code in the low word of the returned LRESULT, and in the high word the number of the argument under which the error box should be placed. If the high word is zero the error message box is placed under the function itself. See the section on error handling to find out more about error codes.

Notes: