skyawa 发表于 2005-8-21 23:42:00

求问高手,关于executeInApplicationContext函数

<P>void LoadTemplate(void * pData)<BR>{<BR>&nbsp; AcApDocument* pDoc = acDocManager-&gt;curDocument();<BR>&nbsp; if (acDocManager-&gt;isApplicationContext())<BR>&nbsp; {<BR>&nbsp;&nbsp; acDocManager-&gt;appContextNewDocument((const char *)pData);<BR>&nbsp; }<BR>&nbsp; else<BR>&nbsp;&nbsp; acutPrintf("Err To Create Doc!\\n");<BR>}</P>
<P>void xxxx(){</P>
<P>CString templPath = "";<BR>&nbsp;templPath = m_arxPath + "模板\\模板.dwt";</P>
<P>char * pData = templPath.GetBuffer(templPath.GetLength());<BR>&nbsp;acDocManager-&gt;executeInApplicationContext(LoadTemplate,(void *)pData);<BR>}</P>
<P>这样从模板打开一个了一个新文档,但是程序环境从此好像跳出了文档环境。获取的活动文档还是前一个文档,而且还有很多问题,连arx本身都无法卸载了。我想问问大家都是怎么处理打开和关闭文档的。怎么把上下文环境还给文档。难道只能用非模态对话框来处理。docman里的东西我也看了,根据arx的帮助,appContextNewDocument只能给com或非模态对话框使用??帮忙给推荐一个方法能打开和保存文件。</P>

skyawa 发表于 2005-8-24 02:47:00

