--- FSLib.c~	2007-01-16 11:55:20.000000000 +0200
+++ FSLib.c	2021-02-02 11:01:40.000000000 +0300
@@ -66,7 +66,7 @@ static HMQ               hmq;
 
 static int               tidSNAPThread;
 static int               iSNAPThreadStatus;
-static HMTX              hmtxUseSNAP = NULL;
+static HMTX              hmtxUseSNAP = NULLHANDLE;
 static HEV               hevSNAPCommandAvailable;  // Posted when there is a command for the SNAP-Thread!
 static HEV               hevSNAPResultReady;       // Posted when the result is ready for the command.
 static int               iSNAPCommand;             // Command code
@@ -84,7 +84,7 @@ static void             *pSNAPCommandPar
 typedef struct _FSLib_HWNDList
 {
   HWND hwndClient;
-  void *pNext;
+  struct _FSLib_HWNDList *pNext;
 } FSLib_HWNDList, *FSLib_HWNDList_p;
 
 static FSLib_HWNDList_p  pHWNDListHead = NULL;
@@ -95,13 +95,13 @@ static int               bFSLib_Initiali
 static unsigned long ulTimerFreq = 1;
 static unsigned long long llStartTime = 0;
 
-static void InitTimer()
+static void InitTimer(void)
 {
   DosTmrQueryFreq(&ulTimerFreq);
   DosTmrQueryTime((PQWORD) &llStartTime);
 }
 
-static unsigned long long GetTimeElapsed()
+static unsigned long long GetTimeElapsed(void)
 {
   unsigned long long llTime;
 
@@ -111,17 +111,18 @@ static unsigned long long GetTimeElapsed
 #endif
 
 // Some prototypes
-static int  SNAP_Initialize();
-static void SNAP_Uninitialize();
-static int  SNAP_StartVideoModeUsage();
-static void SNAP_StopVideoModeUsage();
+static int  SNAP_Initialize(void);
+static void SNAP_Uninitialize(void);
+static int  SNAP_StartVideoModeUsage(void);
+static void SNAP_StopVideoModeUsage(void);
 static void SNAP_SetVideoMode_core(GA_modeInfo *pVideoMode);
 static void SNAP_SetVideoMode(GA_modeInfo *pVideoMode);
 static void SNAP_ThreadFunc(void *pParm);
 
-static int  FSLib_RegisterWindowClass();
+static int  FSLib_RegisterWindowClass(void);
+static void FSLib_FindBestFSMode(FSLib_VideoMode_p pSrcBufferDesc, GA_modeInfo *pFSModeInfo);
 
-static void SNAP_StopVideoModeUsage()
+static void SNAP_StopVideoModeUsage(void)
 {
   if (bUnloadRef2D)
   {
@@ -133,7 +134,7 @@ static void SNAP_StopVideoModeUsage()
   }
 }
 
-static int SNAP_StartVideoModeUsage()
+static int SNAP_StartVideoModeUsage(void)
 {
   int iResult = 1;
 
@@ -215,8 +216,7 @@ static int SNAP_StartVideoModeUsage()
   return iResult;
 }
 
-
-static void SNAP_Uninitialize()
+static void SNAP_Uninitialize(void)
 {
   //  If current video mode != desktop video mode, then set desktop video mode!
   if (!iInPM)
@@ -280,7 +280,7 @@ static void SNAP_Uninitialize()
   }
 }
 
-static int SNAP_Initialize()
+static int SNAP_Initialize(void)
 {
 #ifdef DEBUG_BUILD
   printf("[SNAP_Initialize] : Initializing...\n");
@@ -313,7 +313,6 @@ static int SNAP_Initialize()
   return 1;
 }
 
-
 static int SNAP_SameVideoMode(GA_modeInfo *pVideoMode1, GA_modeInfo *pVideoMode2)
 {
   int iResult = 0;
@@ -338,7 +337,7 @@ static int SNAP_SameVideoMode(GA_modeInf
   return iResult;
 }
 
-static void SNAP_StopPresentationManager()
+static void SNAP_StopPresentationManager(void)
 {
   HAB hab;
   HWND hwnd;
@@ -355,18 +354,18 @@ static void SNAP_StopPresentationManager
 
   hwnd = WinQueryDesktopWindow(hab, 0);
 #ifdef DEBUG_BUILD
-  if (hwnd==NULL)
+  if (hwnd==NULLHANDLE)
     printf("[SNAP_StopPresentationManager] : Error at WinQueryDesktopWindow()!\n");
 #endif
   hdc = WinQueryWindowDC(hwnd);                    // Get HDC of desktop
-  if (hdc==NULL)
+  if (hdc==NULLHANDLE)
   {
 #ifdef DEBUG_BUILD
     printf("[SNAP_StopPresentationManager] : Error at WinQueryWindowDC(), trying other...!\n");
 #endif
     hdc = WinOpenWindowDC(hwnd);                    // Get HDC of desktop
 #ifdef DEBUG_BUILD
-    if (hdc==NULL)
+    if (hdc==NULLHANDLE)
       printf("[SNAP_StopPresentationManager] : Error at WinOpenWindowDC()!\n");
 #endif
   }
@@ -380,25 +379,25 @@ static void SNAP_StopPresentationManager
   }
 }
 
