diff --git a/configure.ac b/configure.ac
index 9f30d29..29737da 100644
--- a/configure.ac
+++ b/configure.ac
@@ -120,6 +120,14 @@ AC_C_INLINE
 # libtool
 AC_PROG_CXX
 
+if "$os_win32" = "true"; then
+  if test "$enable_shared" = "yes"; then
+    AC_DEFINE(DLLBUILD, [], [Building a DLL])
+  else
+    AC_DEFINE(STATIC_LIBMODBUS, [], [Building a static library])
+  fi
+fi
+
 # Various types
 AC_TYPE_INT64_T
 AC_TYPE_SIZE_T
diff --git a/src/modbus.h b/src/modbus.h
index fa7ec4a..ae204ce 100644
--- a/src/modbus.h
+++ b/src/modbus.h
@@ -25,6 +25,8 @@
 # if defined(DLLBUILD)
 /* define DLLBUILD when building the DLL */
 #  define MODBUS_API __declspec(dllexport)
+# elif defined(STATIC_LIBMODBUS)
+#  define MODBUS_API
 # else
 #  define MODBUS_API __declspec(dllimport)
 # endif
