diff -Nur --exclude '*.obj' --exclude '*.exp' --exclude '*.lib' --exclude '*.idb' '--exclude=osgeo4w' fcgi2-2.4.2/include/fcgi_config.h ../include/fcgi_config.h
--- fcgi2-2.4.2/include/fcgi_config.h	1970-01-01 01:00:00.000000000 +0100
+++ ../include/fcgi_config.h	2020-11-17 18:08:42.348163900 +0100
@@ -0,0 +1,39 @@
+/* 
+ *  Copied to fcgi_config.h when building on WinNT without cygwin,
+ *  i.e. configure is not run.  See fcgi_config.h.in for details.
+ */
+
+#define HAVE_FPOS 1
+#define HAVE_LIMITS_H 1
+#define HAVE_STREAMBUF_CHAR_TYPE 1
+#define HAVE_STRERROR 1
+#undef HAVE_ARPA_INET_H
+#undef HAVE_DLFCN_H
+#undef HAVE_FILENO_PROTO
+#undef HAVE_INTTYPES_H
+#undef HAVE_IOSTREAM_WITHASSIGN_STREAMBUF
+#undef HAVE_LIBNSL
+#undef HAVE_LIBSOCKET
+#undef HAVE_MEMORY_H
+#undef HAVE_NETDB_H
+#undef HAVE_NETINET_IN_H
+#undef HAVE_PTHREAD
+#undef HAVE_SOCKADDR_UN_SUN_LEN
+#undef HAVE_SOCKLEN
+#undef HAVE_STDINT_H
+#undef HAVE_STDLIB_H
+#undef HAVE_STRING_H
+#undef HAVE_STRINGS_H
+#undef HAVE_SYS_PARAM_H
+#undef HAVE_SYS_SOCKET_H
+#undef HAVE_SYS_STAT_H
+#undef HAVE_SYS_TIME_H
+#undef HAVE_SYS_TYPES_H
+#undef HAVE_UNISTD_H
+#undef HAVE_VA_ARG_LONG_DOUBLE_BUG
+#undef PTHREAD_CREATE_JOINABLE
+#undef STDC_HEADERS
+#undef USE_LOCKING
+#undef const
+#undef inline
+#undef ssize_t
diff -Nur --exclude '*.obj' --exclude '*.exp' --exclude '*.lib' --exclude '*.idb' '--exclude=osgeo4w' fcgi2-2.4.2/libfcgi/fcgi_stdio.c ../libfcgi/fcgi_stdio.c
--- fcgi2-2.4.2/libfcgi/fcgi_stdio.c	2019-02-19 12:19:19.000000000 +0100
+++ ../libfcgi/fcgi_stdio.c	2020-11-17 18:08:42.350148400 +0100
@@ -107,6 +107,11 @@
 static int acceptCalled = FALSE;
 static int isCGI = FALSE;
 
+#ifdef WIN32
+#include <fcntl.h>
+#include <io.h>
+#endif
+
 int FCGI_Accept(void)
 {
     if(!acceptCalled) {
@@ -131,6 +136,11 @@
         FCGI_stdout->fcgx_stream = NULL;
         FCGI_stderr->stdio_stream = stderr;
         FCGI_stderr->fcgx_stream = NULL;
+
+#ifdef _WIN32
+	_setmode( _fileno(stdout), _O_BINARY);
+	_setmode( _fileno(stdin), _O_BINARY);
+#endif
     } else {
         FCGX_Stream *in, *out, *error;
         FCGX_ParamArray envp;
diff -Nur --exclude '*.obj' --exclude '*.exp' --exclude '*.lib' --exclude '*.idb' '--exclude=osgeo4w' fcgi2-2.4.2/libfcgi/libfcgi.mak ../libfcgi/libfcgi.mak
--- fcgi2-2.4.2/libfcgi/libfcgi.mak	2019-02-19 12:19:19.000000000 +0100
+++ ../libfcgi/libfcgi.mak	2020-11-17 18:16:22.459067300 +0100
@@ -50,7 +50,7 @@
     if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
 
 CPP=cl.exe
-CPP_PROJ=/nologo /MD /W3 /O2 /Ob2 /I "..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"$(INTDIR)\libfcgi.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c 
+CPP_PROJ=/nologo /MD /W3 /O2 /Ob2 /I "..\include" /DDLLAPI=__declspec(dllexport) /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"$(INTDIR)\libfcgi.pch" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c 
 
 .c{$(INTDIR)}.obj::
    $(CPP) @<<
@@ -90,7 +90,7 @@
 BSC32_SBRS= \
 	
 LINK32=link.exe
-LINK32_FLAGS=Ws2_32.lib /nologo /dll /pdb:none /machine:I386 /out:"$(OUTDIR)\libfcgi.dll" /implib:"$(OUTDIR)\libfcgi.lib" 
+LINK32_FLAGS=Ws2_32.lib /nologo /dll /pdb:none /out:"$(OUTDIR)\libfcgi.dll" /implib:"$(OUTDIR)\libfcgi.lib" 
 LINK32_OBJS= \
 	"$(INTDIR)\fcgi_stdio.obj" \
 	"$(INTDIR)\fcgiapp.obj" \
@@ -266,7 +266,7 @@
 
 !IF  "$(CFG)" == "release"
 
-CPP_SWITCHES=/nologo /MD /W3 /GX /O2 /Ob2 /I "..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"$(INTDIR)\libfcgi.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c 
+CPP_SWITCHES=/nologo /MD /W3 /EHsc /O2 /Ob2 /I "..\include" /DDLLAPI=__declspec(dllexport) /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"$(INTDIR)\libfcgi.pch" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
 
 "$(INTDIR)\fcgio.obj" : $(SOURCE) "$(INTDIR)"
 	$(CPP) @<<
@@ -276,7 +276,7 @@
 
 !ELSEIF  "$(CFG)" == "debug"
 
-CPP_SWITCHES=/nologo /MDd /W3 /Gm /Gi /GX /ZI /Od /I "..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR"$(INTDIR)\\" /Fp"$(INTDIR)\libfcgi.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c 
+CPP_SWITCHES=/nologo /MDd /W3 /Gm /Gi /EHsc /ZI /Od /I "..\include" /DDLLAPI=__declspec(dllexport) /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR"$(INTDIR)\\" /Fp"$(INTDIR)\libfcgi.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c
 
 "$(INTDIR)\fcgio.obj"	"$(INTDIR)\fcgio.sbr" : $(SOURCE) "$(INTDIR)"
 	$(CPP) @<<
