ObjectARX, AutoCAD. Среда программирования библиотеки C++


Типовое ObjectARX-приложение - часть 2

// add or delete functions.

// Declarations of other local functions:

void main _((int, char **));

int dofun _((void));

int funcload _((void));

ads_real rfact _((int x));

ads_real rsqr _((ads_real x));

// ACRXENTRYPOINT -- This function replaces main() for an ObjectARX

// program.

extern "C" AcRx::AppRetCode

acrxEntryPoint(AcRx::AppMsgCode msg, void* ptr)


switch(msg) {

case AcRx::kInitAppMsg:



case AcRx::kInvkSubrMsg:



case AcRx::kLoadADSMsg:



return AcRx::kRetOK;


// FUNCLOAD -- Define this application’s external functions.

// Return RTERROR on error, else RTNORM.

static int funcload()


int i;

for (i = 0; i < ELEMENTS(func_table); i++) {

if (!acedDefun(func_table[i].func_name, (short)i))

return RTERROR;


return RTNORM;


// DOFUN -- Execute external function (called upon an RQSUBR

// request). Return value from the function executed, RTNORM

// or RTERROR.

static int dofun()


struct resbuf *rb;

int val;

// Get the function code and check that it’s within range.

// (It can’t fail to be, but paranoia doesn’t hurt.)

if ((val = acedGetFunCode()) < 0 || val >= ELEMENTS(func_table))


acdbFail(/*MSG2*/"Received nonexistent function code.");

return RTERROR;


// Fetch the arguments, if any.

rb = acedGetArgs();

// Call the handler and return its success-failure status.

val = (*func_table[val].func)(rb);


return val;


// The code from the beginning of main() to here is UNCHANGED when

// you add or delete functions.

// FACT -- First set up the argument, then call the factorial

// function.

static int

fact(struct resbuf *rb)


int x;

if (rb == NULL)

return RTERROR;

if (rb->restype == RTSHORT) {

x = rb->resval.rint; // Save in local variable

} else {

acdbFail(/*MSG3*/"Argument should be an integer.");

return RTERROR;


if (x < 0) { // Check argument range

Содержание  Назад  Вперед