明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1695|回复: 2

[求助][ARX]来看看代码,运行两次CAD就崩溃

[复制链接]
发表于 2006-11-20 16:46:00 | 显示全部楼层 |阅读模式

照搬照抄了一个addline的小程序,加载后在CAD中使用该命令绘制line后无显示,但命令行提示success,第二次使用后CAD崩溃,请教一下是怎么回事情,谢谢了,代码如下:

// ex03.cpp : 定义 DLL 应用程序的入口点。
//

#include "stdafx.h"
#include <adslib.h>
#include <rxdlinkr.h>
#include <aced.h>
#include <dbents.h>
#include <geassign.h>
#include <dbsymtb.h>
#include <dbapserv.h>
//-----------------------------------------------------------------------------
//----- DLL Entry Point
Acad::ErrorStatus
postToDatabase(AcDbEntity* pEnt,AcDbObjectId& idObj)
{
 Acad::ErrorStatus es;
 AcDbBlockTable* pBlockTable;
 AcDbBlockTableRecord* pSpaceRecord;
 if(acdbHostApplicationServices()->workingDatabase()==NULL)
  return Acad::eNoDatabase;
 if ((es=acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,AcDb::kForRead))==Acad::eOk)
 {
  if((es==pBlockTable->getAt(ACDB_MODEL_SPACE,pSpaceRecord,AcDb::kForWrite))==Acad::eOk)
  {
   if((es=pSpaceRecord->appendAcDbEntity(idObj,pEnt))==Acad::eOk)
    pEnt->close();
   pSpaceRecord->close();
  }
  pBlockTable->close();
 }
 return es;
}
//-----------------------------------------------------------------
Acad::ErrorStatus newLine()
{
 ads_point pt1,pt2;
 int retval;
 try
 {
  if((retval=acedGetPoint(NULL, "\nSelect lower left:",pt1))!=RTNORM)
   throw retval;
  if((retval=acedGetPoint(pt1,"\nSelect upper right:",pt2))!=RTNORM)
   throw retval;
 }
 catch (int e)
 {
  if(e==RTCAN)
   return Acad::eUserBreak ;
  if(e==RTERROR)
   return Acad::eInvalidInput ;
 }
 AcDbLine* pLine =new AcDbLine(asPnt3d(pt1),asPnt3d(pt2));
 if(!pLine)
 {
  acedAlert("Not enough memory to create a Line!");
  return Acad::eOutOfMemory ;
 }


 AcDbObjectId id;
 return postToDatabase(pLine,id);

}


//------------------------------------------------------------------------
void addLineCommand()
{
 if(newLine()==Acad::eOk)
  acutPrintf("Success\n");
 else
  acutPrintf("Failed\n");
}

//-------------------------------------------------------------------------

extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void*pkt)
{
 switch(msg)
 {
 case AcRx::kInitAppMsg:
  acrxDynamicLinker->unlockApplication(pkt);
  acrxDynamicLinker->registerAppMDIAware(pkt);
  //注册命令
  acedRegCmds->addCommand("EXAM03","addline","addline",ACRX_CMD_MODAL,addLineCommand);
  break;
 case AcRx::kUnloadAppMsg:
   acedRegCmds->removeGroup("EXAM03");
   break;
 }
 return AcRx::kRetOK;
}

//------------------------------------------------------------------------

BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
      )
{
    return TRUE;
}

发表于 2006-11-21 09:05:00 | 显示全部楼层
if((es==pBlockTable->getAt(ACDB_MODEL_SPACE,pSpaceRecord,AcDb::kForWrite))==Acad::eOk)
这句有问题
 楼主| 发表于 2006-11-21 10:27:00 | 显示全部楼层

if((es=pBlockTable->getAt(ACDB_MODEL_SPACE,pSpaceRecord,AcDb::kForWrite))==Acad::eOk)

多了一个=号,语法上检查不出来,谢谢了!

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 22:41 , Processed in 0.176185 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表