<P>弄懂了一点。。我的整个程序工作在一个文档范围的命令里,一个命令只能操作一个文档。汗`~~~,无论怎么执行,该命令停留在前一个文档里,除非命令结束。新打开的文档只能用数据库方式处理。(能不能用windows消息再打开一个命令处理新打开的文档??)</P>
<P>我后来又使用了程序范围的命令。更古怪的事情发生了,只要执行程序范围的命令,当前文档的resouce就不见了,意味着点击新建菜单工具条就出现致命错误。后来我又写了反应器把文档资源压栈出栈才勉强保证不出错了。为什么arx支持程序范围命令,却不把这种命令做的好用点。</P>
<P>各位ARX高手,能不能指点一下我理解中的错误。新学CAD开发,问题很多。</P>

skyawa 发表于 2005-8-24 09:11:00

<P>老外就是凶哦,原来是2004arx的bug,程序范围的命令会导致资源失效,我的解决办法比较牵强。以下是从autodesk找来的。</P>
<P>I am having a problem with the code created by the ObjectARX wizard. <BR>I register a command with ACRX_CMD_SESSION. My test command does nothing, but after it runs I can do everything except open another drawing. When I close all drawings the Open Toolbar is not there. It comes up with a dialog box that says <BR>FATAL ERROR: Unhandled Access Violation Reading 0x0002 Exception at 7c18aacah<BR><BR>Thanks,<BR><BR>Justin </P>
<P>/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</P>
<P>Hi Justin,<BR>I had the same problem, here is what i get.<BR>Regards, Petra<BR><BR>-----------------------------------<BR>The problem is similar to one that was reported before for similar<BR>behavior with appContextOpenDocument and a Change Request was logged.<BR>However it turns out that the problem has more to do with the code<BR>generated by the ObjectARX wizard than AutoCAD itself.<BR><BR>The work around is to remove the following line in the<BR>acrxEntrypPint.cpp<BR>ACED_ARXCOMMAND_ENTRY_AUTO(CtestnewsyncdocApp, GIPS, testnewsyncdoc,<BR>test, ACRX_CMD_MODAL, NULL)<BR><BR>and then add the following in the On_kInitAppMsg():<BR><BR>virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {<BR>AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;<BR>acedRegCmds-&gt;addCommand( "GIPS",<BR>"testopensyncdoc",<BR>"test",<BR>ACRX_CMD_MODAL ,<BR>GIPStestnewsyncdoc);<BR><BR>return (retCode) ;<BR>}<BR>-----------------------------------<BR>This is a follow up to my last reply. Here is a better work around that<BR>does not break the wizards. (thanks Cyrille)<BR><BR>The bug in AutoCAD is that AutoCAD assumes its own resource handle is<BR>always set when an API is called. So AutoCAD tries to load one of its<BR>strings or dialog templates from the ARX application resource rather than<BR>its own resource file. This indeed fails or succeeds but with the wrong<BR>stuff. In any case, that will result in a crash sooner or later.<BR><BR>In your application which does not include MFC support do the following:<BR>**** Use ACED_ARXCOMMAND_ENTRY_AUTO(CtestnewsyncdocApp, GIPS,<BR>testnewsyncdoc, test, ACRX_CMD_MODAL, NULL)<BR><BR>declare this in StdAfx.h<BR>HINSTANCE acedGetAcadResourceInstance () ;<BR>(it is declared in rxmfcapi.h but you cannot include that file in non MFC<BR>application, so you need to do it by hand)<BR><BR>Then use the acDocManager API<BR>static void AsdkArxProject4_MyCommand1 (void) {<BR>acDocManager-&gt;pushResourceHandle (acedGetAcadResourceInstance ()) ;<BR>... acDocManager-&gt;popResourceHandle () ;<BR>}<BR>****<BR><BR>I changed your project to the following and the crash is resolved:<BR>****<BR>//wb added this to StdAfx.h<BR>HINSTANCE acedGetAcadResourceInstance () ;<BR><BR><BR>// ----- GIPStestnewsyncdoc.testnewsyncdoc command (do not rename)<BR>static void GIPStestnewsyncdoc(void)<BR>{<BR>//wb added this<BR>acDocManager-&gt;pushResourceHandle (acedGetAcadResourceInstance ()) ;<BR><BR>static char pData[] = "acad.dwt";<BR>AcApDocument* pDoc = acDocManager-&gt;curDocument();<BR>if (pDoc) {<BR>acutPrintf("\nCurrently in Document context : %s, Switching to<BR>App.\n",pDoc-&gt;fileName());<BR>acDocManager-&gt;executeInApplicationContext(newSyncDocHelper, (void<BR>*)pData);<BR>}<BR><BR>//wb added this<BR>acDocManager-&gt;popResourceHandle () ;<BR><BR>}<BR>****<BR><BR>If you have a project that includes MFC support then you can do the<BR>following:<BR>****<BR>Restore the AutoCAD resource handle in the command implementation by<BR>adding<BR>AfxSetResourceHandle (acedGetAcadResourceInstance ()) to the beginning of<BR>the command:<BR><BR>static void GIPS_testnewsyncdoc () {<BR>AfxSetResourceHandle (acedGetAcadResourceInstance ()) ;<BR>...<BR>}<BR>This does not break the wizard and it is compatible with the AutoCAD<BR>2005 code fix. It is also more simple to implement.<BR>****<BR><BR>Cheers,<BR>autodesk Wayne Brill<BR>Developer Technical Services</P>

easypower 发表于 2009-4-28 23:07:00

<p>FATAL ERROR: Unhandled Access Violation Reading 0x0002 Exception at 7c18aacah</p><p>遇到同样的问题</p><p>感谢</p><p>1、修改命令方式为ACRX_CMD_SESSION</p><p>2、换06的sdk</p>

cad新学生 发表于 2009-11-21 20:37:00

<p>遇到同样问题,新手没明太白您是怎么解决的?</p><p>还是这方法行不通!</p><p>acDocManager-&gt;pushResourceHandle (acedGetAcadResourceInstance ()) ;<br/>&nbsp;/*acDocManager-&gt;pushResourceHandle(_hdllInstance); */<br/>&nbsp;acDocManager-&gt;executeInApplicationContext(CreateDoc,(void *)pData); <br/>&nbsp;acDocManager-&gt;popResourceHandle () ;<br/>&nbsp;acedCommand(RTSTR,_T("ZOOM"),RTSTR,_T("E"),RTNONE);还是不显示啊!</p><p></p>
页: [1]
查看完整版本: 求问高手,关于executeInApplicationContext函数