-static void SNAP_RestartPresentationManager()
+static void SNAP_RestartPresentationManager(void)
 {
   HWND hwnd;
   HDC  hdc;
 
   hwnd = WinQueryDesktopWindow(hab, 0);
 #ifdef DEBUG_BUILD
-  if (hwnd==NULL)
+  if (hwnd==NULLHANDLE)
     printf("[SNAP_RestartPresentationManager] : Error at WinQueryDesktopWindow()!\n");
 #endif
   hdc = WinQueryWindowDC(hwnd);                    // Get HDC of desktop
-  if (hdc==NULL)
+  if (hdc==NULLHANDLE)
   {
 #ifdef DEBUG_BUILD
     printf("[SNAP_RestartPresentationManager] : Error at WinQueryWindowDC(), trying other...!\n");
 #endif
     hdc = WinOpenWindowDC(hwnd);                    // Get HDC of desktop
 #ifdef DEBUG_BUILD
-    if (hdc==NULL)
+    if (hdc==NULLHANDLE)
       printf("[SNAP_RestartPresentationManager] : Error at WinOpenWindowDC()!\n");
 #endif
   }
@@ -577,7 +576,7 @@ static void SNAP_ThreadUninitialize(int 
 #ifdef DEBUG_BUILD
       printf("[SNAP_ThreadFunc] :   GA_unloadDriver()...\n");
 #endif
-      GA_unloadDriver(dc); dc = NULL;
+      GA_unloadDriver(dc); dc = NULLHANDLE;
     }
     if ((hmq) && (!iEmergency))
     {
@@ -795,7 +794,7 @@ static void SNAP_ThreadFunc(void *pParm)
 #ifdef DEBUG_BUILD
     printf("[SNAP_ThreadFunc] : Could not query init funcs\n");
 #endif
-    GA_unloadDriver(dc); dc = NULL;
+    GA_unloadDriver(dc); dc = NULLHANDLE;
     WinDestroyMsgQueue(hmq);
     WinTerminate(hab);
     iSNAPThreadStatus = SNAPTHREADSTATUS_STOPPED_ERROR;
@@ -810,7 +809,7 @@ static void SNAP_ThreadFunc(void *pParm)
 #ifdef DEBUG_BUILD
     printf("[SNAP_ThreadFunc] : Could not query driver funcs\n");
 #endif
-    GA_unloadDriver(dc); dc = NULL;
+    GA_unloadDriver(dc); dc = NULLHANDLE;
     WinDestroyMsgQueue(hmq);
     WinTerminate(hab);
     iSNAPThreadStatus = SNAPTHREADSTATUS_STOPPED_ERROR;
@@ -860,7 +859,7 @@ static void SNAP_ThreadFunc(void *pParm)
   // Create semaphores
   if ((rc = DosCreateMutexSem(NULL, &hmtxUseSNAP, 0, FALSE))!=NO_ERROR)
   {
-    GA_unloadDriver(dc); dc = NULL;
+    GA_unloadDriver(dc); dc = NULLHANDLE;
 #ifdef DEBUG_BUILD
     printf("[SNAP_ThreadFunc] : Could not create mutex semaphore! rc = %d\n", rc);
 #endif
@@ -873,7 +872,7 @@ static void SNAP_ThreadFunc(void *pParm)
   if ((rc = DosCreateEventSem(NULL, &hevSNAPCommandAvailable, 0, FALSE))!=NO_ERROR)
   {
     DosCloseMutexSem(hmtxUseSNAP); hmtxUseSNAP = NULLHANDLE;
-    GA_unloadDriver(dc); dc = NULL;
+    GA_unloadDriver(dc); dc = NULLHANDLE;
 #ifdef DEBUG_BUILD
     printf("[SNAP_ThreadFunc] : Could not create event semaphore! rc = %d\n", rc);
 #endif
@@ -887,7 +886,7 @@ static void SNAP_ThreadFunc(void *pParm)
   {
     DosCloseEventSem(hevSNAPCommandAvailable); hevSNAPCommandAvailable = NULLHANDLE;
     DosCloseMutexSem(hmtxUseSNAP); hmtxUseSNAP = NULLHANDLE;
-    GA_unloadDriver(dc); dc = NULL;
+    GA_unloadDriver(dc); dc = NULLHANDLE;
 #ifdef DEBUG_BUILD
     printf("[SNAP_ThreadFunc] : Could not create event semaphore! rc = %d\n", rc);
 #endif
@@ -907,7 +906,7 @@ static void SNAP_ThreadFunc(void *pParm)
     DosCloseEventSem(hevSNAPResultReady); hevSNAPResultReady = NULLHANDLE;
     DosCloseEventSem(hevSNAPCommandAvailable); hevSNAPCommandAvailable = NULLHANDLE;
     DosCloseMutexSem(hmtxUseSNAP); hmtxUseSNAP = NULLHANDLE;
-    GA_unloadDriver(dc); dc = NULL;
+    GA_unloadDriver(dc); dc = NULLHANDLE;
     WinDestroyMsgQueue(hmq);
     WinTerminate(hab);
     iSNAPThreadStatus = SNAPTHREADSTATUS_STOPPED_ERROR;
@@ -980,7 +979,7 @@ static void FSLib_GAmodeInfo2FSLibVideoM
   memcpy(&(pVideoMode->PixelFormat), &(pModeInfo->PixelFormat), sizeof(FSLib_PixelFormat));
 }
 
-DECLSPEC int               FSLIBCALL FSLib_Initialize()
+DECLSPEC int               FSLIBCALL FSLib_Initialize(void)
 {
   int rc;
 
@@ -1012,7 +1011,7 @@ DECLSPEC int               FSLIBCALL FSL
   // Register new class
   if (!FSLib_RegisterWindowClass())
   {
-    DosCloseMutexSem(hmtxUseHWNDList); hmtxUseHWNDList = NULL;
+    DosCloseMutexSem(hmtxUseHWNDList); hmtxUseHWNDList = NULLHANDLE;
     SNAP_Uninitialize();
 #ifdef DEBUG_BUILD
     printf("[FSLib_Initialize] : Could not register new window class!\n");
@@ -1027,7 +1026,7 @@ DECLSPEC int               FSLIBCALL FSL
   return 1;
 }
 
-DECLSPEC void              FSLIBCALL FSLib_Uninitialize()
+DECLSPEC void              FSLIBCALL FSLib_Uninitialize(void)
 {
   if (bFSLib_Initialized)
   {
@@ -1053,7 +1052,7 @@ DECLSPEC void              FSLIBCALL FSL
 #ifdef DEBUG_BUILD
     printf("[FSLib_Uninitialize] : Destroying semaphore\n");
 #endif
-    DosCloseMutexSem(hmtxUseHWNDList); hmtxUseHWNDList = NULL;
+    DosCloseMutexSem(hmtxUseHWNDList); hmtxUseHWNDList = NULLHANDLE;
     // Uninitialize SNAP
 #ifdef DEBUG_BUILD
     printf("[FSLib_Uninitialize] : Uninitializing SNAP\n");
@@ -1066,7 +1065,7 @@ DECLSPEC void              FSLIBCALL FSL
   }
 }
 
-static void FSLib_EmergencyUninitialize()
+static void FSLib_EmergencyUninitialize(void)
 {
   if (bFSLib_Initialized)
   {
@@ -1092,7 +1091,7 @@ static void FSLib_EmergencyUninitialize(
 #ifdef DEBUG_BUILD
     printf("[FSLib_EmergencyUninitialize] : Destroying mutex semaphore\n");
 #endif
-    DosCloseMutexSem(hmtxUseHWNDList); hmtxUseHWNDList = NULL;
+    DosCloseMutexSem(hmtxUseHWNDList); hmtxUseHWNDList = NULLHANDLE;
 
     // We don't have to uninitialize SNAP here, it will be done by
     // SNAPThread's Exception handler
@@ -1288,23 +1287,23 @@ static MRESULT EXPENTRY FSLib_WndProc(HW
 	fflush(stdout);
 #endif
 	// Set up window storage initial values
-	WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_PVOID_USERDATA, (ULONG) 0);
+	WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_PVOID_USERDATA, 0);
 	DosCreateMutexSem(NULL, &hmtxUseWindowData, 0, FALSE);
 	WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_HMTX_USEWINDOWDATA, (ULONG) hmtxUseWindowData);
-	WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_PFNWP_USERWINDOWFN, (ULONG) 0);
+	WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_PFNWP_USERWINDOWFN, 0);
 	pFSModeInfo = (GA_modeInfo *) malloc(sizeof(GA_modeInfo));
         memcpy(pFSModeInfo, &desktopModeInfo, sizeof(GA_modeInfo));
 	WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_PGAMODEINFO_FSMODEINFO, (ULONG) pFSModeInfo);
-	WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_INT_VRNDISABLED, (ULONG) 1); // True
-	WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_INT_RUNINFSMODE, (ULONG) 0); // False
-	WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_PRECTL_VISIBLEAREA, (ULONG) NULL);
-	WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_INT_NUMOFVISIBLEAREARECTANGLES, (ULONG) 0);
-        WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_INT_MAXNUMOFVISIBLEAREARECTANGLES, (ULONG) 0);
+	WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_INT_VRNDISABLED, 1); // True
+	WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_INT_RUNINFSMODE, 0); // False
+	WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_PRECTL_VISIBLEAREA, 0);
+	WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_INT_NUMOFVISIBLEAREARECTANGLES, 0);
+        WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_INT_MAXNUMOFVISIBLEAREARECTANGLES, 0);
 	pSrcBufferDesc = (FSLib_VideoMode_p) malloc(sizeof(FSLib_VideoMode));
         FSLib_GAmodeInfo2FSLibVideoMode(pFSModeInfo, pSrcBufferDesc);
 	WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_PVOID_SRCBUFFERDESC, (ULONG) pSrcBufferDesc);
