WSGetNumberAsUCS2String (C 函数)

int WSGetNumberAsUCS2String(WSLINK l, const unsigned short **s, int *n)

读取由 l 指定的 WSTP 连接上的下一个数字,作为 UCS2 字符的一个字符串,表示存储在长度为 n 的字符串 s 中的数字值.

更多信息

  • WSGetNumberAsUCS2String() 可分配内存以储存字符串值. 可调用有 s 内容的 WSReleaseUCS2String() 来释放 WSGetNumberAsUCS2String() 分配的内存. 若 WSGetNumberAsUCS2String() 失败,则不要调用有 s 内容的 WSReleaseUCS2String().
  • 若发生错误,则 WSGetNumberAsUCS2String() 返回0;若成功,则返回非零值.
  • WSTP 的标头文件 wstp.h 已对 WSGetNumberAsUCS2String() 作出声明.

范例

基本范例  (1)

#include "wstp.h"

/* A function for reading an integer from a link */

void f(WSLINK l)
{
    switch(WSGetType(l))
    {
        case WSTKINT:
        {
            int rawType;
            rawType = WSGetRawType(l);
            if(rawType == WSTK_WSSHORT)
            {
                short theNumber;
                WSGetInteger16(l, &theNumber);
                /* ... */
            }
            else if(rawType == WSTK_WSINT)
            {
                int theNumber;
                WSGetInteger32(l, &theNumber);
                /* ... */
            }
            else
            {
                const unsigned short *theNumber;
                int length;
                WSGetNumberAsUCS2String(l, &theNumber, &length);
                /* ... */
                WSReleaseUCS2String(l, theNumber, length);
            }
        }
        break;
        case WSTKREAL:
            /* ... */
    }
}