照搬照抄了一个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; } |