diff --git a/Foreign/CUDA/Internal/Offsets.hsc b/Foreign/CUDA/Internal/Offsets.hsc
--- a/Foreign/CUDA/Internal/Offsets.hsc
+++ b/Foreign/CUDA/Internal/Offsets.hsc
@@ -11,7 +11,7 @@
 -- Runtime API
 --------------------------------------------------------------------------------
 
-#include <cuda_runtime_api.h>
+#include "cbits/stubs.h"
 
 devNameOffset, devMaxThreadDimOffset, devMaxGridSizeOffset :: Int
 
diff --git a/Foreign/CUDA/Runtime/Device.chs b/Foreign/CUDA/Runtime/Device.chs
--- a/Foreign/CUDA/Runtime/Device.chs
+++ b/Foreign/CUDA/Runtime/Device.chs
@@ -28,7 +28,7 @@
 
 ) where
 
-#include <cuda_runtime_api.h>
+#include "cbits/stubs.h"
 {# context lib="cudart" #}
 
 -- Friends
diff --git a/Foreign/CUDA/Runtime/Error.chs b/Foreign/CUDA/Runtime/Error.chs
--- a/Foreign/CUDA/Runtime/Error.chs
+++ b/Foreign/CUDA/Runtime/Error.chs
@@ -31,7 +31,6 @@
 import System.IO.Unsafe
 
 #include "cbits/stubs.h"
-#include <cuda_runtime_api.h>
 {# context lib="cudart" #}
 
 
diff --git a/Foreign/CUDA/Runtime/Event.chs b/Foreign/CUDA/Runtime/Event.chs
--- a/Foreign/CUDA/Runtime/Event.chs
+++ b/Foreign/CUDA/Runtime/Event.chs
@@ -20,7 +20,7 @@
 
 ) where
 
-#include <cuda_runtime_api.h>
+#include "cbits/stubs.h"
 {# context lib="cudart" #}
 
 -- Friends
diff --git a/Foreign/CUDA/Runtime/Exec.chs b/Foreign/CUDA/Runtime/Exec.chs
--- a/Foreign/CUDA/Runtime/Exec.chs
+++ b/Foreign/CUDA/Runtime/Exec.chs
@@ -21,7 +21,6 @@
 ) where
 
 #include "cbits/stubs.h"
-#include <cuda_runtime_api.h>
 {# context lib="cudart" #}
 
 -- Friends
diff --git a/Foreign/CUDA/Runtime/Marshal.chs b/Foreign/CUDA/Runtime/Marshal.chs
--- a/Foreign/CUDA/Runtime/Marshal.chs
+++ b/Foreign/CUDA/Runtime/Marshal.chs
@@ -38,7 +38,7 @@
 
 ) where
 
-#include <cuda_runtime_api.h>
+#include "cbits/stubs.h"
 {# context lib="cudart" #}
 
 -- Friends
diff --git a/Foreign/CUDA/Runtime/Stream.chs b/Foreign/CUDA/Runtime/Stream.chs
--- a/Foreign/CUDA/Runtime/Stream.chs
+++ b/Foreign/CUDA/Runtime/Stream.chs
@@ -18,7 +18,7 @@
 
 ) where
 
-#include <cuda_runtime_api.h>
+#include "cbits/stubs.h"
 {# context lib="cudart" #}
 
 -- Friends
diff --git a/Foreign/CUDA/Runtime/Texture.chs b/Foreign/CUDA/Runtime/Texture.chs
--- a/Foreign/CUDA/Runtime/Texture.chs
+++ b/Foreign/CUDA/Runtime/Texture.chs
@@ -29,7 +29,7 @@
 import Foreign
 import Foreign.C
 
-#include <cuda_runtime_api.h>
+#include "cbits/stubs.h"
 {# context lib="cudart" #}
 
 #c
diff --git a/Foreign/CUDA/Runtime/Utils.chs b/Foreign/CUDA/Runtime/Utils.chs
--- a/Foreign/CUDA/Runtime/Utils.chs
+++ b/Foreign/CUDA/Runtime/Utils.chs
@@ -12,7 +12,7 @@
 module Foreign.CUDA.Runtime.Utils (runtimeVersion, driverVersion)
   where
 
-#include <cuda_runtime_api.h>
+#include "cbits/stubs.h"
 {# context lib="cudart" #}
 
 -- Friends
diff --git a/cbits/stubs.h b/cbits/stubs.h
--- a/cbits/stubs.h
+++ b/cbits/stubs.h
@@ -5,14 +5,21 @@
 #ifndef C_STUBS_H
 #define C_STUBS_H
 
+#if defined(mingw32_TARGET_OS)
+#include <host_defines.h>
+#undef CUDARTAPI
+#define CUDARTAPI __stdcall
+#endif
+
 /*
  * We need to work around some shortcomings in the C parser of c2hs by disabling advanced attributes etc on Apple platforms.
  */
-#ifdef __APPLE__ 
+#ifdef __APPLE__
 #define _ANSI_SOURCE
 #define __AVAILABILITY__
 #define __OSX_AVAILABLE_STARTING(_mac, _iphone)
-#define __OSX_AVAILABLE_BUT_DEPRECATED(_macIntro, _macDep, _iphoneIntro, _iphoneDep) 
+#define __OSX_AVAILABLE_BUT_DEPRECATED(_macIntro, _macDep, _iphoneIntro, _iphoneDep)
+#define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(_osxIntro, _osxDep, _iosIntro, _iosDep, _msg)
 #endif
 
 #include <cuda.h>
diff --git a/configure b/configure
--- a/configure
+++ b/configure
@@ -624,6 +624,7 @@
 
 ac_subst_vars='LTLIBOBJS
 LIBOBJS
+cuda_ghci_libs
 cuda_frameworks
 cuda_libraries
 cuda_lib_path
@@ -1655,6 +1656,52 @@
 
 } # ac_fn_c_check_header_compile
 
+# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES
+# ---------------------------------------------
+# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
+# accordingly.
+ac_fn_c_check_decl ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  as_decl_name=`echo $2|sed 's/ *(.*//'`
+  as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
+$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+#ifndef $as_decl_name
+#ifdef __cplusplus
+  (void) $as_decl_use;
+#else
+  (void) $as_decl_name;
+#endif
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_decl
+
 # ac_fn_c_try_link LINENO
 # -----------------------
 # Try to link conftest.$ac_ext, and return whether this succeeded.
@@ -3097,8 +3144,26 @@
 # that, otherwise choose the default
 #
 if test "$NVCC" != ""; then
-    cuda_prefix="$(dirname "$(dirname "$NVCC")")"
-    cuda_c2hsflags="--cpp="$NVCC" --cppopts=-E --cppopts=-arch=sm_20 "
+  case $target in
+    *mingw* )
+    # We need a Windows-style path, but mingw doesn't include cygpath,
+    # thus this hack.
+    NVCC=`cd $(dirname $NVCC) && pwd -W`/$(basename nvcc)
+    ;;
+  esac
+
+  cuda_prefix="$(dirname "$(dirname "$NVCC")")"
+
+  case $target in
+    *mingw* )
+      cuda_c2hsflags="--cppopts=-E --cppopts=-arch=sm_20 --cppopts="-D${target_os}_TARGET_OS=1" "
+      CPPFLAGS+=" "-D${target_os}_TARGET_OS=1" "
+      ;;
+    * )
+      cuda_c2hsflags="--cpp="$NVCC" --cppopts=-E --cppopts=-arch=sm_20 "
+      ;;
+  esac
+
 else
     echo "WARNING: Cannot find the CUDA compiler 'nvcc'. This is likely to cause problems."
     cuda_prefix="/usr/local/cuda"
