类型:转载 责任编辑:asp.net 日期:2007/05/23
热门软件下载:
错误信息:
\ap_Win32App.cpp(1408): error C2712: 无法在要求对象展开的函数中使用 __try
当有DEBUG定义时都没问题
源程序:
int AP_Win32App::WinMain(const char * szAppName, HINSTANCE hInstance,
HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
bool bShowApp = true;
bool bShowSplash = true;
bool bSplashPref = true;
BOOL bInitialized = FALSE;
// this is a static function and doesnt have a this pointer.
MSG msg;
#ifdef _MSC_VER
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_DEBUG );
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_WNDW);
#endif
// HACK: load least-common-denominator Rich Edit control
// TODO: fix Spell dlg so we dont rely on this
// ALT: make it a Preview widget instead
HINSTANCE hinstRich = LoadLibrary("riched32.dll");
if (!hinstRich)
hinstRich = LoadLibrary("riched20.dll");
UT_ASSERT(hinstRich);
AP_Win32App * pMyWin32App;
// OLE Stuff
if (SUCCEEDED(OleInitialize(NULL)))
bInitialized = TRUE;
// We put this in a block to force the destruction of Args in the stack
{
// Load the command line into an XAP_Args class
#ifdef _MSC_VER // when using MSVC use already split arguments
XAP_Args XArgs = XAP_Args(__argc, (const char**)__argv);
#else // but for other compiles may not be available so use szCmdLine
UT_String szNewCmdLine = UT_String_sprintf ( "%s %s", "AbiWord.exe", szCmdLine ) ;
XAP_Args XArgs = XAP_Args(szNewCmdLine.c_str());
#endif
// Step 1: Initialize our application.
pMyWin32App = new AP_Win32App(hInstance, &XArgs, szAppName);
AP_Args Args = AP_Args(&XArgs, szAppName, pMyWin32App);
Args.parsePoptOpts();
pMyWin32App->initialize();
bShowSplash = Args.getShowSplash();
// Consider the user saved preferences for the Splash Screen
const XAP_Prefs * pPrefs = pMyWin32App->getPrefs();
UT_ASSERT(pPrefs);
if (pPrefs && pPrefs->getPrefsValueBool (AP_PREF_KEY_ShowSplash, &bSplashPref))
{
bShowSplash = bShowSplash && bSplashPref;
}
// Step 2: Handle all non-window args.
// process args (calls common arg handler, which then calls platform specific)
// As best I understand, it returns true to continue and show window, or
// false if no window should be shown (and thus we should simply exit).
if (!Args.doWindowlessArgs())
{
pMyWin32App->shutdown(); // properly shutdown the app 1st
delete pMyWin32App;
return 0;
}
// Step 3: Create windows as appropriate.
// if some args are botched, it returns false and we should
// continue out the door.
// We used to check for bShowApp here. It shouldnt be needed
// anymore, because doWindowlessArgs was supposed to bail already. -PL
if (!pMyWin32App->openCmdLineFiles(&Args))
{
pMyWin32App->shutdown(); // properly shutdown the app 1st
delete pMyWin32App;
return 0;
}
#ifdef SPLASH
if (bShowSplash)
{
_showSplash(hInstance, szAppName);
}
#endif
}
//
// This block is controlled by the Structured Exception Handle
// if any crash happens here we will recover it and save the file (cross fingers)
//
#if !defined(__MINGW32__) && !defined(DEBUG)
__try
#endif
{
UT_uint32 iHeight = 0, iWidth = 0, t_flag =0;
UT_sint32 iPosX = 0, iPosY = 0;
if (!((XAP_App::getApp()->getGeometry(&iPosX,&iPosY,&iWidth,&iHeight,&t_flag)) &&
((iWidth > 0) && (iHeight > 0))) )
XAP_App::getApp()->getDefaultGeometry(iWidth,iHeight,t_flag);
if ((t_flag & PREF_FLAG_GEOMETRY_MAXIMIZED)==PREF_FLAG_GEOMETRY_MAXIMIZED)
iCmdShow = SW_SHOWMAXIMIZED;
if (bShowApp)
{
// display the windows
for(UT_uint32 i = 0;i<pMyWin32App->m_vecFrames.getItemCount();i++)
{
AP_Win32Frame * curFrame = (AP_Win32Frame*)pMyWin32App->m_vecFrames[i];
UT_ASSERT(curFrame);
HWND hwnd = curFrame->getLevelWindow();
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
}
// do dispatch loop
while( GetMessage(&msg, NULL, 0, 0) )
{
// TranslateMessage is not called because AbiWord
// has its own way of decoding keyboard accelerators
if (pMyWin32App->handleModelessDialogMessage(&msg))
continue;
TranslateMessage(&msg);
DispatchMessage(&msg);
// Check for idle condition
while( !UT_Win32Idle::_isEmpty() &&
!PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) )
{
// Fire idle functions when no pending messages
UT_Win32Idle::_fireall();
}
}
}
// Un-init OLE
if (bInitialized)
OleUninitialize();
FreeLibrary(hinstRich);
// unload all loaded plugins (remove some of the memory leaks shown at shutdown :-)
XAP_ModuleManager::instance().unloadAllPlugins();
// Step 4: Destroy the App. It should take care of deleting all frames.
pMyWin32App->shutdown();
delete pMyWin32App;
}// end of thes block is controlled by the SEH
//
// If an exception happens, with "catch" the block
// and then the save it into disk
//
#if !defined(__MINGW32__) && !defined(DEBUG)
__except (1)
{
AP_Win32App *pApp = (AP_Win32App *) XAP_App::getApp();
UT_ASSERT(pApp);
UT_uint32 i = 0;
for(;i<pApp->m_vecFrames.getItemCount();i++)
{
AP_Win32Frame * curFrame = (AP_Win32Frame*)pApp->m_vecFrames[i];
UT_ASSERT(curFrame);
if (NULL == curFrame->getFilename())
curFrame->backup(".abw.saved");
else
curFrame->backup(".saved");
}
// Tell the user was has just happened
AP_Win32Frame * curFrame = (AP_Win32Frame*)pApp->m_vecFrames[0];
if (curFrame)
{
curFrame->showMessageBox(AP_STRING_ID_MSG_Exception,XAP_Dialog_MessageBox::b_O, XAP_Dialog_MessageBox::a_OK);
}
}// end of except
#endif
SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF );
return msg.wParam;
}
网友回答:
__try里面只要有带有构造函数的对象就不行。
换成try/catch.
catch(...)?
用try,catch
你的代码也够长的,没时间看。对于__try的实现windows是用结构化异常处理SEH支持的,它会在编译期进行unwind操作,如果其中有构造函数的对象是无法unwind的,所以报错。
象你这里面用到了MFC,你不知在哪有对象存在,所以出问题很正常的。