OSDN Git Service

upgrade to 3.6.2
[jnethack/source.git] / win / win32 / winhack.c
index a85bdc4..c6941d7 100644 (file)
@@ -5,7 +5,9 @@
 // winhack.cpp : Defines the entry point for the application.
 //
 
+#include "win10.h"
 #include <process.h>
+
 #include "winMS.h"
 #include "hack.h"
 #include "dlb.h"
 #include "mhmain.h"
 #include "mhmap.h"
 
+#if !defined(SAFEPROCS)
+#error You must #define SAFEPROCS to build winhack.c
+#endif
+
 /* Borland and MinGW redefine "boolean" in shlwapi.h,
    so just use the little bit we need */
 typedef struct _DLLVERSIONINFO {
@@ -57,6 +63,8 @@ _nhapply_image_transparent(HDC hDC, int x, int y, int width, int height,
 
 // Global Variables:
 NHWinApp _nethack_app;
+extern int GUILaunched;     /* We tell shared startup code in windmain.c
+                               that the GUI was launched via this */
 
 #ifdef __BORLANDC__
 #define _stricmp(s1, s2) stricmp(s1, s2)
@@ -64,7 +72,7 @@ NHWinApp _nethack_app;
 #endif
 
 // Foward declarations of functions included in this code module:
-extern boolean FDECL(pcmain, (int, char **));
+extern boolean FDECL(main, (int, char **));
 static void __cdecl mswin_moveloop(void *);
 
 #define MAX_CMDLINE_PARAM 255
@@ -80,21 +88,44 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
     TCHAR *p;
     TCHAR wbuf[BUFSZ];
     char buf[BUFSZ];
+
     DWORD major, minor;
-    boolean resuming;
     /* OSVERSIONINFO osvi; */
 
     UNREFERENCED_PARAMETER(hPrevInstance);
     UNREFERENCED_PARAMETER(lpCmdLine);
     UNREFERENCED_PARAMETER(nCmdShow);
 
-    sys_early_init();
+    /*
+     * Get a set of valid safe windowport function
+     * pointers during early startup initialization.
+     *
+     * When get_safe_procs is called with 0 as the param,
+     * non-functional, but safe function pointers are set
+     * for all windowport routines.
+     *
+     * When get_safe_procs is called with 1 as the param,
+     * raw_print, raw_print_bold, and wait_synch, and nhgetch
+     * are set to use C stdio routines via stdio_raw_print,
+     * stdio_raw_print_bold, stdio_wait_synch, and
+     * stdio_nhgetch.
+     */
+    windowprocs = *get_safe_procs(0);
 
-    /* ensure that we don't access violate on a panic() */
+    /*
+     * Now we are going to override a couple
+     * of the windowprocs functions so that
+     * error messages are handled in a suitable
+     * way for the graphical version.
+     */
     windowprocs.win_raw_print = mswin_raw_print;
     windowprocs.win_raw_print_bold = mswin_raw_print_bold;
+    windowprocs.win_wait_synch = mswin_wait_synch;
+
+    win10_init();
+    sys_early_init();
 
-    /* init applicatio structure */
+    /* init application structure */
     _nethack_app.hApp = hInstance;
     _nethack_app.hAccelTable =
         LoadAccelerators(hInstance, (LPCTSTR) IDC_NETHACKW);
@@ -204,10 +235,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
         }
         free(savefile);
     }
-    resuming = pcmain(argc, argv);
-
-    moveloop(resuming);
-
+    GUILaunched = 1;
+    /* let main do the argument processing */
+    (void) main(argc, argv);
     return 0;
 }