--- a/mfhdf/fortran/mfsdf.c
+++ b/mfhdf/fortran/mfsdf.c
@@ -30,7 +30,7 @@
 intf nscsnatt(intf *id, _fcd name, intf *nt, intf *count, void *data, intf *len);
 intf nsfsflmd(intf *id, intf *fillmode);
 
-#if defined H4_HAVE_WIN32_API && !defined CMAKE_INTDIR
+#if defined _MSC_VER && !defined CMAKE_INTDIR
 
 /*-----------------------------------------------------------------------------
  * Name:    scend
--- a/mfhdf/hdfimport/CMakeLists.txt
+++ b/mfhdf/hdfimport/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required (VERSION 3.18)
 project (HDF4_MFHDF_HDFIMPORT C)
 
-if (WIN32)
+if (MSVC)
   set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:LIBCMT")
 endif ()
 
--- a/mfhdf/hdiff/CMakeLists.txt
+++ b/mfhdf/hdiff/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required (VERSION 3.18)
 project (HDF4_MFHDF_HDIFF C)
 
-if (WIN32)
+if (MSVC)
   set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:LIBCMT")
 endif ()
 
--- a/mfhdf/libsrc/CMakeLists.txt
+++ b/mfhdf/libsrc/CMakeLists.txt
@@ -69,7 +69,7 @@
           ${HDF_EXTRA_FLAGS}
   )
   TARGET_C_PROPERTIES (${HDF4_MF_LIB_TARGET} STATIC)
-  target_link_libraries (${HDF4_MF_LIB_TARGET} PUBLIC "$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:MinGW>>:ws2_32.lib>")
+  target_link_libraries (${HDF4_MF_LIB_TARGET} PUBLIC "$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:MinGW>>:ws2_32;wsock32>")
   target_link_libraries (${HDF4_MF_LIB_TARGET} PUBLIC ${HDF4_SRC_LIB_TARGET})
   set_global_variable (HDF4_LIBRARIES_TO_EXPORT "${HDF4_LIBRARIES_TO_EXPORT};${HDF4_MF_LIB_TARGET}")
   H4_SET_LIB_OPTIONS (${HDF4_MF_LIB_TARGET} ${HDF4_MF_LIB_NAME} STATIC 0)
@@ -94,7 +94,7 @@
           ${HDF_EXTRA_FLAGS}
   )
   TARGET_C_PROPERTIES (${HDF4_MF_LIBSH_TARGET} SHARED)
-  target_link_libraries (${HDF4_MF_LIBSH_TARGET} PUBLIC "$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:MinGW>>:ws2_32.lib>")
+  target_link_libraries (${HDF4_MF_LIBSH_TARGET} PUBLIC "$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:MinGW>>:ws2_32;wsock32>")
   target_link_libraries (${HDF4_MF_LIBSH_TARGET} PUBLIC ${HDF4_SRC_LIBSH_TARGET})
   set_global_variable (HDF4_LIBRARIES_TO_EXPORT "${HDF4_LIBRARIES_TO_EXPORT};${HDF4_MF_LIBSH_TARGET}")
   H4_SET_LIB_OPTIONS (${HDF4_MF_LIBSH_TARGET} ${HDF4_MF_LIB_NAME} SHARED "MF")
--- a/config/cmake/ConfigureChecks.cmake
+++ b/config/cmake/ConfigureChecks.cmake
@@ -59,7 +59,11 @@
 endif ()
 
 if (WINDOWS)
-  set (CMAKE_REQUIRED_LIBRARIES "ws2_32.lib;wsock32.lib")
+  if (MINGW)
+    set (CMAKE_REQUIRED_LIBRARIES "ws2_32;wsock32")
+  else ()
+    set (CMAKE_REQUIRED_LIBRARIES "ws2_32.lib;wsock32.lib")
+  endif ()
   set (${HDF_PREFIX}_HAVE_WIN32_API 1)
   set (${HDF_PREFIX}_HAVE_SYSTEM 1)
   if (NOT UNIX AND NOT CYGWIN)
--- a/config/cmake/HDFMacros.cmake
+++ b/config/cmake/HDFMacros.cmake
@@ -202,7 +202,7 @@
 
   if (${libtype} MATCHES "SHARED")
     if (WIN32)
-      if (MINGW)
+      if (HDF4_MSVC_NAMING_CONVENTION AND MINGW)
         set_target_properties (${libtarget} PROPERTIES
             IMPORTED_IMPLIB "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${IMPORT_LIB_NAME}.lib"
             IMPORTED_LOCATION "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${IMPORT_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}"
@@ -263,7 +263,7 @@
 macro (HDF_README_PROPERTIES target_fortran)
   set (BINARY_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
   set (BINARY_PLATFORM "${CMAKE_SYSTEM_NAME}")
-  if (WIN32)
+  if (MSVC)
     set (BINARY_EXAMPLE_ENDING "zip")
     set (BINARY_INSTALL_ENDING "msi")
     if (CMAKE_CL_64)
--- a/hdf/src/H4api_adpt.h
+++ b/hdf/src/H4api_adpt.h
@@ -25,7 +25,7 @@
 
 #if defined(hdf_shared_EXPORTS)
 #if defined(_MSC_VER) || defined(__MINGW32__) /* MSVC Compiler Case */
-#define HDFERRPUBLIC extern __declspec(dllimport)
+#define HDFERRPUBLIC extern __declspec(dllexport)
 #define HDFPUBLIC    __declspec(dllexport)
 #define HDFLIBAPI    extern __declspec(dllexport)
 #define HDFFCLIBAPI  extern __declspec(dllimport)