@@ -3118,6 +3183,16 @@
     #LDFLAGS+=" -Xlinker -rpath ${cuda_lib_path} "
     #CPPFLAGS+=" -arch ${target_cpu} "
     ;;
+  mingw*)
+    case $target_cpu in
+      x86_64*)
+        cuda_lib_path="${cuda_prefix}/lib/x64"
+        ;;
+      *)
+        cuda_lib_path="${cuda_prefix}/lib/Win32"
+        ;;
+    esac
+    ;;
   *)
     case $target_cpu in
       x86_64*)
@@ -3607,7 +3682,52 @@
 
 done
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing cuDriverGetVersion" >&5
+
+case $target in
+  *mingw32* )
+    # AC_SEARCH_LIBS doesn't work on Win32 with functions that use the
+    # stdcall calling convention, so we use AC_CHECK_DELCS instead.
+    LIBS+="-lcuda -lcudart"
+    ac_fn_c_check_decl "$LINENO" "cuDriverGetVersion" "ac_cv_have_decl_cuDriverGetVersion" "#include <cuda.h>
+"
+if test "x$ac_cv_have_decl_cuDriverGetVersion" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_CUDRIVERGETVERSION $ac_have_decl
+_ACEOF
+if test $ac_have_decl = 1; then :
+
+else
+  as_fn_error $? "could not find CUDA driver library${longerror}" "$LINENO" 5
+fi
+
+    ac_fn_c_check_decl "$LINENO" "cudaRuntimeGetVersion" "ac_cv_have_decl_cudaRuntimeGetVersion" "#include <cuda_runtime_api.h>
+"
+if test "x$ac_cv_have_decl_cudaRuntimeGetVersion" = xyes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_CUDARUNTIMEGETVERSION $ac_have_decl
+_ACEOF
+if test $ac_have_decl = 1; then :
+
+else
+  as_fn_error $? "could not find CUDA runtime library${longerror}" "$LINENO" 5
+fi
+
+
+    cuda_ghci_libs+="`nm ${cuda_lib_path}/cuda.lib | head -2 | tail -1 | sed -e 's/://' -e 's/.dll//'` "
+    cuda_ghci_libs+="`nm ${cuda_lib_path}/cudart.lib | head -2 | tail -1 | sed -e 's/://' -e 's/.dll//'` "
+    ;;
+  *)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing cuDriverGetVersion" >&5
 $as_echo_n "checking for library containing cuDriverGetVersion... " >&6; }
 if ${ac_cv_search_cuDriverGetVersion+:} false; then :
   $as_echo_n "(cached) " >&6
