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

MLUserData()

void * MLUserData(MLINK link, MLUserFunction *fp)
returns the data object and function pointer installed by MLSetUserData().
  • MLUserData() is declared in the MathLink header file mathlink.h.
#include <stdlib.h>
#include "mathlink.h"

typedef struct foo_ {
    int member;
} foo;


int main(int argc, char **argv)
{
    MLENV env;
    MLINK link;
    int error;
    foo *fobj;

    fobj = (foo *)malloc(sizeof(foo));
    if(fobj (foo *)0)
        { /* unable to allocate memory for foo object */ }

    env = MLInitialize((char *)0);
    if(env (MLENV)0)
        { /* unable to initialize MathLink environment */ }

    link = MLOpenArgcArgv(env, argc, argv, &error);
    if(link (MLINK)0 || error MLEOK)
        { /* unable to create link object */ }

    MLSetUserData(link, (void *)fobj, (MLUserFunction)0);

    /* ... */

    fobj = MLUserData(link, (MLUserFunction *)0);

    free(fobj);

    MLClose(link);
    MLDeinitialize(env);

    return 0;
}