明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 947|回复: 0

arx 工程在特定的文件出错

[复制链接]
发表于 2014-8-18 16:31 | 显示全部楼层 |阅读模式
本帖最后由 zdqwy19 于 2014-8-18 16:51 编辑

acrxEntryPoint.cpp文件
  1. // (C) Copyright 2002-2012 by Autodesk, Inc.
  2. //-----------------------------------------------------------------------------
  3. //----- acrxEntryPoint.cpp
  4. //-----------------------------------------------------------------------------
  5. #include "StdAfx.h"
  6. #include "resource.h"
  7. #include "CreateEnt.h"
  8. #include "ModifyEnt.h"
  9. #include <vector>
  10. #pragma once;
  11. using namespace std;

  12. //-----------------------------------------------------------------------------
  13. #define szRDS _RXST("")

  14. //-----------------------------------------------------------------------------
  15. //----- ObjectARX EntryPoint
  16. class CtxbhApp : public AcRxArxApp {

  17. public:
  18.   CtxbhApp () : AcRxArxApp () {}

  19.   virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
  20.     // TODO: Load dependencies here

  21.     // You *must* call On_kInitAppMsg here
  22.     AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
  23.    
  24.     // TODO: Add your initialization code here

  25.     return (retCode) ;
  26.   }

  27.   virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
  28.     // TODO: Add your code here

  29.     // You *must* call On_kUnloadAppMsg here
  30.     AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;

  31.     // TODO: Unload dependencies here

  32.     return (retCode) ;
  33.   }

  34.   virtual void RegisterServerComponents () {}

  35.   static void MyGroup_test () {
  36.     // Put your command code here
  37.     AcGePoint3d pt(0,0,0);
  38.     vector<AcGePoint3d> pts;
  39.     for(int i=0;i<12360;++i)
  40.     {
  41.       pts.push_back(pt);
  42.       pt.x+=10;
  43.       pt.y+=10;
  44.     }
  45.     int bstart=1;
  46.     for(vector<AcGePoint3d>::iterator j=pts.begin();j!=pts.end();++j)
  47.     {
  48.       ACHAR str[10];
  49.       AcDbObjectId textId;
  50.       acdbRToS(bstart,-1,-1,str);
  51.       textId = CCreateEnt::CreateText((*j),str,7);
  52.       CModifyEnt::ChangeColor(textId, 3);
  53.       CModifyEnt::ChangeWidthFactor(textId, 0.7);
  54.       bstart=bstart+1;
  55.     }
  56.   }
  57.   
  58.   
  59. } ;

  60. //-----------------------------------------------------------------------------
  61. IMPLEMENT_ARX_ENTRYPOINT(CtxbhApp)

  62. ACED_ARXCOMMAND_ENTRY_AUTO(CtxbhApp, MyGroup, _test, test, ACRX_CMD_MODAL, NULL)
CreateEnt.h文件
  1. #include "StdAfx.h"
  2. #pragma once


  3. // CCreateEnt


  4. class CCreateEnt
  5. {
  6. public:
  7.   // 在模型空间添加实体;
  8.   static AcDbObjectId PostToModelSpace(AcDbEntity* pEnt);
  9.   //写入单行文字;
  10.   static AcDbObjectId CreateText(const AcGePoint3d& ptInsert,const ACHAR* text,double height);

  11.   CCreateEnt();
  12.   virtual ~CCreateEnt();
  13. };
