Custom Functions > Function Definitions > LRESULT
  
LRESULT
The type definition LRESULT appears in mcadincl.h. MyCFunction is the code that executes the custom function. PTC 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.
LRESULT MyCFunction(returnValue, argument1,...)
void * const returnValue;
const void * const argument1;
...
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 custom function that returns a scalar, returnValue is a pointer to a COMPLEXSCALAR structure, as implemented by the LPCOMPLEXSCALAR construct.
argument1
Points to a read-only COMPLEXARRAY, COMPLEXSCALAR, or MCSTRING structure where the first function argument is stored.
If you are implementing a custom function that has a scalar as its first argument, argument1 is a pointer to a LPCCOMPLEXSCALAR structure.
...
If you are implementing a custom function that has more than one argument, your MyCFunction will have additional arguments, each of which must be one of the types defined above. The additional arguments will be pointers to the read-only structures where the data for the corresponding custom function argument is stored.
Parameter Requirements
The arrays and scalars that you can pass in and out of a DLL file are always complex, and arrays are always two dimensional. You can access the real and complex parts of any scalar input value by using the ParamName->real and ParamName->imag members. Similarly, you can access the real and complex parts of any input array by using the Array->hReal and Array->hImag members. Arrays are indexed by column, then row, as opposed to the order of indices inside PTC Mathcad (by row, then column). All arrays are assumed to have two dimensions. To reference a vector, you set the first array index (column) to 0, for example:
ArrayName->hReal[0][row], or
ArrayName->hImag[0][row]
Return Value
MyCFunction returns 0 to indicate an error-free return. To indicate an error MyCFunction returns 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.
Additional Information
MyCFunction is a placeholder for the library-supplied function name. You can choose any name for your function, but you must register the address of your executable code with PTC Mathcad by setting the lpfnMyCFunction member of the FUNCTIONINFO structure.