From: Oscar F. <of...@wa...> - 2002-09-28 12:01:39
|
Hi. I've discovered that programs built with MinGW's g++ 3.2 dies with 'abnormal program termination' when a Windows callback throws an exception. The trivial Windows GUI program attached below works fine with MinGW gcc 2.95.3-6, FSF gcc 3.1 configured with --enable-sjlj-exceptions, Borland 5.5.1 and MSVC++ 6 sp4 Build, execute, click on the 'close window' box, say 'no'. Of course, I've discovered the problem while working on a "real world" application <g>. This is a serious drawback. The question: is dwarf exception handling supposed to work across Windows callbacks? If the answer to the above is 'No', IMHO MinGW should go back to sjlj exceptions. -- Oscar // Begin file foo.cpp #include <windows.h> #include <string.h> const char *CLASSNAME = "Tutorial", *WINNAME = "Tutorial 2 - The Window"; LRESULT CALLBACK WndProc(HWND hWnd, unsigned int iMessage, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) { HWND hWnd; MSG Message; WNDCLASS WndClass; memset(&WndClass, 0, sizeof(WndClass)); WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0; WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); WndClass.hCursor = LoadCursor(NULL, IDC_ARROW); WndClass.hIcon = LoadIcon(hInstance, NULL); WndClass.hInstance = hInstance; WndClass.lpfnWndProc = WndProc; WndClass.lpszClassName = CLASSNAME; WndClass.style = CS_HREDRAW | CS_VREDRAW; if(!RegisterClass(&WndClass)) return 0; hWnd = CreateWindow(CLASSNAME, WINNAME, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 100, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); try { while(GetMessage(&Message, hWnd, 0, 0)) { TranslateMessage(&Message); DispatchMessage(&Message); } } catch(...) { MessageBox(0, "Exception", "Exception", MB_OK); } return Message.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) { switch(iMessage) { case WM_CLOSE: case WM_DESTROY: if(MessageBox(hWnd, "Do you really want to quit?", "Message", MB_YESNO) == IDYES) PostQuitMessage(0); else throw 10; break; default: return DefWindowProc(hWnd, iMessage, wParam, lParam); } return 0; } // End of file foo.cpp |