乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 75|回复: 4

求问高手,关于executeInApplicationContext函数

[复制链接]

1

主题

3

帖子

1

银币

初来乍到

Rank: 1

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

使用道具 举报

1

主题

3

帖子

1

银币

初来乍到

Rank: 1

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

使用道具 举报

1

主题

3

帖子

1

银币

初来乍到

Rank: 1

铜币
7
发表于 2005-8-24 09:11:00 | 显示全部楼层
老外就是凶哦,原来是2004arx的bug,程序范围的命令会导致资源失效,我的解决办法比较牵强。以下是从autodesk找来的。
I am having a problem with the code created by the ObjectARX wizard.
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
FATAL ERROR: Unhandled Access Violation Reading 0x0002 Exception at 7c18aacah
Thanks,
Justin
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Hi Justin,
I had the same problem, here is what i get.
Regards, Petra
-----------------------------------
The problem is similar to one that was reported before for similar
behavior with appContextOpenDocument and a Change Request was logged.
However it turns out that the problem has more to do with the code
generated by the ObjectARX wizard than AutoCAD itself.
The work around is to remove the following line in the
acrxEntrypPint.cpp
ACED_ARXCOMMAND_ENTRY_AUTO(CtestnewsyncdocApp, GIPS, testnewsyncdoc,
test, ACRX_CMD_MODAL, NULL)
and then add the following in the On_kInitAppMsg():
virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
acedRegCmds->addCommand( "GIPS",
"testopensyncdoc",
"test",
ACRX_CMD_MODAL ,
GIPStestnewsyncdoc);
return (retCode) ;
}
-----------------------------------
This is a follow up to my last reply. Here is a better work around that
does not break the wizards. (thanks Cyrille)
The bug in AutoCAD is that AutoCAD assumes its own resource handle is
always set when an API is called. So AutoCAD tries to load one of its
strings or dialog templates from the ARX application resource rather than
its own resource file. This indeed fails or succeeds but with the wrong
stuff. In any case, that will result in a crash sooner or later.
In your application which does not include MFC support do the following:
**** Use ACED_ARXCOMMAND_ENTRY_AUTO(CtestnewsyncdocApp, GIPS,
testnewsyncdoc, test, ACRX_CMD_MODAL, NULL)
declare this in StdAfx.h
HINSTANCE acedGetAcadResourceInstance () ;
(it is declared in rxmfcapi.h but you cannot include that file in non MFC
application, so you need to do it by hand)
Then use the acDocManager API
static void AsdkArxProject4_MyCommand1 (void) {
acDocManager->pushResourceHandle (acedGetAcadResourceInstance ()) ;
... acDocManager->popResourceHandle () ;
}
****
I changed your project to the following and the crash is resolved:
****
//wb added this to StdAfx.h
HINSTANCE acedGetAcadResourceInstance () ;

// ----- GIPStestnewsyncdoc.testnewsyncdoc command (do not rename)
static void GIPStestnewsyncdoc(void)
{
//wb added this
acDocManager->pushResourceHandle (acedGetAcadResourceInstance ()) ;
static char pData[] = "acad.dwt";
AcApDocument* pDoc = acDocManager->curDocument();
if (pDoc) {
acutPrintf("\nCurrently in Document context : %s, Switching to
App.\n",pDoc->fileName());
acDocManager->executeInApplicationContext(newSyncDocHelper, (void
*)pData);
}
//wb added this
acDocManager->popResourceHandle () ;
}
****
If you have a project that includes MFC support then you can do the
following:
****
Restore the AutoCAD resource handle in the command implementation by
adding
AfxSetResourceHandle (acedGetAcadResourceInstance ()) to the beginning of
the command:
static void GIPS_testnewsyncdoc () {
AfxSetResourceHandle (acedGetAcadResourceInstance ()) ;
...
}
This does not break the wizard and it is compatible with the AutoCAD
2005 code fix. It is also more simple to implement.
****
Cheers,
autodesk Wayne Brill
Developer Technical Services
回复

使用道具 举报

14

主题

202

帖子

4

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
258
发表于 2009-4-28 23:07:00 | 显示全部楼层
FATAL ERROR: Unhandled Access Violation Reading 0x0002 Exception at 7c18aacah
遇到同样的问题
感谢
1、修改命令方式为ACRX_CMD_SESSION
2、换06的sdk
回复

使用道具 举报

11

主题

21

帖子

1

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2009-11-21 20:37:00 | 显示全部楼层
遇到同样问题,新手没明太白您是怎么解决的?
还是这方法行不通!
acDocManager->pushResourceHandle (acedGetAcadResourceInstance ()) ;
/*acDocManager->pushResourceHandle(_hdllInstance); */
acDocManager->executeInApplicationContext(CreateDoc,(void *)pData);
acDocManager->popResourceHandle () ;
acedCommand(RTSTR,_T("ZOOM"),RTSTR,_T("E"),RTNONE);还是不显示啊!
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-2-5 22:07 , Processed in 0.249433 second(s), 62 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表