diff --git a/mex/sources/perfect_foresight_problem/DynamicModelCaller.cc b/mex/sources/perfect_foresight_problem/DynamicModelCaller.cc
index 2a59e0937..73d7a4642 100644
--- a/mex/sources/perfect_foresight_problem/DynamicModelCaller.cc
+++ b/mex/sources/perfect_foresight_problem/DynamicModelCaller.cc
@@ -17,15 +17,6 @@
* along with Dynare. If not, see .
*/
-#if defined(_WIN32) || defined(__CYGWIN32__)
-# ifndef NOMINMAX
-# define NOMINMAX // Do not define "min" and "max" macros
-# endif
-# include
-#else
-# include // unix/linux DLL (.so) handling routines
-#endif
-
#include
#include "DynamicModelCaller.hh"
@@ -34,7 +25,11 @@
std::string DynamicModelCaller::error_msg;
+#if defined(_WIN32) || defined(__CYGWIN32__)
+HINSTANCE DynamicModelDllCaller::dynamic_mex{nullptr};
+#else
void *DynamicModelDllCaller::dynamic_mex{nullptr};
+#endif
DynamicModelDllCaller::dynamic_tt_fct DynamicModelDllCaller::residual_tt_fct{nullptr}, DynamicModelDllCaller::g1_tt_fct{nullptr};
DynamicModelDllCaller::dynamic_deriv_fct DynamicModelDllCaller::residual_fct{nullptr}, DynamicModelDllCaller::g1_fct{nullptr};
diff --git a/mex/sources/perfect_foresight_problem/DynamicModelCaller.hh b/mex/sources/perfect_foresight_problem/DynamicModelCaller.hh
index 8c64938fd..4d10bb1ad 100644
--- a/mex/sources/perfect_foresight_problem/DynamicModelCaller.hh
+++ b/mex/sources/perfect_foresight_problem/DynamicModelCaller.hh
@@ -21,6 +21,15 @@
#include
#include
+#if defined(_WIN32) || defined(__CYGWIN32__)
+# ifndef NOMINMAX
+# define NOMINMAX // Do not define "min" and "max" macros
+# endif
+# include
+#else
+# include // unix/linux DLL (.so) handling routines
+#endif
+
class DynamicModelCaller
{
public:
@@ -39,7 +48,11 @@ public:
class DynamicModelDllCaller : public DynamicModelCaller
{
private:
+#if defined(_WIN32) || defined(__CYGWIN32__)
+ static HINSTANCE dynamic_mex;
+#else
static void *dynamic_mex;
+#endif
using dynamic_tt_fct = void (*)(const double *y, const double *x, int nb_row_x, const double *params, const double *steady_state, int it_, double *T);
using dynamic_deriv_fct = void (*) (const double *y, const double *x, int nb_row_x, const double *params, const double *steady_state, int it_, const double *T, double *deriv);
static dynamic_tt_fct residual_tt_fct, g1_tt_fct;