-        WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_INT_WINDOWACTIVE, (ULONG) 0); // False
-        WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_INT_DIRTYWINDOW, (ULONG) 0); // False
+        WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_INT_WINDOWACTIVE, 0); // False
+        WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_INT_DIRTYWINDOW, 0); // False
         pswpFrameSWP = (PSWP) malloc(sizeof(SWP));
         WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_PSWP_FRAMESWP, (ULONG) pswpFrameSWP);
 
@@ -1464,12 +1463,12 @@ static MRESULT EXPENTRY FSLib_WndProc(HW
 	  if (!prectlVisibleArea)
 	  {
             iMaxNumOfVisibleAreaRectangles = 50;
-	    prectlVisibleArea = malloc(iMaxNumOfVisibleAreaRectangles*sizeof(RECTL));
+	    prectlVisibleArea = (PRECTL) malloc(iMaxNumOfVisibleAreaRectangles * sizeof(RECTL));
           }
 
 	  // Get the all ORed rectangles
           if (prectlVisibleArea)
-	  do {
+	   do {
 	    rgnctl.ircStart = 1;
 	    rgnctl.crc = iMaxNumOfVisibleAreaRectangles;
 	    rgnctl.crcReturned = 0;
@@ -1518,8 +1517,8 @@ static MRESULT EXPENTRY FSLib_WndProc(HW
             printf("[FSLib_WndProc] : WM_VRNENABLED : Redrawing dirty window.\n");
 	    fflush(stdout);
 #endif
-            WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_INT_DIRTYWINDOW, (ULONG) 0); // False
-            WinInvalidateRect(hwnd, NULL, TRUE);
+            WinSetWindowULong(hwnd, FSLIB_WINDOWDATA_INT_DIRTYWINDOW, 0); // False
+            WinInvalidateRect(hwnd, NULLHANDLE, TRUE);
           }
 
 #ifdef DEBUG_BUILD
@@ -1726,8 +1725,7 @@ static MRESULT EXPENTRY FSLib_WndProc(HW
 }
 
 
-
-static int FSLib_RegisterWindowClass()
+static int FSLib_RegisterWindowClass(void)
 {
   HAB hab;
 
@@ -1866,8 +1864,14 @@ static void FSLib_FindBestFSMode(FSLib_V
 #endif
 }
 
+#ifdef __cplusplus
+extern "C" {
+#endif
 // -- Definition of DosGetInfoSeg() API to be called from 32bits code: --
 USHORT APIENTRY16 DOS16GETINFOSEG(PUSHORT pselGlobal, PUSHORT pselLocal);
+#ifdef __cplusplus
+}
+#endif
 #define DosGetInfoSeg DOS16GETINFOSEG
 
 /* Global Information Segment */
@@ -1908,7 +1912,7 @@ typedef struct _GINFOSEG {	/* gis */
 } GINFOSEG;
 typedef GINFOSEG FAR *PGINFOSEG;
 
-static int FSLib_IsPMTheForegroundFSSession()
+static int FSLib_IsPMTheForegroundFSSession(void)
 {
   APIRET         rc;
   USHORT         globalSeg, localSeg;
@@ -1936,7 +1940,7 @@ static int FSLib_IsPMTheForegroundFSSess
 
 
 // Get all available fullscreen video modes
-DECLSPEC FSLib_VideoMode_p FSLIBCALL FSLib_GetVideoModeList()
+DECLSPEC FSLib_VideoMode_p FSLIBCALL FSLib_GetVideoModeList(void)
 {
   FSLib_VideoMode_p pResult, pLast, pNewEntry;
   GA_modeInfo modeInfo;
@@ -1997,7 +2001,7 @@ DECLSPEC int               FSLIBCALL FSL
   return 1;
 }
 // Get pointer to desktop video mode (Don't free it, it's static!)
-DECLSPEC FSLib_VideoMode_p FSLIBCALL FSLib_GetDesktopVideoMode()
+DECLSPEC FSLib_VideoMode_p FSLIBCALL FSLib_GetDesktopVideoMode(void)
 {
   return &desktopVideoModeInfo;
 }
@@ -2623,8 +2627,8 @@ DECLSPEC int               FSLIBCALL FSL
                   printf("[FSLib_BitBlt] : End of Blitting\n");
                   fflush(stdout);
 #endif
-
                 }
+
 #ifdef SWCURSOR_HACK
                 // Resore mouse cursor if have to
                 if ((cursorFuncs.BeginAccess) && (cursorFuncs.EndAccess) && (bMouseHidden))
@@ -2642,7 +2646,6 @@ DECLSPEC int               FSLIBCALL FSL
 
                 DosReleaseMutexSem(hmtxUseSNAP);
               }
-              
             }
 #ifdef DEBUG_BUILD
             else
@@ -2658,7 +2661,6 @@ DECLSPEC int               FSLIBCALL FSL
             printf("[FSLib_BitBlt] : Not enough memory for modified visible area!\n");
           }
 #endif
