diff --git a/mex/sources/k_order_perturbation/dynamic_dll.cpp b/mex/sources/k_order_perturbation/dynamic_dll.cpp
index 4ee119dab5bd3d2f8c59fe3ff5e5a4f9000c3861..76d0f0b0f4e74381cccf9586b539a00cf7b1e3c1 100644
--- a/mex/sources/k_order_perturbation/dynamic_dll.cpp
+++ b/mex/sources/k_order_perturbation/dynamic_dll.cpp
@@ -75,7 +75,7 @@ DynamicModelDLL::DynamicModelDLL(const string &modName, const int y_length, cons
 
 DynamicModelDLL::~DynamicModelDLL()
 {
-#if !defined(__CYGWIN32__) && !defined(_WIN32)
+#if defined(__CYGWIN32__) || defined(_WIN32)
   FreeLibrary(dynamicHinstance);
 #else
   dlclose(dynamicHinstance);
diff --git a/mex/sources/k_order_perturbation/dynamic_dll.h b/mex/sources/k_order_perturbation/dynamic_dll.h
index f12996b3c891e7598b1765d37f343b8455f0f064..a7e38b41b5bf0c36391f053db1a3d55c602cfb81 100644
--- a/mex/sources/k_order_perturbation/dynamic_dll.h
+++ b/mex/sources/k_order_perturbation/dynamic_dll.h
@@ -24,7 +24,7 @@
 // K_ORDER_PERTURBATION_API functions as being imported from a DLL, wheras this DLL sees symbols
 // defined with this macro as being exported.
 
-#if (defined _WIN32) || (defined __CYGWIN32__)
+#if defined(_WIN32) || defined(__CYGWIN32__)
 # include <windows.h>
 # ifdef _MSC_VER
 #  define K_ORDER_PERTURBATION_API __declspec(dllexport)
@@ -39,7 +39,7 @@
 #include "dynare_exception.h"
 
 // <model>_Dynamic DLL pointer
-#if (defined _WIN32) || (defined __CYGWIN32__)
+#if defined(_WIN32) || defined(__CYGWIN32__)
 typedef void  *(DynamicFn)
 #else // Linux or Mac
 typedef void  (*DynamicFn)
@@ -56,7 +56,7 @@ typedef void *(mexFunctionPtr)(int nlhs, mxArray *plhs[], int nrhs, const mxArra
 class DynamicModelDLL
 {
 private:
-#if (defined _WIN32) || (defined __CYGWIN32__)
+#if defined(_WIN32) || defined(__CYGWIN32__)
   DynamicFn  *Dynamic; // pointer to the Dynamic function in DLL
 #else
   DynamicFn  Dynamic; // pointer to the Dynamic function in DLL