OpenersNotesSection(Spacer1)Details

MLGetByteString() allocates memory for the array of character codes. You must call (NonWLLink[MLReleaseByteString(), paclet:ref/c/MLReleaseByteString]) to disown this memory. If MLGetByteString() fails and the function's return value indicates an error, do not call (NonWLLink[MLReleaseByteString(), paclet:ref/c/MLReleaseByteString]) on the value contained in s.

MLGetByteString() is convenient in situations where no special characters occur.

The character codes used by MLGetByteString() are exactly the ones returned by ToCharacterCode in the Wolfram Language.

The array of character codes in MLGetByteString() is not terminated by a null character.

Characters such as newlines are specified by their raw character codes, not by ASCII forms such as ∖n.

MLGetByteString() returns immutable data.

MLGetByteString() 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 MLGetByteString() fails.

MLGetByteString() 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 a string encoded with codes from ToCharacterCode[] from a link */

void f(MLINK lp)
{
	const unsigned char *string;
	int length;

	if(! MLGetByteString(lp, &string, &length, 0))
		{
			/* unable to read the byte string from lp */
			return;
		}

	/* ... */

	MLReleaseByteString(lp, string, length);
}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(NonWLLink[MLReleaseByteString(), paclet:ref/c/MLReleaseByteString])  ▪  (NonWLLink[MLGetString(), paclet:ref/c/MLGetString])  ▪  (NonWLLink[MLGetUCS2String(), paclet:ref/c/MLGetUCS2String])  ▪  (NonWLLink[MLGetUTF8String(), paclet:ref/c/MLGetUTF8String])  ▪  (NonWLLink[MLGetUTF16String(), paclet:ref/c/MLGetUTF16String])  ▪  (NonWLLink[MLGetUTF32String(), paclet:ref/c/MLGetUTF32String])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Manipulating Expressions in External Programs, paclet:tutorial/ManipulatingExpressionsInExternalPrograms])}, {▪(RefLinkPlain[Handling Lists, Arrays and Other Expressions, paclet:tutorial/HandlingListsArraysAndOtherExpressions])}})}})