source: trunk/fm3.c@ 1336

Last change on this file since 1336 was 1336, checked in by Steven Levine, 17 years ago

Ticket 26: add thread 1 exception handler support to fm3.exe

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
RevLine 
[907]1
2/***********************************************************************
3
4 $Id: fm3.c 1336 2008-12-13 00:01:10Z stevenhl $
5
6 fm/2 starter
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2008 Steven H.Levine
10
11 05 Jan 08 SHL Sync
[1077]12 18 Jul 08 SHL Add Fortify support
[1336]13 11 Dec 08 SHL Add exception handler support
[907]14
15***********************************************************************/
16
17#include <string.h>
18
[2]19#define INCL_DOS
20#define INCL_WIN
[907]21#define INCL_LONGLONG
[1336]22#define INCL_DOSEXCEPTIONS // XCTP_...
23#define INCL_DOSERRORS // NO_ERROR
[2]24
[1215]25#include "dll\fm3dll.h"
[1336]26#include "dll\mainwnd.h" // Data declaration(s)
[2]27#include "dll\tools.h"
28#include "dll\version.h"
[1078]29#include "dll\errutil.h"
[1077]30#include "dll\fortify.h"
[1164]31#include "dll\init.h" // StartFM3
[1215]32#include "dll\notebook.h" // Data declaration(s)
[1336]33#include "dll\errutil.h" // Error reporting
34#include "dll\excputil.h" // Exception handlers
[2]35
[1336]36static PSZ pszSrcFile = __FILE__;
37
[551]38int main(int argc, char *argv[])
39{
40 HAB hab;
41 HMQ hmq;
42 QMSG qmsg;
43 HWND hwndFrame;
[1336]44 APIRET regRet;
45 EXCEPTIONREGISTRATIONRECORD regRec = { NULL, NULL };
[2]46
[551]47 strcpy(appname, "FM/3");
[2]48 DosError(FERR_DISABLEHARDERR);
[1336]49
50 regRec.ExceptionHandler = HandleException;
51 regRet = DosSetExceptionHandler(&regRec);
52 if (regRet != NO_ERROR) {
53#if 0 // 10 Dec 08 SHL fixme to report later maybe?
54 Dos_Error(MB_ENTER, regRet, HWND_DESKTOP, pszSrcFile, __LINE__,
55 "DosSetExceptionHandler");
56#endif
57 DbgMsg(pszSrcFile, __LINE__,
58 "DosSetExceptionHandler failed with error %u", regRet);
59 }
60
[2]61 hab = WinInitialize(0);
[551]62 if (hab) {
63 hmq = WinCreateMsgQueue(hab, 2048);
64 if (hmq) {
65 if (InitFM3DLL(hab, argc, argv)) {
66 if (CheckVersion(VERMAJOR, VERMINOR)) {
[1077]67# ifdef FORTIFY
68 Fortify_EnterScope();
69# endif
[551]70 hwndFrame = StartFM3(hab, argc, argv);
71 if (hwndFrame != (HWND) 0) {
72 for (;;) {
73 if (!WinGetMsg(hab, &qmsg, (HWND) 0, 0, 0)) {
74 if (qmsg.hwnd)
75 qmsg.msg = WM_CLOSE;
76 else
77 break;
78 }
79 if (hwndBubble &&
80 ((qmsg.msg > (WM_BUTTON1DOWN - 1) &&
81 qmsg.msg < (WM_BUTTON3DBLCLK + 1)) ||
82 (qmsg.msg > (WM_CHORD - 1) &&
83 qmsg.msg < (WM_BUTTON3CLICK + 1))) &&
84 WinIsWindowVisible(hwndBubble))
85 WinShowWindow(hwndBubble, FALSE);
86 WinDispatchMsg(hab, &qmsg);
87 }
88 if (WinIsWindow(hab, WinWindowFromID(hwndFrame, FID_CLIENT)))
89 WinSendMsg(WinWindowFromID(hwndFrame, FID_CLIENT), WM_CLOSE,
90 MPVOID, MPVOID);
91 }
[1077]92# ifdef FORTIFY
[1078]93 for (;;) {
94 UCHAR scope = Fortify_LeaveScope();
95 if ((CHAR)scope == 0)
96 break;
97 Runtime_Error(__FILE__, __LINE__, "Attempting to exit thread with scope non-zero (%u)", scope);
98 if ((CHAR)scope < 0)
99 break;
100 }
[1336]101 Fortify_DumpAllMemory();
[1077]102# endif
[551]103 }
[2]104 }
105 DosSleep(250L);
106 WinDestroyMsgQueue(hmq);
107 }
108 WinTerminate(hab);
109 }
[1336]110
111 if (regRet == NO_ERROR) {
112 regRet = DosUnsetExceptionHandler(&regRec);
113 if (regRet != NO_ERROR) {
114 DbgMsg(pszSrcFile, __LINE__,
115 "DosUnsetExceptionHandler failed with error %u", regRet);
116 }
117 }
[2]118 return 0;
119}
Note: See TracBrowser for help on using the repository browser.