--- a/AutoPanoSift.h
+++ b/AutoPanoSift.h
@@ -1,6 +1,30 @@
+
+#ifndef AUTOPANOS_SIFT_H
+#define AUTOPANOS_SIFT_H
+
+#include "config.h"
+
+// include windows.h here
+// to prevent the global namespace to become polluted with 
+// badly named Windows macros
+
+
 #ifdef __cplusplus
 extern "C" {
 #endif
+
+#if defined(_WIN32)
+# define VC_EXTRALEAN
+#ifndef NOMINMAX
+# define NOMINMAX
+#endif
+# include <windows.h>
+# undef NOMINMAX
+# ifdef DIFFERENCE
+#  undef DIFFERENCE
+# endif
+#endif 
+
 #ifdef HAS_PANO13
 #include "pano13/filter.h"
 #include "pano13/panorama.h"
@@ -16,11 +40,22 @@
 #define bool int
 #define true 1
 #define false 0
-#define min(x,y) ((x)<(y)?(x):(y))
-#define max(x,y) ((x)>(y)?(x):(y))
-#define abs(x) ((x)>0?(x):(-x))
+#ifndef min
+  #define min(x,y) ((x)<(y)?(x):(y))
+#endif
+#ifndef max
+  #define max(x,y) ((x)>(y)?(x):(y))
+#endif
+#ifndef abs
+  #define abs(x) ((x)>0?(x):(-x))
+#endif
+
 #define Double_PositiveInfinity (1e+308)
 #define Double_NegativeInfinity (-1e+308)
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
 
 void Write(char* fmt, ...);
 void WriteLine(char* fmt, ...);
@@ -38,7 +73,7 @@
 void DoubleMap_delete(double** self);
 
 void*** PtrMap_new(int xDim, int yDim);
-void PtrMap_delete(void*** self, void* deletefn);
+void PtrMap_delete(void*** self, void (* deletefn)(void*));
 
 typedef struct Random Random;
 struct Random {
@@ -97,7 +132,7 @@
 int ArrayList_IndexOf(ArrayList* self, void* value);
 typedef struct IComparator IComparator;
 struct IComparator {
-	int (*compareTo)(IComparator* self, const void*, const void*);
+    int (*compareTo)(IComparator* self, const void*, const void*);
 };
 void ArrayList_Sort(ArrayList* self, IComparator*);
 
@@ -618,9 +653,11 @@
 void FilterPoint_delete(FilterPoint* self);
 
 typedef struct AreaFilter AreaFilter;
+
 struct AreaFilter {
-	
-};
+  int dummy; // dummy entry required by MSVC 2008	
+};
+
 AreaFilter* AreaFilter_new0();
 void AreaFilter_delete(AreaFilter* self);
 double AreaFilter_PolygonArea(AreaFilter* self, ArrayList* orderedPoints);
@@ -745,3 +782,4 @@
 BondBall* MultiMatch_BuildBondBall (MultiMatch* self, ArrayList* ransacFiltered, int bottomDefault);
 
 
+#endif // AUTOPANOS_SIFT_H