复制代码
CreateEnt.cpp文件
  1. #include "StdAfx.h"
  2. // CreateEnt.cpp : 实现文件;
  3. //

  4. #include "stdafx.h"
  5. #include "CreateEnt.h"


  6. // CCreateEnt
  7.   // 将实体添加到图形数据库的模型空间;
  8. AcDbObjectId CCreateEnt::PostToModelSpace(AcDbEntity* pEnt)
  9. {
  10.   AcDbBlockTable *pBlockTable;
  11.   acdbHostApplicationServices()->workingDatabase()
  12.     ->getBlockTable(pBlockTable, AcDb::kForRead);
  13.   AcDbBlockTableRecord *pBlockTableRecord;
  14.   pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
  15.     AcDb::kForWrite);
  16.   AcDbObjectId entId;
  17.   pBlockTableRecord->appendAcDbEntity(entId, pEnt);
  18.   pBlockTable->close();
  19.   pBlockTableRecord->close();
  20.   pEnt->close();
  21.   return entId;
  22. }
  23. // 写入单行文字;
  24. AcDbObjectId CCreateEnt::CreateText(const AcGePoint3d& ptInsert,const ACHAR* text,double height)
  25. {
  26.   AcDbObjectId style = AcDbObjectId::kNull;
  27.   double rotation = 0;
  28.   AcDbText *pText =new AcDbText(ptInsert,text,style,height,rotation);
  29.   return CCreateEnt::PostToModelSpace(pText);
  30. }
  31. CCreateEnt::CCreateEnt(){}

  32. CCreateEnt::~CCreateEnt(){}



  33. // CCreateEnt 消息处理程序;

复制代码
ModifyEnt.h文件
  1. #include "StdAfx.h"
  2. #pragma once


  3. // CModifyEnt


  4. class CModifyEnt
  5. {
  6. public:
  7.   static Acad::ErrorStatus ChangeColor(AcDbObjectId entId, Adesk::UInt16 colorIndex);//更改实体颜色;
  8.   static Acad::ErrorStatus ChangeWidthFactor(AcDbObjectId entId, double WidthFactor);//更改文字宽高比;
  9.   CModifyEnt();
  10.   virtual ~CModifyEnt();
  11. };

复制代码
ModifyEnt.cpp文件
  1. // ModifyEnt.cpp : 实现文件;
  2. //

  3. #include "stdafx.h"
  4. #include "ModifyEnt.h"


  5. // CModifyEnt
  6.   //更改实体颜色;
  7. Acad::ErrorStatus CModifyEnt::ChangeColor(AcDbObjectId entId, Adesk::UInt16 colorIndex)
  8. {
  9.   AcDbEntity *pEntity;
  10.   // 打开图形数据库中的对象;
  11.   acdbOpenObject(pEntity, entId, AcDb::kForWrite);
  12.   // 修改实体的颜色;
  13.   pEntity->setColorIndex(colorIndex);
  14.   // 用完之后,及时关闭;
  15.   pEntity->close();
  16.   return Acad::eOk;
  17. }
  18. //更改文字宽高比;
  19. Acad::ErrorStatus CModifyEnt::ChangeWidthFactor(AcDbObjectId entId, double WidthFactor)
  20. {
  21.   AcDbEntity *pEntity;
  22.   // 打开图形数据库中的对象;
  23.   acdbOpenObject(pEntity, entId, AcDb::kForWrite);
  24.   // 修改文字宽高比;
  25.   if(pEntity->isKindOf(AcDbText::desc()))
  26.   {
  27.     AcDbText *pText = AcDbText::cast(pEntity);
  28.     pText->setWidthFactor(WidthFactor);
  29.   }
  30.   // 用完之后,及时关闭;
  31.   pEntity->close();
  32.   return Acad::eOk;
  33. }

  34. CModifyEnt::CModifyEnt()
  35. {

  36. }

  37. CModifyEnt::~CModifyEnt()
  38. {
  39. }


  40. // CModifyEnt 消息处理程序;

复制代码
上面5段代码合在一起的压缩文件:

用于测试的图形

     现在是这样情况,我手头三台电脑:
1、安装win7x64+cad2014;
2、安装win7x86+cad2007;
3、安装winXPx86+cad2008;
三台电脑在新建的空白文件上运行上述代码都没有问题;1#机在test.dwg中运行上述代码也没有问题;2#机和3#机在test.dwg中运行上述代码就引起cad崩溃,提示acad.exe缓冲区溢出。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

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

本版积分规则

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

GMT+8, 2024-4-24 03:27 , Processed in 0.397542 second(s), 34 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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