OpenersNotesSection(Spacer1)Details

MLGetData() does not allocate b; b must be provided.

MLGetData() returns 0 in the event of an error, and a nonzero value if the function succeeds.

Use (NonWLLink[MLError(), paclet:ref/c/MLError]) to retrieve the error code if MLGetData() fails.

MLGetData() is declared in the MathLink header file (RefLink[mathlink.h, paclet:ref/file/mathlink.h]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

#include "mathlink.h"

/* read data from a link in textual form */

void f(MLINK lp)
{
	int size, count;
	char *buff;

	switch(MLGetType(lp))
	{
		case MLTKSTR:
			if(! MLBytesToGet(lp, &size))
				{
					/* unable to read the number of bytes from lp */
					return;
				}

			buff = (char *)malloc(size * sizeof(char));
			if(buff == (char *)0)
				{
					/* unable to allocate mmemory */
					return;
				}

			if(! MLGetData(lp, buff, size &count))
				{
					/* unable to read the string data from lp */
					free(buff);
					return;
				}

			/* ... */

			free(buff);

			break;
	}

	/* ... */
}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(NonWLLink[MLGetType(), paclet:ref/c/MLGetType])  ▪  (NonWLLink[MLBytesToGet(), paclet:ref/c/MLBytesToGet])}})}})