MLPutRawData (C 函数)
MLPutRawData 已经被 WSPutRawData 所取代.
int MLPutRawData(MLINK link, const unsigned char *d, int l)
把长为 l 字节的 d 中的原始字符数据或数值数据写入 link.
更多信息

- 使用 MLPutRawData() 以及 MLPutType() 和 MLPutRawSize() 手动把数据写入链接,而不是使用特定类型的 API 函数例如 MLPutInteger32() 或 MLPutUTF8String().
- 使用 MLPutRawData() 发送数值数据会绕过 MathLink 库的内部机理以确保数据在异种计算机系统间的兼容性. 为了使用该函数,用户需要考虑计算机系统间字节顺序和 C 类型大小的区别.
- 当使用 MLPutType() 发送字符数据,令牌自变量 WLTKOLDSTR 用于字符串数据或 WLTKOLDSYM 用于符号数据. 不要使用 MLPutRawData() 以任何除7位 ASCII 编码之外的格式发送字符数据.
- 当使用对于二进制数据具有正确令牌的 MLPutType() 发送数值数据,MathLink 标头文件 mathlink.h 包含这些令牌的完整列表,为方便起见,这里列出较常见的令牌:
-
unsigned char WLTK_CUCHAR short WLTK_CSHORT int WLTK_CINT long WLTK_CLONG float WLTK_CFLOAT double WLTK_CDOUBLE long double WLTK_CLONGDOUBLE - MLPutRawData() 在错误事件中返回0,如果函数成功则返回非零值.
- 如果 MLPutRawData() 失败,则使用 MLError() 检索错误代码.
- MLPutRawData() 在 MathLink 标头文件 mathlink.h 中被声明.
范例
基本范例 (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 */ }
}