CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

列表和其他动态分配的数据

2022-12-31 23:53| 发布者: admin| 查看: 232| 评论: 0|来自: AutoCAD

resbuf 结构包含一个指针字段,用于将结果缓冲区链接到列表中。可以通过在应用程序中声明结果缓冲区来静态分配结果缓冲区。当仅使用单个结果缓冲区(例如 byand)或只需要一个短列表时,可以执行此操作。但是,通过动态分配较长的列表更容易处理,并且 ObjectARX 函数返回的列表始终是动态分配的。返回链表的最常用函数之一是。rbnextacedGetVar()acedSetVar()acedGetArgs()

评估外部函数显示了外部子例程的 AutoLISP 调用格式,该子例程采用三种不同类型的参数:字符串、整数和实值:

(doit pstr iarg rarg)

以下代码段演示如何使用此类调用序列实现函数。示例函数检查参数列表是否正确,并在对值进行操作之前在本地保存这些值(未显示操作)。该示例假定先前的调用已为外部子例程分配了函数代码 0,并且此应用程序定义的所有函数都至少采用一个参数:acedDefun()

// Execute a defined function.  
int dofun() 
{ 
    struct resbuf *rb; 
    char str[64]; 
    int ival, val; 
    ads_real rval; 
    ads_point pt; 
// Get the function code.  
    if ((val = acedGetFuncode()) == RTERROR) 
        return BAD; // Indicate failure.  
    // Get the arguments passed in with the function.  
    if ((rb = acedGetArgs()) == NULL) 
        return BAD; 
    switch (val) { // Which function is called?  
    case 0: // (doit)  
        if (rb->restype != RTSTR) { 
            acutPrintf("\nDOIT called with %d type.", 
                rb->restype); 
            acutPrintf("\nExpected a string."); 
            return BAD; 
        } 
// Save the value in local string.  
        strcpy(str, rb->resval.rstring); 
// Advance to the next result buffer.  
        rb = rb->rbnext; 
        if (rb == NULL) { 
            acutPrintf("\nDOIT: Insufficient number of 
                arguments."); 
            return BAD; 
        } 
        if (rb->restype != RTSHORT) { 
            acutPrintf("\nDOIT called with %d type.", 
                rb->restype); 
            acutPrintf("\nExpected a short integer."); 
            return BAD; 
        } 
// Save the value in local variable.  
        ival = rb->resval.rint; 
// Advance to the last argument.  
        rb = rb->rbnext; 
        if (rb == NULL) { 
            acutPrintf("\nDOIT: Insufficient number of 
                arguments."); 
            return BAD; 
        } 
        if (rb->restype != RTREAL) { 
            acutPrintf("\nDOIT called with %d type.", 
                rb->restype); 
            acutPrintf("\nExpected a real."); 
            return BAD; 
        } 
// Save the value in local variable.  
        rval = rb->resval.rreal; 
// Check that it was the last argument. 
        if (rb->rbnext != NULL) { 
                acutPrintf("\nDOIT: Too many arguments."); 
            return BAD; 
        } 
// Operate on the three arguments.  
        . . . 
        return GOOD;  // Indicate success  
        break; 
    case 1: 
// Execute other functions. 
        . . . 
    } 
} 
注意:此示例在一个方面非常出色:是唯一返回应用程序不必显式释放的链表的 ObjectARX 全局函数。以下部分介绍管理列表所需内存的常用方法。acedGetArgs()

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 13:59

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部