diff --git a/include/nsthread.h b/include/nsthread.h
index 51278e88..07c73f37 100644
--- a/include/nsthread.h
+++ b/include/nsthread.h
@@ -216,6 +216,12 @@ MSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 version 16.0)
 #  define NS_INVALID_PID        (-1)
 #  define NS_INVALID_SOCKET     (-1)
 #  define NS_INVALID_FD         (-1)
+
+typedef int ns_sockerrno_t;
+typedef long uid_t;
+typedef long gid_t;
+typedef long suseconds_t;
+
 # endif
 
 
diff --git a/nsd/connchan.c b/nsd/connchan.c
index cc89c3a8..3844b9f3 100644
--- a/nsd/connchan.c
+++ b/nsd/connchan.c
@@ -47,12 +47,12 @@
 #  define be32toh(x) betoh32(x)
 #  define be64toh(x) betoh64(x)
 # endif
-#elif defined(__APPLE__) || defined(_MSC_VER)
+#elif defined(__APPLE__) || defined(_WIN32)
 # define be16toh(x) ntohs(x)
 # define htobe16(x) htons(x)
 # define be32toh(x) ntonl(x)
 # define htobe32(x) htonl(x)
-# if defined(_MSC_VER)
+# if defined(_WIN32)
 /*
  * Not sure, why htonll() and ntohll() are undefined in Visual Studio 2019:
  *
diff --git a/nsd/dstring.c b/nsd/dstring.c
index 4e11f354..a6b80c0b 100644
--- a/nsd/dstring.c
+++ b/nsd/dstring.c
@@ -239,7 +239,7 @@ Ns_DStringVPrintf(Ns_DString *dsPtr, const char *fmt, va_list apSrc)
      * Check for overflow and retry. For win32 just double the buffer size
      * and iterate, otherwise we should get this correct first time.
      */
-#if defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1900
+#if defined(_WIN32) && (!defined(_MSC_VER) || _MSC_VER < 1900)
     while (result == -1 && errno == ERANGE) {
         newLength = dsPtr->spaceAvl * 2;
 #else
diff --git a/nsd/exec.c b/nsd/exec.c
index 899dbdde..a7b5928f 100644
--- a/nsd/exec.c
+++ b/nsd/exec.c
@@ -38,7 +38,7 @@
 #ifdef _WIN32
 
 # include <process.h>
-# include <VersionHelpers.h>
+# include <versionhelpers.h>
 static void Set2Argv(Ns_DString *dsPtr, const Ns_Set *env);
 
 #else
