美文网首页
第十一章 创建Callout Library - 使用 J 链接

第十一章 创建Callout Library - 使用 J 链接

作者: Cache技术分享 | 来源:发表于2023-12-31 08:40 被阅读0次

    第十一章 创建Callout Library - 使用 J 链接类型传递标准计数字符串

    使用 J 链接类型传递标准计数字符串

    iris-callin.h 头文件定义了计数字符串结构 IRIS_EXSTR,表示标准 IRIS 字符串。此结构包含一个字符元素数组(8 位、16Unicode32wchar t)和一个指定数组中元素数量的 int 值(最多字符串长度限制):

    typedef struct {
       unsigned int   len;         /* length of string */
       union {
          Callin_char_t  *ch;      /* text of the 8-bit string */
          unsigned short *wch;     /* text of the 16-bit string */
          wchar_t        *lch;     /* text of the 32-bit string */
    /* OR unsigned short *lch   if 32-bit characters are not enabled */
       } str;
    } IRIS_EXSTR, *IRIS_EXSTRP;
    
    
    C Datatype Input In/Out Notes
    IRIS_EXSTR 1j or j 1J or J 8 位国家字符的标准字符串
    IRIS_EXSTR 2j or n 2J or N 16 位 Unicode 字符的标准字符串
    IRIS_EXSTR 4j 4J 32 位字符的标准字符串 wchar_t 字符

    IRIS_EXSTR 数据结构由 Callin API(低级 InterSystems 函数调用库)中的函数进行操作。有关详细信息,请参阅使用 Callin API 中的“Callin 函数参考”。尽管名称相似,Callin API$ZF标注接口是完全独立的产品)。

    以下函数用于创建和销毁 IRIS_EXSTR 实例:

    • IrisExStrNew[W][H] — 为字符串分配请求的存储量,并使用长度和指向该结构的值字段的指针填充 IRIS_EXSTR 结构。
    • IrisExStrKill — 释放与 IRIS_EXSTR 字符串关联的存储。

    这是一个 Callout 库,它使用所有三种链接类型来返回数字字符串:

    使用 J 连接传递字符串

    以下三个函数均生成一个随机整数,将其转换为最多包含 6 位数字的数字字符串,并使用 J 链接返回字符串 。

    #define ZF_DLL   // Required when creating a Callout library.
    #include <iris-cdzf.h>
    #include <stdio.h>
    #include <wchar.h>
    #include <iris-callin.h>
    
    int get_sample_L(IRIS_EXSTRP retval) {  // 8-bit characters
       Callin_char_t numstr[6];
       size_t len = 0;
       sprintf(numstr,"%d",(rand()%1000000));
       len = strlen(numstr);
       IRISEXSTRKILL(retval);
       if (!IRISEXSTRNEW(retval,len)) {return ZF_FAILURE;}
       memcpy(retval->str.ch,numstr,len);   // copy to retval->str.ch
       return ZF_SUCCESS;
    }
    
    int get_sample_LW(IRIS_EXSTRP retval) {  // 16-bit characters
       unsigned short numstr[6];
       size_t len = 0;
       swprintf(numstr,6,L"%d",(rand()%1000000));
       len = wcslen(numstr);
       IRISEXSTRKILL(retval);
       if (!IRISEXSTRNEW(retval,len)) {return ZF_FAILURE;}
       memcpy(retval->str.wch,numstr,(len*sizeof(unsigned short)));   // copy to retval->str.wch
       return ZF_SUCCESS;
    }
    
    int get_sample_LH(IRIS_EXSTRP retval) {  // 32-bit characters
       wchar_t numstr[6];
       size_t len = 0;
       swprintf(numstr,6,L"%d",(rand()%1000000));
       len = wcslen(numstr);
       IRISEXSTRKILL(retval);
       if (!IRISEXSTRNEW(retval,len)) {return ZF_FAILURE;}
       memcpy(retval->str.lch,numstr,(len*sizeof(wchar_t)));   // copy to retval->str.lch
       return ZF_SUCCESS;
    }
    
    ZFBEGIN
    ZFENTRY("GetSampleL","1J",get_sample_L)
    ZFENTRY("GetSampleLW","2J",get_sample_LW)
    ZFENTRY("GetSampleLH","4J",get_sample_LH)
    ZFEND
    

    注意:始终终止 IRIS_EXSTRP 输入参数 在前面的示例中,始终调用 IRISEXSTRKILL(retval) 以从内存中删除输入参数。即使参数不用于输出,也应该始终这样做。如果不这样做可能会导致内存泄漏。

    相关文章

      网友评论

          本文标题:第十一章 创建Callout Library - 使用 J 链接

          本文链接:https://www.haomeiwen.com/subject/yttyndtx.html