-
         }
       }
     }
--- FSLib.h~	2005-02-15 16:37:58.000000000 +0200
+++ FSLib.h	2021-02-02 11:01:40.000000000 +0300
@@ -4,6 +4,10 @@
 #define INCL_WIN
 #include <os2.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define FSLIBCALL _System
 #define DECLSPEC  __declspec(dllexport)
 
@@ -35,23 +39,23 @@ typedef struct _FSLib_VideoMode
   unsigned int       uiBPP;
   FSLib_PixelFormat  PixelFormat;
 
-  void *pNext;
+  struct _FSLib_VideoMode * pNext;
 
 } FSLib_VideoMode, *FSLib_VideoMode_p;
 
 // Initialization of FSLib for the calling process.
 // Returns 1 if successful!
-DECLSPEC int               FSLIBCALL FSLib_Initialize();
+DECLSPEC int               FSLIBCALL FSLib_Initialize(void);
 
 // Uninitialization of FSLib.
-DECLSPEC void              FSLIBCALL FSLib_Uninitialize();
+DECLSPEC void              FSLIBCALL FSLib_Uninitialize(void);
 
 // Get all available fullscreen video modes
-DECLSPEC FSLib_VideoMode_p FSLIBCALL FSLib_GetVideoModeList();
+DECLSPEC FSLib_VideoMode_p FSLIBCALL FSLib_GetVideoModeList(void);
 // Free list of available fullscreen video modes
 DECLSPEC int               FSLIBCALL FSLib_FreeVideoModeList(FSLib_VideoMode_p pVideoModeListHead);
 // Get pointer to desktop video mode (Don't free it, it's static!)
-DECLSPEC FSLib_VideoMode_p FSLIBCALL FSLib_GetDesktopVideoMode();
+DECLSPEC FSLib_VideoMode_p FSLIBCALL FSLib_GetDesktopVideoMode(void);
 
 
 // Create a FSLib client window with given frame, telling the
@@ -117,4 +121,8 @@ DECLSPEC int               FSLIBCALL FSL
 //   to/from fullscreen mode (flag is in mp2)
 #define FSLN_TOGGLEFSMODE        0
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