@@ -3665,7 +3785,7 @@
   as_fn_error $? "could not find CUDA driver library${longerror}" "$LINENO" 5
 fi
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing cudaRuntimeGetVersion" >&5
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing cudaRuntimeGetVersion" >&5
 $as_echo_n "checking for library containing cudaRuntimeGetVersion... " >&6; }
 if ${ac_cv_search_cudaRuntimeGetVersion+:} false; then :
   $as_echo_n "(cached) " >&6
@@ -3723,6 +3843,8 @@
   as_fn_error $? "could not find CUDA runtime library${longerror}" "$LINENO" 5
 fi
 
+    ;;
+esac
 
 # Populate the buildinfo, with the search paths and any target specific options
 #
@@ -3738,6 +3860,7 @@
 for x in $LIBS; do
     cuda_libraries+="${x#-l} "
 done
+
 
 
 
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -22,8 +22,26 @@
 # that, otherwise choose the default
 #
 if test "$NVCC" != ""; then
-    cuda_prefix="$(dirname "$(dirname "$NVCC")")"
-    cuda_c2hsflags="--cpp="$NVCC" --cppopts=-E --cppopts=-arch=sm_20 "
+  case $target in
+    *mingw* )
+    # We need a Windows-style path, but mingw doesn't include cygpath,
+    # thus this hack.
+    NVCC=`cd $(dirname $NVCC) && pwd -W`/$(basename nvcc)
+    ;;
+  esac
+
+  cuda_prefix="$(dirname "$(dirname "$NVCC")")"
+
+  case $target in
+    *mingw* )
+      cuda_c2hsflags="--cppopts=-E --cppopts=-arch=sm_20 --cppopts="-D${target_os}_TARGET_OS=1" "
+      CPPFLAGS+=" "-D${target_os}_TARGET_OS=1" "
+      ;;
+    * )
+      cuda_c2hsflags="--cpp="$NVCC" --cppopts=-E --cppopts=-arch=sm_20 "
+      ;;
+  esac
+
 else
     echo "WARNING: Cannot find the CUDA compiler 'nvcc'. This is likely to cause problems."
     cuda_prefix="/usr/local/cuda"
@@ -43,6 +61,16 @@
     #LDFLAGS+=" -Xlinker -rpath ${cuda_lib_path} "
     #CPPFLAGS+=" -arch ${target_cpu} "
     ;;
+  mingw*)
+    case $target_cpu in
+      x86_64*)
+        cuda_lib_path="${cuda_prefix}/lib/x64"
+        ;;
+      *)
+        cuda_lib_path="${cuda_prefix}/lib/Win32"
+        ;;
+    esac
+    ;;
   *)
     case $target_cpu in
       x86_64*)
@@ -115,9 +143,24 @@
 # CUDA 5.5 on OS X (Mavericks) — I guess, because the library is now only a stub.
 #
 AC_CHECK_HEADERS([cuda.h cuda_runtime_api.h], [], [AC_MSG_ERROR(could not find CUDA headers${longerror})])
-AC_SEARCH_LIBS(cuDriverGetVersion, cuda,      [], [AC_MSG_ERROR(could not find CUDA driver library${longerror})])
-AC_SEARCH_LIBS(cudaRuntimeGetVersion, cudart, [], [AC_MSG_ERROR(could not find CUDA runtime library${longerror})])
 
