OpenersNotesSection(Spacer1)Details

Use MLPutRawData() in conjunction with (NonWLLink[MLPutType(), paclet:ref/c/MLPutType]) and (NonWLLink[MLPutRawSize(), paclet:ref/c/MLPutRawSize]) to manually put data to a link rather than using the type-specific API functions such as (NonWLLink[MLPutInteger32(), paclet:ref/c/MLPutInteger32]) or (NonWLLink[MLPutUTF8String(), paclet:ref/c/MLPutUTF8String]).

Sending numerical data with MLPutRawData() bypasses the MathLink library's internal mechanisms for ensuring data compatibility between heterogenous computer systems. To use this function, users will need to account for endianness and C-type size differences between computer systems.

When sending character data use (NonWLLink[MLPutType(), paclet:ref/c/MLPutType]) with the token argument MLTKOLDSTR for string data or MLTKOLDSYM for symbol data. Do not use MLPutRawData() to send character data in any format other than 7-bit ASCII encoding.

When sending numerical data use (NonWLLink[MLPutType(), paclet:ref/c/MLPutType]) with the correct token for the binary data. The MathLink header file (RefLink[mathlink.h, paclet:ref/file/mathlink.h]) contains the complete list of these tokens, but the more common tokens are listed here for convenience:

MLPutRawData() returns a 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 MLPutRawData() fails.

MLPutRawData() 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"

/* send a function as raw data to a link */

void f(MLINK lp)
{
	int a = 2, b = 3;

	if(! MLPutType(lp, MLTKFUNC))
		{ return; /* unable to put the function type to lp */ }

	if(! MLPutArgCount(lp, 2))
		{ return; /* unable to put the number of arguments to lp */ }

	if(! MLPutType(lp, MLTKOLDSYM))
		{ return; /* unable to put function head type to lp */ }
	
	if(! MLPutRawSize(lp, 4))
		{ return; /* unable to put the size of the symbol to lp */ }

	if(! MLPutRawData(lp, (const unsigned char *)"Plus", 4))
		{ return; /* unable to put the raw bytes to lp */ }

	if(! MLPutType(lp, MLTK_CINT))
		{ return; /* unable to put the argument type to lp */ }

	if(! MLPutRawSize(lp, sizeof(int)))
		{ return; /* unable to put the size of the integer to lp */ }

	if(! MLPutRawData(lp, (const unsigned char *)&a, sizeof(a)))
		{ return; /* unable to put the raw bytes of a to lp */ }

	if(! MLPutType(lp, MLTK_CINT))
		{ return; /* unable to put the second argument type to lp */ }

	if(! MLPutRawSize(lp, sizeof(int)))
		{ return; /* unable to put the size of the integer to lp */ }

	if(! MLPutRawData(lp, (const unsigned char *)&b, sizeof(b)))
		{ return; /* unable to put the raw bytes of b to lp */ }
}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(NonWLLink[MLPutNext(), paclet:ref/c/MLPutNext])  ▪  (NonWLLink[MLPutType(), paclet:ref/c/MLPutType])  ▪  (NonWLLink[MLPutRawSize(), paclet:ref/c/MLPutRawSize])  ▪  (NonWLLink[MLPutArgCount(), paclet:ref/c/MLPutArgCount])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Manipulating Expressions in External Programs, paclet:tutorial/ManipulatingExpressionsInExternalPrograms])}})}})