This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
MathLink C Function

MLEvaluateString()

int MLEvaluateString(MLINK link, char *string)
sends a string to Mathematica for evaluation, and discards any packets sent in response.
  • The code for MLEvaluateString() is not included in the MathLink library, but is generated automatically by mcc or mprep in processing MathLink template files.
  • MLEvaluateString(lp, "Print[\"string\"]") will cause string to be printed in a Mathematica session at the other end of the link.
  • MLEvaluateString() is only available for use in mprep MathLink template programs.
  • MLEvaluateString() returns 0 on failure and a nonzero value on success.
  • MLEvaluateString() is declared in the MathLink header file mathlink.h.
:Begin:
:Function: f
:Pattern: KernelTime[]
:Arguments: {}
:ArgumentTypes: Manual
:ReturnType: Manual
:End:

#include "mathlink.h"

/* read the Kernel's response from evaluating the expression
{Date[],$TimeZone} */

void f(void)
{
    /* Pretend we are not in our local timezone. */
    if(! MLEvaluateString(stdlink, "$TimeZone = 9;"))
        { /* unable to send $TimeZone = 9; to stdlink */ }

    if(! MLEvaluate(stdlink, "{Date[],$TimeZone}"))
        { /* unable to send the expression to stdlink */ }

    /* get the Kernel's response */
    switch(MLGetType(stdlink))
    {
        /* ... */
    }

    /* ... */    
}