WSGetData (C 函数)

int WSGetData(WSLINK link,char *b,int len,int *count)

从由 link 指定的 WSTP 连接中获取文本数据,把结果存在最大长度为 len 的缓冲区 b 中,并把实际读取的字节数存在 count 中.

更多信息

  • WSGetData() 不分配 ;必须提供 .
  • 若发生错误,则 WSGetData() 返回0;若函数成功,则返回非零值.
  • WSGetData() 失败,则使用 WSError() 检索错误代码.
  • WSTP 的标头文件 wstp.h 已对 WSGetData() 作出声明.

范例

基本范例  (1)

#include "wstp.h"

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

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

    switch(WSGetType(lp))
    {
        case WSTKSTR:
            if(! WSBytesToGet(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(! WSGetData(lp, buff, size &count))
                {
                    /* unable to read the string data from lp */
                    free(buff);
                    return;
                }

            /* ... */

            free(buff);

            break;
    }

    /* ... */
}