diff --git a/Common/OS.cpp b/Common/OS.cpp
index c01c30fded326cabb69e96efa17803451f0694ae..b8fd20a55fe376adefb09686ab5f74832376b30f 100644
--- a/Common/OS.cpp
+++ b/Common/OS.cpp
@@ -13,6 +13,7 @@
 #include <sys/stat.h>
 #include <signal.h>
 #include <time.h>
+#include <math.h>
 
 #if !defined(WIN32) || defined(__CYGWIN__)
 #include <unistd.h>
@@ -164,3 +165,17 @@ int SystemCall(const char *command)
   return system(command);
 #endif
 }
+
+//HACK: allow the use of mixed debug/non-debug code with MSVC
+#if (defined (_MSC_VER) && defined (_DEBUG))
+extern "C" {
+   _CRTIMP void __cdecl _invalid_parameter_noinfo(void) {  }
+}
+#endif
+
+//HACK: fix undefined hypot with MSVC
+#if defined (_MSC_VER)
+extern "C" {
+  double hypot(double x, double y){ return _hypot(x, y); }
+}
+#endif
diff --git a/Common/VertexArray.h b/Common/VertexArray.h
index d294e372bbc19a448e6355ad4ed3ec4b6836adfe..dc67e6fa4a18f1a85bc1e8fe8c7de8a52216c930 100644
--- a/Common/VertexArray.h
+++ b/Common/VertexArray.h
@@ -136,7 +136,9 @@ class VertexArray{
   int getNumVerticesPerElement() { return _numVerticesPerElement; }
   // return the number of element pointers
   int getNumElementPointers() { return _elements.size(); }
-  // return a pointer to the raw vertex array
+  // return a pointer to the raw vertex array (warning: 1) we don't 
+  // range check 2) calling this if _vertices.size() == 0 will cause
+  // some compilers to throw an exception)
   float *getVertexArray(int i=0){ return &_vertices[i]; }
   // return a pointer to the raw normal array
   char *getNormalArray(int i=0){ return &_normals[i]; }
diff --git a/Geo/GEdge.cpp b/Geo/GEdge.cpp
index f887184cdd3b3c62580a650426d17c99606f611f..80e1316061d805f6bb15871da06173d8ba94ef25 100644
--- a/Geo/GEdge.cpp
+++ b/Geo/GEdge.cpp
@@ -48,6 +48,7 @@ void GEdge::getNumMeshElements(unsigned *const c) const
 
 MElement *const *GEdge::getStartElementType(int type) const
 {
+  if(lines.empty()) return 0; // msvc would throw an exception
   return reinterpret_cast<MElement *const *>(&lines[0]);
 }
 
diff --git a/Geo/GFace.cpp b/Geo/GFace.cpp
index 56a7378bac874abe5e2f9f786acbd9f23b2a61c9..32b67ec52388cdd22996016c902fe1543552922d 100644
--- a/Geo/GFace.cpp
+++ b/Geo/GFace.cpp
@@ -75,8 +75,10 @@ MElement *const *GFace::getStartElementType(int type) const
 {
   switch(type) {
   case 0:
+    if(triangles.empty()) return 0; // msvc would throw an exception
     return reinterpret_cast<MElement *const *>(&triangles[0]);
   case 1:
+    if(quadrangles.empty()) return 0; // msvc would throw an exception
     return reinterpret_cast<MElement *const *>(&quadrangles[0]);
   }
   return 0;
diff --git a/Geo/GRegion.cpp b/Geo/GRegion.cpp
index f785033ee0f66b111e9cdb0448c5ba1f5dbb0cee..ec47ece13763c3bac04628666319e2718f5357be 100644
--- a/Geo/GRegion.cpp
+++ b/Geo/GRegion.cpp
@@ -56,12 +56,16 @@ MElement *const *GRegion::getStartElementType(int type) const
 {
   switch(type) {
   case 0:
+    if(tetrahedra.empty()) return 0; // msvc would throw an exception
     return reinterpret_cast<MElement *const *>(&tetrahedra[0]);
   case 1:
+    if(hexahedra.empty()) return 0; // msvc would throw an exception
     return reinterpret_cast<MElement *const *>(&hexahedra[0]);
   case 2:
+    if(prisms.empty()) return 0; // msvc would throw an exception
     return reinterpret_cast<MElement *const *>(&prisms[0]);
   case 3:
+    if(pyramids.empty()) return 0; // msvc would throw an exception
     return reinterpret_cast<MElement *const *>(&pyramids[0]);
   }
   return 0;
diff --git a/Mesh/Partition.cpp b/Mesh/Partition.cpp
index 6da45ea7348a648af31eed3f89c630e4f563f727..3bc6cc102f81799949d22c5474689933e7afea3e 100644
--- a/Mesh/Partition.cpp
+++ b/Mesh/Partition.cpp
@@ -545,8 +545,9 @@ struct MakeGraphFromEntity
     int nType = entity->getNumElementTypes();
     for(int iType = 0; iType != nType; ++iType) {
       // Loop over all elements in a type
-      MElement *const *element = entity->getStartElementType(iType);
       const int nElem = numElem[iType];
+      if(!nElem) continue;
+      MElement *const *element = entity->getStartElementType(iType);
       for(int iElem = 0; iElem != nElem; ++iElem) {
         const int nFace = DimTr<DIM>::getNumFace(element[iElem]);
         // Insert this element into the map of graph vertices
@@ -619,8 +620,9 @@ struct MatchBoElemToGrVertex
     int nType = entity->getNumElementTypes();
     for(int iType = 0; iType != nType; ++iType) {
       // Loop over all elements in a type
-      MElement *const *element = entity->getStartElementType(iType);
       const int nElem = numElem[iType];
+      if(!nElem) continue;
+      MElement *const *element = entity->getStartElementType(iType);
       for(int iElem = 0; iElem != nElem; ++iElem) {
         FaceT face = DimTr<DIM>::getFace(element[iElem], 0);
         const typename FaceMap::const_iterator faceMapIt = faceMap.find(face);
diff --git a/Numeric/Numeric.cpp b/Numeric/Numeric.cpp
index 2f6e18df561e1ee85e179acdec0cb603de878e79..cb5af2bfb3af5f9f8b5cb938780eb0196056b712 100644
--- a/Numeric/Numeric.cpp
+++ b/Numeric/Numeric.cpp
@@ -13,34 +13,20 @@
 
 #if defined(HAVE_GSL)
 
-#include <gsl/gsl_version.h>
 #include <gsl/gsl_errno.h>
 #include <gsl/gsl_vector.h>
 #include <gsl/gsl_linalg.h>
 
-void new_handler(const char *reason, const char *file, int line,
-                 int gsl_errno)
+void my_gsl_msg(const char *reason, const char *file, int line,
+		int gsl_errno)
 {
   Msg::Error("GSL: %s (%s, line %d)", reason, file, line);
 }
 
 int check_gsl()
 {
-  // check version
-  int major, minor;
-  if(!sscanf(gsl_version, "%d.%d", &major, &minor)){
-    Msg::Fatal("Cannot retreive GSL version");
-    return 0;
-  }
-  if(major < 1 || (major == 1 && minor < 2)) {
-    Msg::Error("Your GSL version (%d.%d.X) has a bug in the singular value",
-        major, minor);
-    Msg::Error("decomposition code. Please upgrade to version 1.2 or above.");
-    Msg::Fatal("You can download the GSL from http://sources.redhat.com/gsl/");
-    return 0;
-  }
   // set new error handler
-  gsl_set_error_handler(&new_handler);
+  gsl_set_error_handler(&my_gsl_msg);
 
   // initilize robust geometric predicates
   gmsh::exactinit() ;
@@ -52,6 +38,7 @@ int check_gsl()
 #define NRANSI
 #include "nrutil.h"
 void dsvdcmp(double **a, int m, int n, double w[], double **v);
+
 int check_gsl()
 {
   // initilize robust geometric predicates
diff --git a/contrib/Metis/Makefile b/contrib/Metis/Makefile
index 3f6fd8313cf5f0e5c1e1e3ee44433d6a7de944e6..714f5eaf4adc852d793592759cfa3573ff318a6e 100644
--- a/contrib/Metis/Makefile
+++ b/contrib/Metis/Makefile
@@ -76,10 +76,10 @@ cpobj: ${OBJ}
 	cp -f ${OBJ} ../../lib/
 
 .c${OBJEXT}:
-	${CC} ${CFLAGS} ${DASH}c $< ${DASH}o ${<:.c=${OBJEXT}}
+	${CC} ${CFLAGS} ${DASH}c $<
 
 clean:
-	rm -f *.o *.obj
+	${RM} *.o *.obj
 
 depend:
 	(sed '/^# DO NOT DELETE THIS LINE/q' Makefile && \
diff --git a/contrib/Metis/metis.h b/contrib/Metis/metis.h
index ff4d5ac96bf2968c726ea536554813b3ec17ac4a..eebe40f4f4cfb0cab63a26a2e50dc659d94cbe55 100644
--- a/contrib/Metis/metis.h
+++ b/contrib/Metis/metis.h
@@ -8,7 +8,7 @@
  * Started 8/27/94
  * George
  *
- * $Id: metis.h,v 1.1 2005-09-21 17:29:38 geuzaine Exp $
+ * $Id: metis.h,v 1.2 2008-09-22 13:23:50 geuzaine Exp $
  */
 
 
@@ -18,7 +18,7 @@
 #else
 #include <malloc.h>
 #endif
-#include <strings.h>
+//#include <strings.h>
 #include <string.h>
 #include <ctype.h>
 #include <math.h>
diff --git a/utils/misc/variables.msvc b/utils/misc/variables.msvc
index 1865a51b07bb72ba0a47820b15e14e25cb926288..21678ece15e366c17bb5f8f005eaa884f109e9ae 100644
--- a/utils/misc/variables.msvc
+++ b/utils/misc/variables.msvc
@@ -12,13 +12,18 @@
 MAKE=C:\src\gmsh\utils\misc\gmake.exe
 
 # Change the following to select which version to build:
+ENABLE_GSL=1
 ENABLE_GUI=0
 ENABLE_PARSER=1
 ENABLE_POSTPRO=1
 ENABLE_TETGEN=1
 ENABLE_NETGEN=0
+ENABLE_METIS=1
 ENABLE_OCC=0
 
+# If you selected ENABLE_GSL, specify where the GSL is installed
+GSL_PREFIX=C:\src\gsl-1.8
+
 # If you selected ENABLE_GUI, specify where FLTK is installed
 FLTK_PREFIX=C:\src\fltk-1.1.9
 
@@ -32,8 +37,8 @@ UNAME=WIN32MSVC
 HOSTNAME=localhost
 
 # The names of the C and C++ compilers
-CC=cl
-CXX=cl /EHsc /nologo /GR /MT
+CC=cl /nologo /MTd
+CXX=cl /EHsc /nologo /GR /MTd
 
 # Debug/Release Single/Multi-threaded Lib/Dll flags:
 # Rel-Sin-Lib: /ML
@@ -57,7 +62,6 @@ LINKER=cl /F16777216
 # All compiler flags except optimization flags
 FLAGS=/DWIN32 /D_USE_MATH_DEFINES /DHAVE_NO_DLL /DHAVE_NO_SOCKLEN_T
 FLAGS+=/DHAVE_ANN /DHAVE_MATH_EVAL
-
 FLAGS+=/D_CRT_SECURE_NO_DEPRECATE
 
 # Additional system includes ($INCLUDE is automatically defined by MSVC when
@@ -71,6 +75,10 @@ OPTIM=/O2
 GMSH_DIRS=Common Geo Mesh Numeric contrib/ANN contrib/MathEval contrib/NR
 
 # Optional stuff
+ifeq (${ENABLE_GSL},1)
+  FLAGS+=/DHAVE_GSL /I${GSL_PREFIX}
+  GMSH_LIBS+=${GSL_PREFIX}/lib/gsl.lib ${GSL_PREFIX}/lib/gslcblas.lib
+endif
 ifeq (${ENABLE_PARSER},1)
   GMSH_DIRS+=Parser
 else
@@ -89,22 +97,26 @@ ifeq (${ENABLE_TETGEN},1)
   FLAGS+=/DHAVE_TETGEN
   GMSH_DIRS+=contrib/Tetgen
 endif
+ifeq (${ENABLE_METIS},1)
+  FLAGS+=/DHAVE_METIS
+  GMSH_DIRS+=contrib/Metis
+endif
 ifeq (${ENABLE_OCC},1)
   FLAGS+=/DHAVE_OCC /DHAVE_NO_OCC_CONFIG_H /DWNT /I"${OCC_PREFIX}/inc"
-  GMSH_LIBS+=${OCC_PREFIX}/lib/*.lib
+  GMSH_LIBS+=${OCC_PREFIX}/win32/bin/*.lib
 endif
 
 ifeq (${ENABLE_GUI},1)
-  LINKER+=/SUBSYSTEM:WINDOWS
-  GMSH_DIRS+=Graphics Fltk
-  FLAGS+=/DHAVE_FLTK /I"${FLTK_PREFIX}"
-  GMSH_LIBS+=Fltk/Main.obj lib/*.lib lib/*.lib ${FLTK_PREFIX}\lib\fltk*.lib
+  GMSH_DIRS+=Graphics Fltk contrib/NativeFileChooser
+  FLAGS+=/DHAVE_FLTK /DHAVE_NATIVE_FILE_CHOOSER /I"${FLTK_PREFIX}"
+  GMSH_LIBS+=Fltk/Main.obj lib/*.lib ${FLTK_PREFIX}\lib\fltk*.lib
   GMSH_LIBS+=glu32.lib opengl32.lib advapi32.lib gdi32.lib user32.lib
-  GMSH_LIBS+=shell32.lib ole32.lib uuid.lib comctl32.lib
+  GMSH_LIBS+=shell32.lib ole32.lib uuid.lib comctl32.lib comdlg32.lib
   GMSH_LIBS+=wsock32.lib winspool.lib ws2_32.lib Fltk/Win32Icon.res
-  GMSH_LIBS+=/link /NODEFAULTLIB:libcmt.lib
+  GMSH_LIBS+=/link /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:msvcrt.lib
+#  GMSH_LIBS+=/SUBSYSTEM:WINDOWS
 else
-  GMSH_LIBS=Common/Main.obj lib/*.lib
+  GMSH_LIBS+=Common/Main.obj lib/*.lib
 endif
 
 # How you create a static library on this machine