请帮我看看这个代码有什么问题?
AcDbObjectId createLine()<BR> {<BR> AcGePoint3d startPoint(10.0,10.0,0.0);<BR> AcGePoint3d endPoint(20.0,20.0,0.0);<BR> AcDbLine *pLine=new AcDbLine(startPoint,endPoint);<BR> AcDbBlockTable *pblocktable;<BR> acdbCurDwg()->getBlockTable(pBlockTable,AcDb::kForRead);<BR> AcDbBlockTableRecord *pBlockTableRecord;<BR> pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);<BR> pBlockTable->close();<BR> AcDbObjectId lineId;<BR> pBlockTableRecord->appendAcDbEntity(lineId,pLine);<BR> pBlockTableRecord->close();<BR> pLine->close()编译时说:e:\ObjectARX 2004\ArxProject1\acrxEntryPoint.cpp(60): error C2601: “createLine” : 本地函数定义是非法的<BR> 我把你的程序在ARX2002下面编译了一下,没有发现你说的错误提示,看看你的程序里面是否包含了头文件“migrtion.h”,把上面这段代码第六行和第七行的pblocktable和pBlockTable改一下,在代码的最后还应该加上一句return lineId;这样就OK了,我在AutoCAD2002下运行成功了,并得到了一条直线。 // (C) Copyright 2002-2003 by Autodesk, Inc. <BR>//<BR>// Permission to use, copy, modify, and distribute this software in<BR>// object code form for any purpose and without fee is hereby granted, <BR>// provided that the above copyright notice appears in all copies and <BR>// that both that copyright notice and the limited warranty and<BR>// restricted rights notice below appear in all supporting <BR>// documentation.<BR>//<BR>// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. <BR>// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF<BR>// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. <BR>// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE<BR>// UNINTERRUPTED OR ERROR FREE.<BR>//<BR>// Use, duplication, or disclosure by the U.S. Government is subject to <BR>// restrictions set forth in FAR 52.227-19 (Commercial Computer<BR>// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)<BR>// (Rights in Technical Data and Computer Software), as applicable.<BR>//
//-----------------------------------------------------------------------------<BR>//----- acrxEntryPoint.h<BR>//-----------------------------------------------------------------------------<BR>#include "StdAfx.h"
//-----------------------------------------------------------------------------<BR>#define szRDS _RXST("")
//-----------------------------------------------------------------------------<BR>//----- ObjectARX EntryPoint<BR>class CArxProject2App : public AcRxArxApp {
public:<BR> CArxProject2App () : AcRxArxApp () {}
virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {<BR> AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;<BR> // TODO: Add your initialization code here
return (retCode) ;<BR> }
virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {<BR> AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;<BR> // TODO: Add your code here
AcDbObjectId CreateLine()<BR>{<BR> AcGePoint3d startPoint(10,10,0);<BR> AcGePoint3d endPoint(20,20,0);<BR> AcDbLine *pLine=new AcDbLine(startPoint,endPoint);<BR> AcDbBlockTable *pBlockTable;<BR> AcDbCurDwg()->GetBlockTable(pBlockTable,AcDbL::kForRead);<BR> AcDbBlockTableRecord *pBlockTableRecord;<BR> pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);<BR> pBlockTable->close();<BR> AcDbObjectId lineId;<BR> pBlockTableRecord->appendAcDEntity(lineId,pLine);<BR> pBlockTableRecord->close();<BR> pLine->close();<BR> return lineId;<BR>}<BR> return (retCode) ;<BR> }
virtual void RegisterServerComponents () {<BR> }
<BR> // ----- ArxProject2.test command (do not rename)<BR> static void ArxProject2test(void)<BR> {<BR> // Add your code for command ArxProject2.test here<BR> }<BR>} ;
//-----------------------------------------------------------------------------<BR>IMPLEMENT_ARX_ENTRYPOINT(CArxProject2App)
ACED_ARXCOMMAND_ENTRY_AUTO(CArxProject2App, ArxProject2, test, MyCommand1, ACRX_CMD_TRANSPARENT, NULL)<BR>
上面是我的代码,有什么不对吗?
在VC.NET上写的2004ARX 我用的是ARX2002,你可以参照ObjectARX2002\docsamps\ents看一下你的代码,或者把完整的程序传上来,我也比较菜,只看代码找不出原因在哪 我和你的代码一样出现的错误也差不多 为什么 <p>这应该是常规情况下类的成员函数不能用作函数指针的问题!你把 createLine()函数定义成静态函数(如:static void createLine()),注意,你若想定义成一个命令,不应有返回值,</p><p>另外:</p><p>ACED_ARXCOMMAND_ENTRY_AUTO(CArxProject2App, ArxProject2, test, MyCommand1, ACRX_CMD_TRANSPARENT, createLine【你原来是NULL】)</p><p>还有,代码里AcDbCurDwg()应该是别人定义一个返回当前数据库的函数,但却没有看到,应该用acdbHostApplicationServices()->workingDatabase()来替代。<br/><br/><br/></p> <p>居然把代码放在卸载ARX函数里面????放在这里试试// TODO: Add your initialization code here</p><p>代码里AcDbCurDwg()应该是别人定义一个返回当前数据库的函数,但却没有看到,应该用acdbHostApplicationServices()->workingDatabase()来替代。 对的。。。。。</p><p></p><p>ACED_ARXCOMMAND_ENTRY_AUTO(CArxProject2App, ArxProject2, test, MyCommand1, ACRX_CMD_TRANSPARENT, createLine【你原来是NULL】)</p><p>对的。。。。。 </p><p></p><p>哈哈<br/></p><p></p><p></p> <p>楼主说的对 注意字母的大小写!</p>
页:
[1]