 include/FLAC/ordinals.h               | 15 +++++++++++++++
 include/share/alloc.h                 |  4 +++-
 include/share/compat.h                |  3 +++
 src/libFLAC/bitreader.c               |  5 +++++
 src/libFLAC/bitwriter.c               |  5 +++++
 src/libFLAC/include/private/bitmath.h |  2 +-
 src/libFLAC/lpc.c                     | 17 ++++++++++++++++-
 src/libFLAC/metadata_object.c         |  5 +++++
 src/libFLAC/stream_decoder.c          |  4 ++++
 9 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/include/FLAC/ordinals.h b/include/FLAC/ordinals.h
index 647b07e..85f90b7 100644
--- a/include/FLAC/ordinals.h
+++ b/include/FLAC/ordinals.h
@@ -35,7 +35,21 @@
 /* If your compiler does not provide <stdint.h> you should provide a replacement
  * which hss suitable replacements for the following intX_T and uintX_t types.
  */
+#if defined(_MSC_VER) && _MSC_VER < 1600
+typedef __int8 FLAC__int8;
+typedef unsigned __int8 FLAC__uint8;
 
+typedef __int16 FLAC__int16;
+typedef __int32 FLAC__int32;
+typedef __int64 FLAC__int64;
+typedef unsigned __int16 FLAC__uint16;
+typedef unsigned __int32 FLAC__uint32;
+typedef unsigned __int64 FLAC__uint64;
+
+typedef int FLAC__bool;
+
+typedef FLAC__uint8 FLAC__byte;
+#else
 #include <stdint.h>
 
 typedef int8_t FLAC__int8;
@@ -51,6 +65,7 @@ typedef uint64_t FLAC__uint64;
 typedef int FLAC__bool;
 
 typedef FLAC__uint8 FLAC__byte;
+#endif
 
 #ifdef true
 #undef true
diff --git a/include/share/alloc.h b/include/share/alloc.h
index 7aa17f7..b2a8a7b 100644
--- a/include/share/alloc.h
+++ b/include/share/alloc.h
@@ -46,10 +46,12 @@
 #endif
 #include <stdlib.h> /* for size_t, malloc(), etc */
 
+#include "share/compat.h"
+
 #ifndef SIZE_MAX
 # ifndef SIZE_T_MAX
 #  ifdef _MSC_VER
-#   define SIZE_T_MAX UINT_MAX /* What happens on 64 bit windows? */
+#   define SIZE_T_MAX SIZE_MAX
 #  else
 #   error
 #  endif
diff --git a/include/share/compat.h b/include/share/compat.h
index 983b045..342d137 100644
--- a/include/share/compat.h
+++ b/include/share/compat.h
@@ -65,7 +65,10 @@
 #endif
 
 #if defined(_MSC_VER)
+#if _MSC_VER < 1500 
+/* Visual Studio 2008 supports the restrict keyword. */
 #define restrict __restrict
+#endif
 #define inline __inline
 #endif
 
diff --git a/src/libFLAC/bitreader.c b/src/libFLAC/bitreader.c
index 792d6dd..4bbbb35 100644
--- a/src/libFLAC/bitreader.c
+++ b/src/libFLAC/bitreader.c
@@ -43,6 +43,11 @@
 #include "share/compat.h"
 #include "share/endswap.h"
 
+#if defined(_MSC_VER) && _MSC_VER < 1600
+#include "FLAC/ordinals.h"
+typedef FLAC__uint32 uint32_t;
+#endif
+
 /* Things should be fastest when this matches the machine word size */
 /* WATCHOUT: if you change this you must also change the following #defines down to FLAC__clz_uint32 below to match */
 /* WATCHOUT: there are a few places where the code will not work unless uint32_t is >= 32 bits wide */
diff --git a/src/libFLAC/bitwriter.c b/src/libFLAC/bitwriter.c
index 7d61d73..5b83c08 100644
--- a/src/libFLAC/bitwriter.c
+++ b/src/libFLAC/bitwriter.c
@@ -43,6 +43,11 @@
 #include "share/compat.h"
 #include "share/endswap.h"
 
+#if defined(_MSC_VER) && _MSC_VER < 1600
+#include "FLAC/ordinals.h"
+typedef FLAC__uint32 uint32_t;
+#endif
+
 /* Things should be fastest when this matches the machine word size */
 /* WATCHOUT: if you change this you must also change the following #defines down to SWAP_BE_WORD_TO_HOST below to match */
 /* WATCHOUT: there are a few places where the code will not work unless uint32_t is >= 32 bits wide */
diff --git a/src/libFLAC/include/private/bitmath.h b/src/libFLAC/include/private/bitmath.h
index 4e60f78..fddba13 100644
--- a/src/libFLAC/include/private/bitmath.h
+++ b/src/libFLAC/include/private/bitmath.h
@@ -33,7 +33,7 @@
 #define FLAC__PRIVATE__BITMATH_H
 
 #include "FLAC/ordinals.h"
-
+#include "share/compat.h"
 /* for CHAR_BIT */
 #include <limits.h>
 
diff --git a/src/libFLAC/lpc.c b/src/libFLAC/lpc.c
index 66a6899..2799e84 100644
--- a/src/libFLAC/lpc.c
+++ b/src/libFLAC/lpc.c
@@ -34,7 +34,22 @@
 #endif
 
 #include <math.h>
-#include <inttypes.h>
+
+#ifndef _MSC_VER
+#  include <inttypes.h>
+#elif _MSC_VER >= 1600
+/* Visual Studio 2010 has reasonable C99 support */
+#  include <stdint.h>
+#define PRId64 "lld"
+#else
+/* Earlier versions do not */
+#include "FLAC/ordinals.h"
+#include <limits.h>
+typedef FLAC__uint32 uint32_t;
+#define UINT32_MAX _UI32_MAX
+#define PRId64 "I64d"
+#endif
+
 #include "FLAC/assert.h"
 #include "FLAC/format.h"
 #include "private/bitmath.h"
diff --git a/src/libFLAC/metadata_object.c b/src/libFLAC/metadata_object.c
index 22d39d4..7163f02 100644
--- a/src/libFLAC/metadata_object.c
+++ b/src/libFLAC/metadata_object.c
@@ -46,6 +46,11 @@
 /* Alias the first (in share/alloc.h) to the second (in src/libFLAC/memory.c). */
 #define safe_malloc_mul_2op_ safe_malloc_mul_2op_p
 
+#if defined(_MSC_VER) && _MSC_VER <= 1500
+#include <limits.h>
+#define UINT32_MAX _UI32_MAX
+#endif
+
 
 /****************************************************************************
  *
diff --git a/src/libFLAC/stream_decoder.c b/src/libFLAC/stream_decoder.c
index 789db1b..5ef27b7 100644
--- a/src/libFLAC/stream_decoder.c
+++ b/src/libFLAC/stream_decoder.c
@@ -55,7 +55,11 @@
 
 
 /* technically this should be in an "export.c" but this is convenient enough */
+#ifdef FLAC__HAS_OGG
 FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC = FLAC__HAS_OGG ;
+#else
+FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC = 0 ;
+#endif
 
 
 /***********************************************************************
