老外就是凶哦,原来是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 |