+case $target in
+  *mingw32* )
+    # AC_SEARCH_LIBS doesn't work on Win32 with functions that use the
+    # stdcall calling convention, so we use AC_CHECK_DELCS instead.
+    LIBS+="-lcuda -lcudart"
+    AC_CHECK_DECLS([cuDriverGetVersion],    [], [AC_MSG_ERROR(could not find CUDA driver library${longerror})], [[#include <cuda.h>]])
+    AC_CHECK_DECLS([cudaRuntimeGetVersion], [], [AC_MSG_ERROR(could not find CUDA runtime library${longerror})], [[#include <cuda_runtime_api.h>]])
+
+    cuda_ghci_libs+="`nm ${cuda_lib_path}/cuda.lib | head -2 | tail -1 | sed -e 's/://' -e 's/.dll//'` "
+    cuda_ghci_libs+="`nm ${cuda_lib_path}/cudart.lib | head -2 | tail -1 | sed -e 's/://' -e 's/.dll//'` "
+    ;;
+  *)
+    AC_SEARCH_LIBS(cuDriverGetVersion,    cuda,   [], [AC_MSG_ERROR(could not find CUDA driver library${longerror})])
+    AC_SEARCH_LIBS(cudaRuntimeGetVersion, cudart, [], [AC_MSG_ERROR(could not find CUDA runtime library${longerror})])
+    ;;
+esac
+
 # Populate the buildinfo, with the search paths and any target specific options
 #
 cuda_ccflags="$CPPFLAGS "
@@ -140,5 +183,6 @@
 AC_SUBST([cuda_lib_path])
 AC_SUBST([cuda_libraries])
 AC_SUBST([cuda_frameworks])
+AC_SUBST([cuda_ghci_libs])
 AC_OUTPUT
 
diff --git a/cuda.cabal b/cuda.cabal
--- a/cuda.cabal
+++ b/cuda.cabal
@@ -1,5 +1,5 @@
 Name:                   cuda
-Version:                0.6.5.0
+Version:                0.6.5.1
 Synopsis:               FFI binding to the CUDA interface for programming NVIDIA GPUs
 Description:
     The CUDA library provides a direct, general purpose C-like SPMD programming
@@ -13,7 +13,11 @@
     The configure script will look for your CUDA installation in the standard
     places, and if the nvcc compiler is found in your PATH, relative to that.
     .
-    This release is for version 6.0 of the CUDA toolkit.
+    This release is for version 6.5 of the CUDA toolkit.
+    .
+    [/NOTE:/]
+    .
+    Due to a bug in nvcc, you must use c2hs-0.17.2. See tmcdonell/cuda#18.
 
 License:                BSD3
 License-file:           LICENSE
@@ -81,8 +85,7 @@
   ghc-prof-options:     -fprof-auto -fprof-cafs
 
 
-Test-suite deviceQuery
-  Type:                 exitcode-stdio-1.0
+Executable nvidia-device-query
   Main-is:              DeviceQuery.hs
   hs-source-dirs:       examples/src/deviceQueryDrv
 
diff --git a/examples/src/deviceQueryDrv/DeviceQuery.hs b/examples/src/deviceQueryDrv/DeviceQuery.hs
--- a/examples/src/deviceQueryDrv/DeviceQuery.hs
+++ b/examples/src/deviceQueryDrv/DeviceQuery.hs
@@ -1,5 +1,7 @@
 {-# LANGUAGE RecordWildCards #-}
 
+module Main where
+
 import Numeric
 import Control.Monad
 import Text.Printf
@@ -31,11 +33,11 @@
 statDevice :: DeviceProperties -> IO ()
 statDevice dev@DeviceProperties{..} =
   let
-      DeviceResources{..}       = deviceResources dev
+      DeviceResources{..} = deviceResources dev
 
-      pad v     = take width $ v ++ repeat ' '
-      width     = maximum $ map (length . fst) props
-      table     = nest 2 $ vcat $ map (\(k,v) -> text (pad k) <+> v) props
+      pad v             = take width $ v ++ repeat ' '
+      width             = maximum $ map (length . fst) props
+      table             = nest 2 $ vcat $ map (\(k,v) -> text (pad k) <+> v) props
 
       grid (x,y)        = int x <+> char 'x' <+> int y
       cube (x,y,z)      = int x <+> char 'x' <+> int y <+> char 'x' <+> int z
@@ -55,9 +57,9 @@
         ,("Maximum threads per block:",          int maxThreadsPerBlock)
         ,("Maximum grid dimensions:",            cube maxGridSize)
         ,("Maximum block dimensions:",           cube maxBlockSize)
-        ,("GPU clock rate:",                     text $ showFreq clockRate)
-        ,("Memory clock rate:",                  text $ showFreq memClockRate)
-        ,("Memory bus width:",                   text $ showFreq memBusWidth)
+        ,("GPU clock rate:",                     text . showFreq $ clockRate * 1000)
+        ,("Memory clock rate:",                  text . showFreq $ memClockRate * 1000)
+        ,("Memory bus width:",                   int memBusWidth <> text "-bit")
         ,("L2 cache size:",                      text $ showBytes cacheMemL2)
         ,("Maximum texture dimensions",          empty)
         ,("  1D:",                               int maxTextureDim1D)
