明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2719|回复: 7

请帮我看看这个代码有什么问题?

[复制链接]
发表于 2005-1-10 23:22:00 | 显示全部楼层 |阅读模式
AcDbObjectId createLine()
{
AcGePoint3d startPoint(10.0,10.0,0.0);
AcGePoint3d endPoint(20.0,20.0,0.0);
AcDbLine *pLine=new AcDbLine(startPoint,endPoint);
AcDbBlockTable *pblocktable;
acdbCurDwg()->getBlockTable(pBlockTable,AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
pBlockTable->close();
AcDbObjectId lineId;
pBlockTableRecord->appendAcDbEntity(lineId,pLine);
pBlockTableRecord->close();
pLine->close() 编译时说:e:\ObjectARX 2004\ArxProject1\acrxEntryPoint.cpp(60): error C2601: “createLine” : 本地函数定义是非法的
发表于 2005-1-11 09:02:00 | 显示全部楼层
我把你的程序在ARX2002下面编译了一下,没有发现你说的错误提示,看看你的程序里面是否包含了头文件“migrtion.h”,把上面这段代码第六行和第七行的pblocktable和pBlockTable改一下,在代码的最后还应该加上一句return lineId;这样就OK了,我在AutoCAD2002下运行成功了,并得到了一条直线。
 楼主| 发表于 2005-1-11 15:47:00 | 显示全部楼层
// (C) Copyright 2002-2003 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
// //-----------------------------------------------------------------------------
//----- acrxEntryPoint.h
//-----------------------------------------------------------------------------
#include "StdAfx.h" //-----------------------------------------------------------------------------
#define szRDS _RXST("") //-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CArxProject2App : public AcRxArxApp { public:
CArxProject2App () : AcRxArxApp () {} virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
// TODO: Add your initialization code here return (retCode) ;
} virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;
// TODO: Add your code here AcDbObjectId CreateLine()
{
AcGePoint3d startPoint(10,10,0);
AcGePoint3d endPoint(20,20,0);
AcDbLine *pLine=new AcDbLine(startPoint,endPoint);
AcDbBlockTable *pBlockTable;
AcDbCurDwg()->GetBlockTable(pBlockTable,AcDbL::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
pBlockTable->close();
AcDbObjectId lineId;
pBlockTableRecord->appendAcDEntity(lineId,pLine);
pBlockTableRecord->close();
pLine->close();
return lineId;
}
return (retCode) ;
} virtual void RegisterServerComponents () {
}
// ----- ArxProject2.test command (do not rename)
static void ArxProject2test(void)
{
// Add your code for command ArxProject2.test here
}
} ; //-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CArxProject2App) ACED_ARXCOMMAND_ENTRY_AUTO(CArxProject2App, ArxProject2, test, MyCommand1, ACRX_CMD_TRANSPARENT, NULL)
上面是我的代码,有什么不对吗? 在VC.NET上写的2004ARX
发表于 2005-1-11 20:14:00 | 显示全部楼层
我用的是ARX2002,你可以参照ObjectARX2002\docsamps\ents看一下你的代码,或者把完整的程序传上来,我也比较菜,只看代码找不出原因在哪
发表于 2008-10-28 15:22:00 | 显示全部楼层
我和你的代码一样  出现的错误也差不多 为什么
发表于 2008-10-28 22:24:00 | 显示全部楼层

这应该是常规情况下类的成员函数不能用作函数指针的问题!你把 createLine()函数定义成静态函数(如:static void createLine()),注意,你若想定义成一个命令,不应有返回值,

另外:

ACED_ARXCOMMAND_ENTRY_AUTO(CArxProject2App, ArxProject2, test, MyCommand1, ACRX_CMD_TRANSPARENT, createLine【你原来是NULL】)

还有,代码里AcDbCurDwg()应该是别人定义一个返回当前数据库的函数,但却没有看到,应该用acdbHostApplicationServices()->workingDatabase()来替代。


发表于 2009-1-27 13:58:00 | 显示全部楼层

居然把代码放在卸载ARX函数里面????放在这里试试// TODO: Add your initialization code here

代码里AcDbCurDwg()应该是别人定义一个返回当前数据库的函数,但却没有看到,应该用acdbHostApplicationServices()->workingDatabase()来替代。  对的。。。。。

ACED_ARXCOMMAND_ENTRY_AUTO(CArxProject2App, ArxProject2, test, MyCommand1, ACRX_CMD_TRANSPARENT, createLine【你原来是NULL】)

对的。。。。。 

哈哈

发表于 2009-1-27 14:51:00 | 显示全部楼层

楼主说的对  注意字母的大小写!

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

本版积分规则

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

GMT+8, 2024-11-25 14:50 , Processed in 0.196081 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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