求大侠相助!
IAcadApplication acadApp;<BR> acadApp.CreateDispatch(_T("AutoCAD.Application"));<BR> acadApp.SetVisible(TRUE);CString bscadPath;<BR> CString str;<BR> FindBScadPath(bscadPath);<BR> str=bscadPath+"BSbsCAD.arx";<BR> acadApp.LoadArx(str);
我的BSbsCAD.arx文件手动加载就好用,但用上面的程序加载就不好用!
说是:D:\Program Files\BSCAD\BSbsCAD.arx ARX命令中发生异常
未处理异常C0000005(Access Violation Reading 0xccccccd0),地址:6564E636h
我该怎么办啊?
谢谢!
回复
不是<FONT color=#0033ff><B>'不好用'</B></FONT>,是你的代码不对,造成AutoCAD异常退出.你安装了几个AutoCAD版本?
贴程序上来吧! 我只装了一个AutoCad2000
贴那个程序?是我的启动程序还是ARX程序? 楼上的大哥能不能说说造成这种错误的可能有那些? 你加载别的ARX程序试试看会不会出问题。 我重新做了一个简单的ARX程序,只是修改AutoCAd图标和标题,用上面的启动程序加载成功!
我详细说一下加载出错的ARX程序:
功能:用COM方法在AutoCAD菜单“窗口”后面添加了一个“。。”菜单。
点击菜单项从数据库中取数据然后画图。就这些!
现在的问题是:用上面的启动程序加载它后,菜单也添加上了,但同时出现
上面的错误!(在添加菜单前的 修改标题都已经修改了)。这些我都是在
InitApplication()中做的.
您觉得错误出在那?谢谢您! 你这个程序加载之后为什么就自动执行了?
你最好跟踪调试一下,没有代码我的经验还判断不出来具体的原因。
但是出现这种错误很可能是与AutoCAD数据库对象交互操作时出现了问题,比如说有的对象没有及时关闭,等等。 因为加载菜单是在InitApplication()中做的.,程序一加载就产生菜单。
我把我的InitApplication()函数贴出来:
void InitApplication()<BR>{<BR> // NOTE: DO NOT edit the following lines.<BR> //{{AFX_ARX_INIT<BR> AddCommand("BS", "DRAWDLG", "DRAWDLG", ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET, BSDrawDlg);<BR> //}}AFX_ARX_INIT<BR> //修改图标和标题<BR> CMDIFrameWnd *pp;<BR> pp=acedGetAcadFrame();<BR> pp->SetWindowText ("BSCAD2000"); <BR> HICON hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);<BR> pp->SetIcon(hIcon,FALSE);<BR> pp->UpdateWindow ();
//数据库连接字符串
m_strConnect="driver={SQL Server};Server=Ren;DATABASE=study;UID=sa";<BR> <BR> AfxOleInit(); //初始化<BR> BOOL Result;<BR> Result=m_adoConnection.Connect (LPCTSTR(m_strConnect),NULL);<BR> <BR> // TODO: add your initialization functions
//创建菜单的函数,下面有<BR> createSmartDrawMenu();
AcCmColor color;<BR> CString strLayername;<BR> //<BR> color.setColorIndex (5);<BR> strLayername="01";<BR> newLayer (strLayername,color);//自己写的建层函数,下面有<BR> //<BR> color.setColorIndex (6);<BR> strLayername="02";<BR> newLayer (strLayername,color);<BR> //<BR> color.setColorIndex (7);<BR> strLayername="03";<BR> newLayer (strLayername,color);<BR> //<BR> acdbLoadLineTypeFile ("CENTER","acadiso.lin",NULL); <BR> acdbLoadLineTypeFile ("PHANTOM","acadiso.lin",NULL);<BR> //<BR> color.setColorIndex (1);<BR> strLayername="05";<BR> newLayer (strLayername,color,"CENTER");<BR> //border<BR> color.setColorIndex (3);<BR> strLayername="06";<BR> newLayer (strLayername,color,"PHANTOM");<BR>}
//////////////////////////<BR>void newLayer( CString& layerName,AcCmColor color,CString linetypeName /* = "CONTINUOUS" */ )<BR>{<BR> AcDbLayerTable* pLayerTbl;<BR> acdbHostApplicationServices()->workingDatabase()->getSymbolTable( pLayerTbl,AcDb::kForWrite );<BR> <BR> if ( !pLayerTbl->has( layerName ) )<BR> {<BR> AcDbLayerTableRecord* pLayerTblRcd = new AcDbLayerTableRecord;<BR> pLayerTblRcd->setName( layerName );<BR> pLayerTblRcd->setIsFrozen( 0 ); <BR> pLayerTblRcd->setIsOff( 0 ); <BR> pLayerTblRcd->setVPDFLT( 0 ); <BR> pLayerTblRcd->setIsLocked( 0 ); <BR> <BR> // ²ãµÄÑÕÉ«<BR> pLayerTblRcd->setColor( color );<BR> <BR> // ÉèÖÃÏßÐÍ<BR> AcDbLinetypeTable* pLinetypeTbl;<BR> AcDbObjectId lineId;<BR> acdbHostApplicationServices()->workingDatabase()->getSymbolTable( pLinetypeTbl,AcDb::kForRead );<BR> if ( ( pLinetypeTbl->getAt( linetypeName,lineId ) ) != Acad::eOk )<BR> {<BR> pLinetypeTbl->getAt( "CONTINUOUS",lineId );<BR> }<BR> pLinetypeTbl->close();<BR> <BR> pLayerTblRcd->setLinetypeObjectId( lineId );<BR> pLayerTbl->add( pLayerTblRcd ); <BR> <BR> pLayerTblRcd->close();<BR> pLayerTbl->close();<BR> }<BR> else<BR> {<BR> pLayerTbl->close();<BR> }<BR>}<BR>///////////////////////////////////////////////////////////////////////
void createSmartDrawMenu ()<BR>{<BR> TRY<BR> {<BR> IAcadApplication bsApp(acedGetAcadWinApp()->GetIDispatch(true)); <BR> IAcadMenuBar bsMenuBar(bsApp.GetMenuBar ());<BR> long numberOfMenus;<BR> numberOfMenus = bsMenuBar.GetCount();<BR> <BR> IAcadMenuGroups bsMenuGroups(bsApp.GetMenuGroups ());<BR> <BR> VARIANT index;<BR> VariantInit(&index);<BR> index.vt=VT_I4;<BR> index.lVal=0;<BR> <BR> IAcadMenuGroup bsMenuGroup(bsMenuGroups.Item (index));<BR> IAcadPopupMenus bsPopupMenus(bsMenuGroup.GetMenus ());<BR> <BR> CString strMenuName="菜单名";<BR> <BR> VariantInit(&index);<BR> index.vt=VT_BSTR;<BR> index.bstrVal=strMenuName.AllocSysString ();<BR> <BR> IDispatch* pDisp=NULL;<BR> <BR> TRY<BR> {<BR> pDisp=bsPopupMenus.Item (index);<BR> pDisp->AddRef ();<BR> }<BR> CATCH(COleDispatchException,e)<BR> {}<BR> END_CATCH;<BR> <BR> <BR> if(pDisp==NULL)<BR> {<BR> //<BR> IAcadPopupMenu bsPopupMenu(bsPopupMenus.Add(strMenuName));<BR> <BR> int i=0;//<BR> VariantInit(&index);<BR> index.vt=VT_I4;<BR> index.lVal=i;<BR> bsPopupMenu.AddMenuItem (index,"画图(&D)...","_DRAWDLG\n");<BR> i++;<BR> <BR> pDisp=bsPopupMenu.m_lpDispatch;<BR> pDisp->AddRef ();<BR> }<BR> <BR> IAcadPopupMenu bsPopupMenu(pDisp);<BR> <BR> if(!bsPopupMenu.GetOnMenuBar ())<BR> {<BR> VariantInit(&index);<BR> index.vt=VT_I4;<BR> index.lVal=numberOfMenus-1;<BR> bsPopupMenu.InsertInMenuBar (index);<BR> }<BR> else<BR> {<BR> VariantInit(&index);<BR> index.vt=VT_BSTR;<BR> index.bstrVal=strMenuName.AllocSysString ();<BR> bsPopupMenus.RemoveMenuFromMenuBar (index);<BR> VariantClear(&index);<BR> }<BR> pDisp->Release ();<BR> }<BR> <BR> CATCH(COleDispatchException,e)<BR> {<BR> e->ReportError();<BR> e->Delete();<BR> }<BR> END_CATCH;<BR>} 发现:
我把程序中的newlayer()新建层函数去掉的话就没有异常了! 那你就继续跟踪一下newlayer()函数中各条语句的返回值情况,看具体是哪个地方产生了异常,下次再遇到这样的问题你就不会束手无策了。
页:
[1]
2