[907] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: fm3.c 1511 2010-04-12 16:36:48Z 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"
|
---|
[1341] | 26 | #include "dll\mainwnd.h" // hwndBubble
|
---|
| 27 | #include "dll\version.h" // VER...
|
---|
| 28 | #include "dll\init.h" // StartFM3
|
---|
| 29 | #include "dll\notebook.h" // appname
|
---|
[1077] | 30 | #include "dll\fortify.h"
|
---|
[1336] | 31 | #include "dll\errutil.h" // Error reporting
|
---|
| 32 | #include "dll\excputil.h" // Exception handlers
|
---|
[2] | 33 |
|
---|
[1336] | 34 | static PSZ pszSrcFile = __FILE__;
|
---|
| 35 |
|
---|
[551] | 36 | int main(int argc, char *argv[])
|
---|
| 37 | {
|
---|
| 38 | HAB hab;
|
---|
| 39 | HMQ hmq;
|
---|
| 40 | QMSG qmsg;
|
---|
| 41 | HWND hwndFrame;
|
---|
[1336] | 42 | APIRET regRet;
|
---|
| 43 | EXCEPTIONREGISTRATIONRECORD regRec = { NULL, NULL };
|
---|
[2] | 44 |
|
---|
[551] | 45 | strcpy(appname, "FM/3");
|
---|
[2] | 46 | DosError(FERR_DISABLEHARDERR);
|
---|
[1336] | 47 |
|
---|
| 48 | regRec.ExceptionHandler = HandleException;
|
---|
| 49 | regRet = DosSetExceptionHandler(®Rec);
|
---|
| 50 | if (regRet != NO_ERROR) {
|
---|
| 51 | #if 0 // 10 Dec 08 SHL fixme to report later maybe?
|
---|
| 52 | Dos_Error(MB_ENTER, regRet, HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
| 53 | "DosSetExceptionHandler");
|
---|
| 54 | #endif
|
---|
| 55 | DbgMsg(pszSrcFile, __LINE__,
|
---|
| 56 | "DosSetExceptionHandler failed with error %u", regRet);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[2] | 59 | hab = WinInitialize(0);
|
---|
[551] | 60 | if (hab) {
|
---|
| 61 | hmq = WinCreateMsgQueue(hab, 2048);
|
---|
| 62 | if (hmq) {
|
---|
| 63 | if (InitFM3DLL(hab, argc, argv)) {
|
---|
| 64 | if (CheckVersion(VERMAJOR, VERMINOR)) {
|
---|
[1077] | 65 | # ifdef FORTIFY
|
---|
| 66 | Fortify_EnterScope();
|
---|
| 67 | # endif
|
---|
[551] | 68 | hwndFrame = StartFM3(hab, argc, argv);
|
---|
| 69 | if (hwndFrame != (HWND) 0) {
|
---|
| 70 | for (;;) {
|
---|
| 71 | if (!WinGetMsg(hab, &qmsg, (HWND) 0, 0, 0)) {
|
---|
| 72 | if (qmsg.hwnd)
|
---|
[1511] | 73 | qmsg.msg = WM_CLOSE; // Map quit to close
|
---|
[551] | 74 | else
|
---|
| 75 | break;
|
---|
| 76 | }
|
---|
| 77 | if (hwndBubble &&
|
---|
| 78 | ((qmsg.msg > (WM_BUTTON1DOWN - 1) &&
|
---|
| 79 | qmsg.msg < (WM_BUTTON3DBLCLK + 1)) ||
|
---|
| 80 | (qmsg.msg > (WM_CHORD - 1) &&
|
---|
| 81 | qmsg.msg < (WM_BUTTON3CLICK + 1))) &&
|
---|
| 82 | WinIsWindowVisible(hwndBubble))
|
---|
| 83 | WinShowWindow(hwndBubble, FALSE);
|
---|
| 84 | WinDispatchMsg(hab, &qmsg);
|
---|
| 85 | }
|
---|
| 86 | if (WinIsWindow(hab, WinWindowFromID(hwndFrame, FID_CLIENT)))
|
---|
| 87 | WinSendMsg(WinWindowFromID(hwndFrame, FID_CLIENT), WM_CLOSE,
|
---|
| 88 | MPVOID, MPVOID);
|
---|
| 89 | }
|
---|
[1077] | 90 | # ifdef FORTIFY
|
---|
[1078] | 91 | for (;;) {
|
---|
| 92 | UCHAR scope = Fortify_LeaveScope();
|
---|
| 93 | if ((CHAR)scope == 0)
|
---|
| 94 | break;
|
---|
| 95 | Runtime_Error(__FILE__, __LINE__, "Attempting to exit thread with scope non-zero (%u)", scope);
|
---|
| 96 | if ((CHAR)scope < 0)
|
---|
| 97 | break;
|
---|
| 98 | }
|
---|
[1341] | 99 | Fortify_DumpAllMemory();
|
---|
[1077] | 100 | # endif
|
---|
[551] | 101 | }
|
---|
[2] | 102 | }
|
---|
| 103 | DosSleep(250L);
|
---|
| 104 | WinDestroyMsgQueue(hmq);
|
---|
| 105 | }
|
---|
| 106 | WinTerminate(hab);
|
---|
| 107 | }
|
---|
[1336] | 108 |
|
---|
| 109 | if (regRet == NO_ERROR) {
|
---|
| 110 | regRet = DosUnsetExceptionHandler(®Rec);
|
---|
| 111 | if (regRet != NO_ERROR) {
|
---|
| 112 | DbgMsg(pszSrcFile, __LINE__,
|
---|
| 113 | "DosUnsetExceptionHandler failed with error %u", regRet);
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
[2] | 116 | return 0;
|
---|
| 117 | }
|
---|