diff --git a/Graphics/Win32/Control.hsc b/Graphics/Win32/Control.hsc
--- a/Graphics/Win32/Control.hsc
+++ b/Graphics/Win32/Control.hsc
@@ -25,6 +25,8 @@
 import Foreign hiding (unsafePerformIO)
 import System.IO.Unsafe
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 #include <commctrl.h>
 
@@ -73,20 +75,20 @@
 checkDlgButton :: HWND -> Int -> ButtonState -> IO ()
 checkDlgButton dialog button check =
   failIfFalse_ "CheckDlgButton" $ c_CheckDlgButton dialog button check
-foreign import stdcall unsafe "windows.h CheckDlgButton"
+foreign import WINDOWS_CCONV unsafe "windows.h CheckDlgButton"
   c_CheckDlgButton :: HWND -> Int -> ButtonState -> IO Bool
 
 checkRadioButton :: HWND -> Int -> Int -> Int -> IO ()
 checkRadioButton dialog first_button last_button check =
   failIfFalse_ "CheckRadioButton" $
     c_CheckRadioButton dialog first_button last_button check
-foreign import stdcall unsafe "windows.h CheckRadioButton"
+foreign import WINDOWS_CCONV unsafe "windows.h CheckRadioButton"
   c_CheckRadioButton :: HWND -> Int -> Int -> Int -> IO Bool
 
 isDlgButtonChecked :: HWND -> Int -> IO ButtonState
 isDlgButtonChecked wnd button =
   failIfZero "IsDlgButtonChecked" $ c_IsDlgButtonChecked wnd button
-foreign import stdcall unsafe "windows.h IsDlgButtonChecked"
+foreign import WINDOWS_CCONV unsafe "windows.h IsDlgButtonChecked"
   c_IsDlgButtonChecked :: HWND -> Int -> IO ButtonState
 
 
@@ -324,7 +326,7 @@
       (maybePos mb_x) (maybePos mb_y) (maybePos mb_w) (maybePos mb_h)
       (maybePtr mb_parent) (maybePtr mb_menu) h nullPtr
 
-foreign import stdcall unsafe "windows.h InitCommonControls"
+foreign import WINDOWS_CCONV unsafe "windows.h InitCommonControls"
   initCommonControls :: IO ()
 
 #endif
diff --git a/Graphics/Win32/Dialogue.hsc b/Graphics/Win32/Dialogue.hsc
--- a/Graphics/Win32/Dialogue.hsc
+++ b/Graphics/Win32/Dialogue.hsc
@@ -26,6 +26,8 @@
 import Foreign
 import Foreign.C
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 
 type DTemplate = LPCTSTR
@@ -43,7 +45,7 @@
 type ResourceID = Int
 
 mkResource :: ResourceID -> IO (Ptr a)
-mkResource res = return (castUINTToPtr (fromIntegral res))
+mkResource res = return (castUINTPtrToPtr (fromIntegral res))
 
 mkDialogTemplateFromResource :: Int -> IO DTemplate
 mkDialogTemplateFromResource = mkResource
@@ -67,7 +69,7 @@
   c_dia_fn <- mkDialogClosure dia_fn
   failIf (== -1) "DialogBoxParam" $
     c_DialogBoxParam inst template (maybePtr mb_parent) c_dia_fn init_val
-foreign import stdcall "windows.h DialogBoxParamW"
+foreign import WINDOWS_CCONV "windows.h DialogBoxParamW"
   c_DialogBoxParam :: HINSTANCE -> DTemplate -> HWND -> FunPtr DialogProc -> LPARAM -> IO Int
 
 dialogBoxIndirect :: HINSTANCE -> DTemplateMem -> Maybe HWND -> DialogProc -> IO Int
@@ -79,7 +81,7 @@
   c_dia_fn <- mkDialogClosure dia_fn
   failIf (== -1) "DialogBoxIndirectParam" $
     c_DialogBoxIndirectParam inst template (maybePtr mb_parent) c_dia_fn init_val
-foreign import stdcall "windows.h DialogBoxIndirectParamW"
+foreign import WINDOWS_CCONV "windows.h DialogBoxIndirectParamW"
   c_DialogBoxIndirectParam :: HINSTANCE -> DTemplateMem -> HWND -> FunPtr DialogProc -> LPARAM -> IO Int
 
 
@@ -207,7 +209,7 @@
   c_dia_fn <- mkDialogClosure dia_fn
   failIfNull "CreateDialogParam" $
     c_CreateDialogParam inst template (maybePtr mb_parent) c_dia_fn init_val
-foreign import stdcall "windows.h CreateDialogParamW"
+foreign import WINDOWS_CCONV "windows.h CreateDialogParamW"
   c_CreateDialogParam :: HINSTANCE -> DTemplate -> HWND -> FunPtr DialogProc -> LPARAM -> IO HWND
 
 createDialogIndirect :: HINSTANCE -> DTemplateMem -> Maybe HWND -> DialogProc -> IO HWND
@@ -219,31 +221,31 @@
   c_dia_fn <- mkDialogClosure dia_fn
   failIfNull "CreateDialogIndirectParam" $
     c_CreateDialogIndirectParam inst template (maybePtr mb_parent) c_dia_fn init_val
-foreign import stdcall "windows.h CreateDialogIndirectParamW"
+foreign import WINDOWS_CCONV "windows.h CreateDialogIndirectParamW"
   c_CreateDialogIndirectParam :: HINSTANCE -> DTemplateMem -> HWND -> FunPtr DialogProc -> LPARAM -> IO HWND
 
-foreign import stdcall "windows.h DefDlgProcW"
+foreign import WINDOWS_CCONV "windows.h DefDlgProcW"
   defDlgProc :: HWND -> WindowMessage -> WPARAM -> LPARAM -> IO LRESULT
 
 endDialog :: HWND -> Int -> IO ()
 endDialog dlg res =
   failIfFalse_ "EndDialog" $ c_EndDialog dlg res
-foreign import stdcall "windows.h EndDialog"
+foreign import WINDOWS_CCONV "windows.h EndDialog"
   c_EndDialog :: HWND -> Int -> IO BOOL
 
-foreign import stdcall unsafe "windows.h GetDialogBaseUnits"
+foreign import WINDOWS_CCONV unsafe "windows.h GetDialogBaseUnits"
   getDialogBaseUnits :: IO LONG
 
 getDlgCtrlID :: HWND -> IO Int
 getDlgCtrlID ctl =
   failIfZero "GetDlgCtrlID" $ c_GetDlgCtrlID ctl
-foreign import stdcall unsafe "windows.h GetDlgCtrlID"
+foreign import WINDOWS_CCONV unsafe "windows.h GetDlgCtrlID"
   c_GetDlgCtrlID :: HWND -> IO Int
 
 getDlgItem :: HWND -> Int -> IO HWND
 getDlgItem dlg item =
   failIfNull "GetDlgItem" $ c_GetDlgItem dlg item
-foreign import stdcall unsafe "windows.h GetDlgItem"
+foreign import WINDOWS_CCONV unsafe "windows.h GetDlgItem"
   c_GetDlgItem :: HWND -> Int -> IO HWND
 
 getDlgItemInt :: HWND -> Int -> Bool -> IO Int
@@ -252,7 +254,7 @@
   res <- c_GetDlgItemInt dlg item p_trans signed
   failIfFalse_ "GetDlgItemInt" $ peek p_trans
   return (fromIntegral res)
-foreign import stdcall "windows.h GetDlgItemInt"
+foreign import WINDOWS_CCONV "windows.h GetDlgItemInt"
   c_GetDlgItemInt :: HWND -> Int -> Ptr Bool -> Bool -> IO UINT
 
 getDlgItemText :: HWND -> Int -> Int -> IO String
@@ -260,46 +262,46 @@
   allocaArray size $ \ p_buf -> do
   _ <- failIfZero "GetDlgItemInt" $ c_GetDlgItemText dlg item p_buf size
   peekTString p_buf
-foreign import stdcall "windows.h GetDlgItemTextW"
+foreign import WINDOWS_CCONV "windows.h GetDlgItemTextW"
   c_GetDlgItemText :: HWND -> Int -> LPTSTR -> Int -> IO Int
 
 getNextDlgGroupItem :: HWND -> HWND -> BOOL -> IO HWND
 getNextDlgGroupItem dlg ctl previous =
   failIfNull "GetNextDlgGroupItem" $ c_GetNextDlgGroupItem dlg ctl previous
-foreign import stdcall unsafe "windows.h GetNextDlgGroupItem"
+foreign import WINDOWS_CCONV unsafe "windows.h GetNextDlgGroupItem"
   c_GetNextDlgGroupItem :: HWND -> HWND -> BOOL -> IO HWND
 
 getNextDlgTabItem :: HWND -> HWND -> BOOL -> IO HWND
 getNextDlgTabItem dlg ctl previous =
   failIfNull "GetNextDlgTabItem" $ c_GetNextDlgTabItem dlg ctl previous
-foreign import stdcall unsafe "windows.h GetNextDlgTabItem"
+foreign import WINDOWS_CCONV unsafe "windows.h GetNextDlgTabItem"
   c_GetNextDlgTabItem :: HWND -> HWND -> BOOL -> IO HWND
 
-foreign import stdcall "windows.h IsDialogMessageW"
+foreign import WINDOWS_CCONV "windows.h IsDialogMessageW"
   isDialogMessage :: HWND -> LPMSG -> IO BOOL
 
 mapDialogRect :: HWND -> LPRECT -> IO ()
 mapDialogRect dlg p_rect =
   failIfFalse_ "MapDialogRect" $ c_MapDialogRect dlg p_rect
-foreign import stdcall unsafe "windows.h MapDialogRect"
+foreign import WINDOWS_CCONV unsafe "windows.h MapDialogRect"
   c_MapDialogRect :: HWND -> LPRECT -> IO Bool
 
 -- No MessageBox* funs in here just yet.
 
-foreign import stdcall "windows.h SendDlgItemMessageW"
+foreign import WINDOWS_CCONV "windows.h SendDlgItemMessageW"
   sendDlgItemMessage :: HWND -> Int -> WindowMessage -> WPARAM -> LPARAM -> IO LONG
 
 setDlgItemInt :: HWND -> Int -> UINT -> BOOL -> IO ()
 setDlgItemInt dlg item value signed =
   failIfFalse_ "SetDlgItemInt" $ c_SetDlgItemInt dlg item value signed
-foreign import stdcall "windows.h SetDlgItemInt"
+foreign import WINDOWS_CCONV "windows.h SetDlgItemInt"
   c_SetDlgItemInt :: HWND -> Int -> UINT -> BOOL -> IO Bool
 
 setDlgItemText :: HWND -> Int -> String -> IO ()
 setDlgItemText dlg item str =
   withTString str $ \ c_str ->
   failIfFalse_ "SetDlgItemText" $ c_SetDlgItemText dlg item c_str
-foreign import stdcall "windows.h SetDlgItemTextW"
+foreign import WINDOWS_CCONV "windows.h SetDlgItemTextW"
   c_SetDlgItemText :: HWND -> Int -> LPCTSTR -> IO Bool
 
 #{enum WindowStyle,
diff --git a/Graphics/Win32/GDI/Bitmap.hsc b/Graphics/Win32/GDI/Bitmap.hsc
--- a/Graphics/Win32/GDI/Bitmap.hsc
+++ b/Graphics/Win32/GDI/Bitmap.hsc
@@ -89,6 +89,8 @@
 import Foreign.C
 
 #include "Win32Aux.h"
+##include "windows_cconv.h"
+
 #include <windows.h>
 
 ----------------------------------------------------------------
@@ -212,32 +214,32 @@
 deleteBitmap :: HBITMAP -> IO ()
 deleteBitmap bitmap =
   failIfFalse_ "DeleteBitmap" $ c_DeleteBitmap bitmap
-foreign import stdcall unsafe "windows.h DeleteObject"
+foreign import WINDOWS_CCONV unsafe "windows.h DeleteObject"
   c_DeleteBitmap :: HBITMAP -> IO Bool
 
 createBitmap :: INT -> INT -> UINT -> UINT -> Maybe LPVOID -> IO HBITMAP
 createBitmap w h planes bits mb_color_data =
   failIfNull "CreateBitmap" $
     c_CreateBitmap w h planes bits (maybePtr mb_color_data)
-foreign import stdcall unsafe "windows.h CreateBitmap"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateBitmap"
   c_CreateBitmap :: INT -> INT -> UINT -> UINT -> LPVOID -> IO HBITMAP
 
 createBitmapIndirect :: LPBITMAP -> IO HBITMAP
 createBitmapIndirect p_bm =
   failIfNull "CreateBitmapIndirect" $ c_CreateBitmapIndirect p_bm
-foreign import stdcall unsafe "windows.h CreateBitmapIndirect"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateBitmapIndirect"
   c_CreateBitmapIndirect :: LPBITMAP -> IO HBITMAP
 
 createCompatibleBitmap :: HDC -> Int32 -> Int32 -> IO HBITMAP
 createCompatibleBitmap dc w h =
   failIfNull "CreateCompatibleBitmap" $ c_CreateCompatibleBitmap dc w h
-foreign import stdcall unsafe "windows.h CreateCompatibleBitmap"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateCompatibleBitmap"
   c_CreateCompatibleBitmap :: HDC -> Int32 -> Int32 -> IO HBITMAP
 
 createDIBPatternBrushPt :: LPVOID -> ColorFormat -> IO HBRUSH
 createDIBPatternBrushPt bm usage =
   failIfNull "CreateDIBPatternBrushPt" $ c_CreateDIBPatternBrushPt bm usage
-foreign import stdcall unsafe "windows.h CreateDIBPatternBrushPt"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateDIBPatternBrushPt"
   c_CreateDIBPatternBrushPt :: LPVOID -> ColorFormat -> IO HBRUSH
 
 ----------------------------------------------------------------
@@ -249,7 +251,7 @@
   allocaSIZE $ \ p_size -> do
   failIfFalse_ "GetBitmapDimensionEx" $ c_GetBitmapDimensionEx bm p_size
   peekSIZE p_size
-foreign import stdcall unsafe "windows.h GetBitmapDimensionEx"
+foreign import WINDOWS_CCONV unsafe "windows.h GetBitmapDimensionEx"
   c_GetBitmapDimensionEx :: HBITMAP -> Ptr SIZE -> IO Bool
 
 setBitmapDimensionEx :: HBITMAP -> SIZE -> IO SIZE
@@ -258,7 +260,7 @@
   failIfFalse_ "SetBitmapDimensionEx" $ do
     c_SetBitmapDimensionEx bm cx cy p_size
   peekSIZE p_size
-foreign import stdcall unsafe "windows.h SetBitmapDimensionEx"
+foreign import WINDOWS_CCONV unsafe "windows.h SetBitmapDimensionEx"
   c_SetBitmapDimensionEx :: HBITMAP -> LONG -> LONG -> Ptr SIZE -> IO Bool
 
 getBitmapInfo :: HBITMAP -> IO BITMAP
@@ -266,7 +268,7 @@
   allocaBytes (fromIntegral sizeofBITMAP) $ \ p_bm -> do
   failIfFalse_ "GetBitmapInfo" $ c_GetBitmapInfo bm sizeofBITMAP p_bm
   peekBITMAP p_bm
-foreign import stdcall unsafe "windows.h GetObjectW"
+foreign import WINDOWS_CCONV unsafe "windows.h GetObjectW"
   c_GetBitmapInfo :: HBITMAP -> DWORD -> LPBITMAP -> IO Bool
 
 ----------------------------------------------------------------
@@ -398,20 +400,20 @@
 getDIBits dc bm start nlines mb_bits info usage =
   failIfZero "GetDIBits" $
     c_GetDIBits dc bm start nlines (maybePtr mb_bits) info usage
-foreign import stdcall unsafe "windows.h GetDIBits"
+foreign import WINDOWS_CCONV unsafe "windows.h GetDIBits"
   c_GetDIBits :: HDC -> HBITMAP -> INT -> INT -> LPVOID -> LPBITMAPINFO -> ColorFormat -> IO INT
 
 setDIBits :: HDC -> HBITMAP -> INT -> INT -> LPVOID -> LPBITMAPINFO -> ColorFormat -> IO INT
 setDIBits dc bm start nlines bits info use =
   failIfZero "SetDIBits" $ c_SetDIBits dc bm start nlines bits info use
-foreign import stdcall unsafe "windows.h SetDIBits"
+foreign import WINDOWS_CCONV unsafe "windows.h SetDIBits"
   c_SetDIBits :: HDC -> HBITMAP -> INT -> INT -> LPVOID -> LPBITMAPINFO -> ColorFormat -> IO INT
 
 createDIBitmap :: HDC -> LPBITMAPINFOHEADER -> DWORD -> LPVOID -> LPBITMAPINFO -> ColorFormat -> IO HBITMAP
 createDIBitmap dc hdr option init_val info usage =
   failIfNull "CreateDIBitmap" $
     c_CreateDIBitmap dc hdr option init_val info usage
-foreign import stdcall unsafe "windows.h CreateDIBitmap"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateDIBitmap"
   c_CreateDIBitmap :: HDC -> LPBITMAPINFOHEADER -> DWORD -> LPVOID -> LPBITMAPINFO -> ColorFormat -> IO HBITMAP
 
 ----------------------------------------------------------------
diff --git a/Graphics/Win32/GDI/Brush.hsc b/Graphics/Win32/GDI/Brush.hsc
--- a/Graphics/Win32/GDI/Brush.hsc
+++ b/Graphics/Win32/GDI/Brush.hsc
@@ -20,6 +20,8 @@
 import System.Win32.Types
 import Graphics.Win32.GDI.Types
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 
 ----------------------------------------------------------------
@@ -29,25 +31,25 @@
 createSolidBrush :: COLORREF -> IO HBRUSH
 createSolidBrush color =
   failIfNull "CreateSolidBrush" $ c_CreateSolidBrush color
-foreign import stdcall unsafe "windows.h CreateSolidBrush"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateSolidBrush"
   c_CreateSolidBrush :: COLORREF -> IO HBRUSH
 
 createHatchBrush :: HatchStyle -> COLORREF -> IO HBRUSH
 createHatchBrush style color =
   failIfNull "CreateHatchBrush" $ c_CreateHatchBrush style color
-foreign import stdcall unsafe "windows.h CreateHatchBrush"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateHatchBrush"
   c_CreateHatchBrush :: HatchStyle -> COLORREF -> IO HBRUSH
 
 createPatternBrush :: HBITMAP -> IO HBRUSH
 createPatternBrush bitmap =
   failIfNull "CreatePatternBrush" $ c_CreatePatternBrush bitmap
-foreign import stdcall unsafe "windows.h CreatePatternBrush"
+foreign import WINDOWS_CCONV unsafe "windows.h CreatePatternBrush"
   c_CreatePatternBrush :: HBITMAP -> IO HBRUSH
 
 deleteBrush :: HBRUSH -> IO ()
 deleteBrush brush =
   failIfFalse_ "DeleteBrush" $ c_DeleteBrush brush
-foreign import stdcall unsafe "windows.h DeleteObject"
+foreign import WINDOWS_CCONV unsafe "windows.h DeleteObject"
   c_DeleteBrush :: HBRUSH -> IO Bool
 
 ----------------------------------------------------------------
@@ -67,7 +69,7 @@
 getStockBrush :: StockBrush -> IO HBRUSH
 getStockBrush sb =
   failIfNull "GetStockBrush" $ c_GetStockBrush sb
-foreign import stdcall unsafe "windows.h GetStockObject"
+foreign import WINDOWS_CCONV unsafe "windows.h GetStockObject"
   c_GetStockBrush :: StockBrush -> IO HBRUSH
 
 ----------------------------------------------------------------
diff --git a/Graphics/Win32/GDI/Clip.hsc b/Graphics/Win32/GDI/Clip.hsc
--- a/Graphics/Win32/GDI/Clip.hsc
+++ b/Graphics/Win32/GDI/Clip.hsc
@@ -17,11 +17,14 @@
 
 module Graphics.Win32.GDI.Clip where
 
+import Control.Monad
 import Graphics.Win32.GDI.Types
 import System.Win32.Types
 
 import Foreign
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 
 type ClipboardFormat = UINT
@@ -54,36 +57,39 @@
 
 -- % , CF_UNICODETEXT  -- WinNT only
 
-foreign import stdcall unsafe "windows.h ChangeClipboardChain"
+foreign import WINDOWS_CCONV unsafe "windows.h ChangeClipboardChain"
   changeClipboardChain :: HWND -> HWND -> IO Bool
 
 closeClipboard :: IO ()
 closeClipboard =
   failIfFalse_ "CloseClipboard" c_CloseClipboard
-foreign import stdcall unsafe "windows.h CloseClipboard"
+foreign import WINDOWS_CCONV unsafe "windows.h CloseClipboard"
   c_CloseClipboard :: IO BOOL
 
-foreign import stdcall unsafe "windows.h CountClipboardFormats"
+foreign import WINDOWS_CCONV unsafe "windows.h CountClipboardFormats"
   countClipboardFormats :: IO Int
 
 emptyClipboard :: IO ()
 emptyClipboard =
   failIfFalse_ "EmptyClipboard" c_EmptyClipboard
-foreign import stdcall unsafe "windows.h EmptyClipboard"
+foreign import WINDOWS_CCONV unsafe "windows.h EmptyClipboard"
   c_EmptyClipboard :: IO BOOL
 
 -- original also tested GetLastError() != NO_ERROR
 
 enumClipboardFormats :: ClipboardFormat -> IO ClipboardFormat
-enumClipboardFormats format =
-  failIfZero "EnumClipboardFormats" $ c_EnumClipboardFormats format
-foreign import stdcall unsafe "windows.h EnumClipboardFormats"
+enumClipboardFormats format = do
+  format' <- c_EnumClipboardFormats format
+  when (format' == 0) $
+    failUnlessSuccess "EnumClipboardFormats" getLastError
+  return format'
+foreign import WINDOWS_CCONV unsafe "windows.h EnumClipboardFormats"
   c_EnumClipboardFormats :: ClipboardFormat -> IO ClipboardFormat
 
 getClipboardData :: ClipboardFormat -> IO HANDLE
 getClipboardData format =
   failIfNull "GetClipboardData" $ c_GetClipboardData format
-foreign import stdcall unsafe "windows.h GetClipboardData"
+foreign import WINDOWS_CCONV unsafe "windows.h GetClipboardData"
   c_GetClipboardData :: ClipboardFormat -> IO HANDLE
 
 getClipboardFormatName :: ClipboardFormat -> IO String
@@ -92,25 +98,25 @@
   len <- failIfZero "GetClipboardFormatName" $
     c_GetClipboardFormatName format c_name 256
   peekTStringLen (c_name, len)
-foreign import stdcall unsafe "windows.h GetClipboardFormatNameW"
+foreign import WINDOWS_CCONV unsafe "windows.h GetClipboardFormatNameW"
   c_GetClipboardFormatName :: ClipboardFormat -> LPTSTR -> Int -> IO Int
 
 getClipboardOwner :: IO HWND
 getClipboardOwner =
   failIfNull "GetClipboardOwner" c_GetClipboardOwner
-foreign import stdcall unsafe "windows.h GetClipboardOwner"
+foreign import WINDOWS_CCONV unsafe "windows.h GetClipboardOwner"
   c_GetClipboardOwner :: IO HWND
 
 getClipboardViewer :: IO HWND
 getClipboardViewer =
   failIfNull "GetClipboardViewer" c_GetClipboardViewer
-foreign import stdcall unsafe "windows.h GetClipboardViewer"
+foreign import WINDOWS_CCONV unsafe "windows.h GetClipboardViewer"
   c_GetClipboardViewer :: IO HWND
 
 getOpenClipboardWindow :: IO HWND
 getOpenClipboardWindow =
   failIfNull "GetClipboardWindow" c_GetOpenClipboardWindow
-foreign import stdcall unsafe "windows.h GetOpenClipboardWindow"
+foreign import WINDOWS_CCONV unsafe "windows.h GetOpenClipboardWindow"
   c_GetOpenClipboardWindow :: IO HWND
 
 getPriorityClipboardFormat :: [ClipboardFormat] -> IO Int
@@ -118,16 +124,16 @@
   withArray formats $ \ format_array ->
   failIf (== -1) "GetPriorityClipboardFormat" $
     c_GetPriorityClipboardFormat format_array (length formats)
-foreign import stdcall unsafe "windows.h GetPriorityClipboardFormat"
+foreign import WINDOWS_CCONV unsafe "windows.h GetPriorityClipboardFormat"
   c_GetPriorityClipboardFormat :: Ptr UINT -> Int -> IO Int
 
-foreign import stdcall unsafe "windows.h IsClipboardFormatAvailable"
+foreign import WINDOWS_CCONV unsafe "windows.h IsClipboardFormatAvailable"
   isClipboardFormatAvailable :: ClipboardFormat -> IO BOOL
 
 openClipboard :: HWND -> IO ()
 openClipboard wnd =
   failIfFalse_ "OpenClipboard" $ c_OpenClipboard wnd
-foreign import stdcall unsafe "windows.h OpenClipboard"
+foreign import WINDOWS_CCONV unsafe "windows.h OpenClipboard"
   c_OpenClipboard :: HWND -> IO BOOL
 
 registerClipboardFormat :: String -> IO ClipboardFormat
@@ -135,17 +141,17 @@
   withTString name $ \ c_name ->
   failIfZero "RegisterClipboardFormat" $
     c_RegisterClipboardFormat c_name
-foreign import stdcall unsafe "windows.h RegisterClipboardFormatW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegisterClipboardFormatW"
   c_RegisterClipboardFormat :: LPCTSTR -> IO ClipboardFormat
 
 setClipboardData :: ClipboardFormat -> HANDLE -> IO HANDLE
 setClipboardData format mem =
   failIfNull "SetClipboardData" $ c_SetClipboardData format mem
-foreign import stdcall unsafe "windows.h SetClipboardData"
+foreign import WINDOWS_CCONV unsafe "windows.h SetClipboardData"
   c_SetClipboardData :: ClipboardFormat -> HANDLE -> IO HANDLE
 
 setClipboardViewer :: HWND -> IO HWND
 setClipboardViewer wnd =
   failIfNull "SetClipboardViewer" $ c_SetClipboardViewer wnd
-foreign import stdcall unsafe "windows.h SetClipboardViewer"
+foreign import WINDOWS_CCONV unsafe "windows.h SetClipboardViewer"
   c_SetClipboardViewer :: HWND -> IO HWND
diff --git a/Graphics/Win32/GDI/Font.hsc b/Graphics/Win32/GDI/Font.hsc
--- a/Graphics/Win32/GDI/Font.hsc
+++ b/Graphics/Win32/GDI/Font.hsc
@@ -38,6 +38,7 @@
 
 import Foreign
 
+##include "windows_cconv.h"
 #include <windows.h>
 
 ----------------------------------------------------------------
@@ -148,7 +149,7 @@
   withTString face $ \ c_face ->
   failIfNull "CreateFont" $
     c_CreateFont h w esc orient wt ital under strike cset out clip q pf c_face
-foreign import stdcall unsafe "windows.h CreateFontW"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateFontW"
   c_CreateFont
      :: INT -> INT -> INT -> INT
      -> FontWeight -> Bool -> Bool -> Bool
@@ -182,7 +183,7 @@
 
 -- missing CreateFontIndirect from WinFonts.ss; GSL ???
 
-foreign import stdcall unsafe "windows.h DeleteObject"
+foreign import WINDOWS_CCONV unsafe "windows.h DeleteObject"
   deleteFont :: HFONT -> IO ()
 
 ----------------------------------------------------------------
@@ -198,7 +199,7 @@
  , sYSTEM_FIXED_FONT   = SYSTEM_FIXED_FONT
  }
 
-foreign import stdcall unsafe "windows.h GetStockObject"
+foreign import WINDOWS_CCONV unsafe "windows.h GetStockObject"
   getStockFont :: StockFont -> IO HFONT
 
 ----------------------------------------------------------------
diff --git a/Graphics/Win32/GDI/Graphics2D.hs b/Graphics/Win32/GDI/Graphics2D.hs
--- a/Graphics/Win32/GDI/Graphics2D.hs
+++ b/Graphics/Win32/GDI/Graphics2D.hs
@@ -23,6 +23,8 @@
 
 import Foreign
 
+#include "windows_cconv.h"
+
 ----------------------------------------------------------------
 -- Lines and Curves
 ----------------------------------------------------------------
@@ -32,66 +34,66 @@
   allocaPOINT $ \ p_point -> do
   failIfFalse_ "MoveToEx" $ c_MoveToEx dc x y p_point
   peekPOINT p_point
-foreign import stdcall unsafe "windows.h MoveToEx"
+foreign import WINDOWS_CCONV unsafe "windows.h MoveToEx"
   c_MoveToEx :: HDC -> Int32 -> Int32 -> Ptr POINT -> IO Bool
 
 lineTo :: HDC -> Int32 -> Int32 -> IO ()
 lineTo dc x y =
   failIfFalse_ "LineTo" $ c_LineTo dc x y
-foreign import stdcall unsafe "windows.h LineTo"
+foreign import WINDOWS_CCONV unsafe "windows.h LineTo"
   c_LineTo :: HDC -> Int32 -> Int32 -> IO Bool
 
 polyline :: HDC -> [POINT] -> IO ()
 polyline dc points =
   withPOINTArray points $ \ pount_array npoints ->
   failIfFalse_ "Polyline" $ c_Polyline dc pount_array npoints
-foreign import stdcall unsafe "windows.h Polyline"
+foreign import WINDOWS_CCONV unsafe "windows.h Polyline"
   c_Polyline :: HDC -> Ptr POINT -> Int -> IO Bool
 
 polylineTo :: HDC -> [POINT] -> IO ()
 polylineTo dc points =
   withPOINTArray points $ \ pount_array npoints ->
   failIfFalse_ "PolylineTo" $ c_PolylineTo dc pount_array npoints
-foreign import stdcall unsafe "windows.h PolylineTo"
+foreign import WINDOWS_CCONV unsafe "windows.h PolylineTo"
   c_PolylineTo :: HDC -> Ptr POINT -> Int -> IO Bool
 
 polygon :: HDC -> [POINT] -> IO ()
 polygon dc points =
   withPOINTArray points $ \ pount_array npoints ->
   failIfFalse_ "Polygon" $ c_Polygon dc pount_array npoints
-foreign import stdcall unsafe "windows.h Polygon"
+foreign import WINDOWS_CCONV unsafe "windows.h Polygon"
   c_Polygon :: HDC -> Ptr POINT -> Int -> IO Bool
 
 polyBezier :: HDC -> [POINT] -> IO ()
 polyBezier dc points =
   withPOINTArray points $ \ pount_array npoints ->
   failIfFalse_ "PolyBezier" $ c_PolyBezier dc pount_array npoints
-foreign import stdcall unsafe "windows.h PolyBezier"
+foreign import WINDOWS_CCONV unsafe "windows.h PolyBezier"
   c_PolyBezier :: HDC -> Ptr POINT -> Int -> IO Bool
 
 polyBezierTo :: HDC -> [POINT] -> IO ()
 polyBezierTo dc points =
   withPOINTArray points $ \ pount_array npoints ->
   failIfFalse_ "PolyBezierTo" $ c_PolyBezierTo dc pount_array npoints
-foreign import stdcall unsafe "windows.h PolyBezierTo"
+foreign import WINDOWS_CCONV unsafe "windows.h PolyBezierTo"
   c_PolyBezierTo :: HDC -> Ptr POINT -> Int -> IO Bool
 
 arc :: HDC -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO ()
 arc dc left top right bottom x1 y1 x2 y2 =
   failIfFalse_ "Arc" $ c_Arc dc left top right bottom x1 y1 x2 y2
-foreign import stdcall unsafe "windows.h Arc"
+foreign import WINDOWS_CCONV unsafe "windows.h Arc"
   c_Arc :: HDC -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO Bool
 
 arcTo :: HDC -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO ()
 arcTo dc left top right bottom x1 y1 x2 y2 =
   failIfFalse_ "ArcTo" $ c_ArcTo dc left top right bottom x1 y1 x2 y2
-foreign import stdcall unsafe "windows.h ArcTo"
+foreign import WINDOWS_CCONV unsafe "windows.h ArcTo"
   c_ArcTo :: HDC -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO Bool
 
 angleArc :: HDC -> Int32 -> Int32 -> WORD -> Float -> Float -> IO ()
 angleArc dc x y r start sweep =
   failIfFalse_ "AngleArc" $ c_AngleArc dc x y r start sweep
-foreign import stdcall unsafe "windows.h AngleArc"
+foreign import WINDOWS_CCONV unsafe "windows.h AngleArc"
   c_AngleArc :: HDC -> Int32 -> Int32 -> WORD -> Float -> Float -> IO Bool
 
 ----------------------------------------------------------------
@@ -105,51 +107,51 @@
 fillRect dc rect brush =
   withRECT rect $ \ c_rect ->
   failIfFalse_ "FillRect" $ c_FillRect dc c_rect brush
-foreign import stdcall unsafe "windows.h FillRect"
+foreign import WINDOWS_CCONV unsafe "windows.h FillRect"
   c_FillRect :: HDC -> Ptr RECT -> HBRUSH -> IO Bool
 
 frameRect :: HDC -> RECT -> HBRUSH -> IO ()
 frameRect dc rect brush =
   withRECT rect $ \ c_rect ->
   failIfFalse_ "FrameRect" $ c_FrameRect dc c_rect brush
-foreign import stdcall unsafe "windows.h FrameRect"
+foreign import WINDOWS_CCONV unsafe "windows.h FrameRect"
   c_FrameRect :: HDC -> Ptr RECT -> HBRUSH -> IO Bool
 
 invertRect :: HDC -> RECT -> IO ()
 invertRect dc rect =
   withRECT rect $ \ c_rect ->
   failIfFalse_ "InvertRect" $ c_InvertRect dc c_rect
-foreign import stdcall unsafe "windows.h InvertRect"
+foreign import WINDOWS_CCONV unsafe "windows.h InvertRect"
   c_InvertRect :: HDC -> Ptr RECT -> IO Bool
 
 rectangle :: HDC -> Int32 -> Int32 -> Int32 -> Int32 -> IO ()
 rectangle dc left top right bottom =
   failIfFalse_ "Rectangle" $ c_Rectangle dc left top right bottom
-foreign import stdcall unsafe "windows.h Rectangle"
+foreign import WINDOWS_CCONV unsafe "windows.h Rectangle"
   c_Rectangle :: HDC -> Int32 -> Int32 -> Int32 -> Int32 -> IO Bool
 
 roundRect :: HDC -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO ()
 roundRect dc left top right bottom w h =
   failIfFalse_ "RoundRect" $ c_RoundRect dc left top right bottom w h
-foreign import stdcall unsafe "windows.h RoundRect"
+foreign import WINDOWS_CCONV unsafe "windows.h RoundRect"
   c_RoundRect :: HDC -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO Bool
 
 ellipse :: HDC -> Int32 -> Int32 -> Int32 -> Int32 -> IO ()
 ellipse dc left top right bottom =
   failIfFalse_ "Ellipse" $ c_Ellipse dc left top right bottom
-foreign import stdcall unsafe "windows.h Ellipse"
+foreign import WINDOWS_CCONV unsafe "windows.h Ellipse"
   c_Ellipse :: HDC -> Int32 -> Int32 -> Int32 -> Int32 -> IO Bool
 
 chord :: HDC -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO ()
 chord dc left top right bottom x1 y1 x2 y2 =
   failIfFalse_ "Chord" $ c_Chord dc left top right bottom x1 y1 x2 y2
-foreign import stdcall unsafe "windows.h Chord"
+foreign import WINDOWS_CCONV unsafe "windows.h Chord"
   c_Chord :: HDC -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO Bool
 
 pie :: HDC -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO ()
 pie dc left top right bottom x1 y1 x2 y2 =
   failIfFalse_ "Pie" $ c_Pie dc left top right bottom x1 y1 x2 y2
-foreign import stdcall unsafe "windows.h Pie"
+foreign import WINDOWS_CCONV unsafe "windows.h Pie"
   c_Pie :: HDC -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO Bool
 
 ----------------------------------------------------------------
@@ -159,21 +161,21 @@
 bitBlt :: HDC -> INT -> INT -> INT -> INT -> HDC -> INT -> INT -> RasterOp3 -> IO ()
 bitBlt dcDest xDest yDest w h dcSrc xSrc ySrc rop =
   failIfFalse_ "BitBlt" $ c_BitBlt dcDest xDest yDest w h dcSrc xSrc ySrc rop
-foreign import stdcall unsafe "windows.h BitBlt"
+foreign import WINDOWS_CCONV unsafe "windows.h BitBlt"
   c_BitBlt :: HDC -> INT -> INT -> INT -> INT -> HDC -> INT -> INT -> RasterOp3 -> IO Bool
 
 maskBlt :: HDC -> INT -> INT -> INT -> INT -> HDC -> INT -> INT -> HBITMAP -> INT -> INT -> RasterOp4 -> IO ()
 maskBlt dcDest xDest yDest w h dcSrc xSrc ySrc bm xMask yMask rop =
   failIfFalse_ "MaskBlt" $
     c_MaskBlt dcDest xDest yDest w h dcSrc xSrc ySrc bm xMask yMask rop
-foreign import stdcall unsafe "windows.h MaskBlt"
+foreign import WINDOWS_CCONV unsafe "windows.h MaskBlt"
   c_MaskBlt :: HDC -> INT -> INT -> INT -> INT -> HDC -> INT -> INT -> HBITMAP -> INT -> INT -> RasterOp4 -> IO Bool
 
 stretchBlt :: HDC -> INT -> INT -> INT -> INT -> HDC -> INT -> INT -> INT -> INT -> RasterOp3 -> IO ()
 stretchBlt dcDest xDest yDest wDest hDest hdcSrc xSrc ySrc wSrc hSrc rop =
   failIfFalse_ "StretchBlt" $
     c_StretchBlt dcDest xDest yDest wDest hDest hdcSrc xSrc ySrc wSrc hSrc rop
-foreign import stdcall unsafe "windows.h StretchBlt"
+foreign import WINDOWS_CCONV unsafe "windows.h StretchBlt"
   c_StretchBlt :: HDC -> INT -> INT -> INT -> INT -> HDC -> INT -> INT -> INT -> INT -> RasterOp3 -> IO Bool
 
 -- We deviate slightly from the Win32 interface
@@ -188,7 +190,7 @@
   withPOINTArray [p1,p2,p3] $ \ vertices _ ->
   failIfFalse_ "PlgBlt" $
     c_PlgBlt hdDest vertices hdSrc x y w h (maybePtr mb_bm) xMask yMask
-foreign import stdcall unsafe "windows.h PlgBlt"
+foreign import WINDOWS_CCONV unsafe "windows.h PlgBlt"
   c_PlgBlt :: HDC -> Ptr POINT -> HDC -> INT -> INT -> INT -> INT -> HBITMAP -> INT -> INT -> IO Bool
 
 ----------------------------------------------------------------
@@ -199,7 +201,7 @@
 textOut dc x y str =
   withTStringLen str $ \ (c_str, len) ->
   failIfFalse_ "TextOut" $ c_TextOut dc x y c_str len
-foreign import stdcall unsafe "windows.h TextOutW"
+foreign import WINDOWS_CCONV unsafe "windows.h TextOutW"
   c_TextOut :: HDC -> INT -> INT -> LPCTSTR -> Int -> IO Bool
 
 -- missing TabbedTextOut from WinFonts.ss; GSL ???
@@ -211,7 +213,7 @@
   failIfFalse_ "GetTextExtentPoint32" $
     c_GetTextExtentPoint32 dc c_str len p_size
   peekSIZE p_size
-foreign import stdcall unsafe "windows.h GetTextExtentPoint32W"
+foreign import WINDOWS_CCONV unsafe "windows.h GetTextExtentPoint32W"
   c_GetTextExtentPoint32 :: HDC -> LPCTSTR -> Int -> Ptr SIZE -> IO Bool
 
 -- missing getTabbedTextExtent from WinFonts.ss; GSL ???
diff --git a/Graphics/Win32/GDI/HDC.hs b/Graphics/Win32/GDI/HDC.hs
--- a/Graphics/Win32/GDI/HDC.hs
+++ b/Graphics/Win32/GDI/HDC.hs
@@ -24,90 +24,92 @@
 
 import Foreign
 
+#include "windows_cconv.h"
+
 ----------------------------------------------------------------
 
 setArcDirection :: HDC -> ArcDirection -> IO ArcDirection
 setArcDirection dc dir =
   failIfZero "SetArcDirection" $ c_SetArcDirection dc dir
-foreign import stdcall unsafe "windows.h SetArcDirection"
+foreign import WINDOWS_CCONV unsafe "windows.h SetArcDirection"
   c_SetArcDirection :: HDC ->  ArcDirection  -> IO  ArcDirection
 
 getArcDirection :: HDC -> IO ArcDirection
 getArcDirection dc =
   failIfZero "GetArcDirection" $ c_GetArcDirection dc
-foreign import stdcall unsafe "windows.h GetArcDirection"
+foreign import WINDOWS_CCONV unsafe "windows.h GetArcDirection"
   c_GetArcDirection :: HDC -> IO  ArcDirection
 
 setPolyFillMode :: HDC -> PolyFillMode -> IO PolyFillMode
 setPolyFillMode dc mode =
   failIfZero "SetPolyFillMode" $ c_SetPolyFillMode dc mode
-foreign import stdcall unsafe "windows.h SetPolyFillMode"
+foreign import WINDOWS_CCONV unsafe "windows.h SetPolyFillMode"
   c_SetPolyFillMode :: HDC ->  PolyFillMode  -> IO  PolyFillMode
 
 getPolyFillMode :: HDC -> IO PolyFillMode
 getPolyFillMode dc =
   failIfZero "GetPolyFillMode" $ c_GetPolyFillMode dc
-foreign import stdcall unsafe "windows.h GetPolyFillMode"
+foreign import WINDOWS_CCONV unsafe "windows.h GetPolyFillMode"
   c_GetPolyFillMode :: HDC -> IO  PolyFillMode
 
 setGraphicsMode :: HDC -> GraphicsMode -> IO GraphicsMode
 setGraphicsMode dc mode =
   failIfZero "SetGraphicsMode" $ c_SetGraphicsMode dc mode
-foreign import stdcall unsafe "windows.h SetGraphicsMode"
+foreign import WINDOWS_CCONV unsafe "windows.h SetGraphicsMode"
   c_SetGraphicsMode :: HDC ->  GraphicsMode  -> IO  GraphicsMode
 
 getGraphicsMode :: HDC -> IO GraphicsMode
 getGraphicsMode dc =
   failIfZero "GetGraphicsMode" $ c_GetGraphicsMode dc
-foreign import stdcall unsafe "windows.h GetGraphicsMode"
+foreign import WINDOWS_CCONV unsafe "windows.h GetGraphicsMode"
   c_GetGraphicsMode :: HDC -> IO  GraphicsMode
 
 setStretchBltMode :: HDC -> StretchBltMode -> IO StretchBltMode
 setStretchBltMode dc mode =
   failIfZero "SetStretchBltMode" $ c_SetStretchBltMode dc mode
-foreign import stdcall unsafe "windows.h SetStretchBltMode"
+foreign import WINDOWS_CCONV unsafe "windows.h SetStretchBltMode"
   c_SetStretchBltMode :: HDC ->  StretchBltMode  -> IO  StretchBltMode
 
 getStretchBltMode :: HDC -> IO StretchBltMode
 getStretchBltMode dc =
   failIfZero "GetStretchBltMode" $ c_GetStretchBltMode dc
-foreign import stdcall unsafe "windows.h GetStretchBltMode"
+foreign import WINDOWS_CCONV unsafe "windows.h GetStretchBltMode"
   c_GetStretchBltMode :: HDC -> IO  StretchBltMode
 
 setBkColor :: HDC -> COLORREF -> IO COLORREF
 setBkColor dc color =
   failIfZero "SetBkColor" $ c_SetBkColor dc color
-foreign import stdcall unsafe "windows.h SetBkColor"
+foreign import WINDOWS_CCONV unsafe "windows.h SetBkColor"
   c_SetBkColor :: HDC ->  COLORREF  -> IO  COLORREF
 
 getBkColor :: HDC -> IO COLORREF
 getBkColor dc =
   failIfZero "GetBkColor" $ c_GetBkColor dc
-foreign import stdcall unsafe "windows.h GetBkColor"
+foreign import WINDOWS_CCONV unsafe "windows.h GetBkColor"
   c_GetBkColor :: HDC -> IO  COLORREF
 
 setTextColor :: HDC -> COLORREF -> IO COLORREF
 setTextColor dc color =
   failIf (== cLR_INVALID) "SetTextColor" $ c_SetTextColor dc color
-foreign import stdcall unsafe "windows.h SetTextColor"
+foreign import WINDOWS_CCONV unsafe "windows.h SetTextColor"
   c_SetTextColor :: HDC ->  COLORREF  -> IO  COLORREF
 
 getTextColor :: HDC -> IO COLORREF
 getTextColor dc =
   failIf (== cLR_INVALID) "GetTextColor" $ c_GetTextColor dc
-foreign import stdcall unsafe "windows.h GetTextColor"
+foreign import WINDOWS_CCONV unsafe "windows.h GetTextColor"
   c_GetTextColor :: HDC -> IO  COLORREF
 
 setBkMode :: HDC -> BackgroundMode -> IO BackgroundMode
 setBkMode dc mode =
   failIfZero "SetBkMode" $ c_SetBkMode dc mode
-foreign import stdcall unsafe "windows.h SetBkMode"
+foreign import WINDOWS_CCONV unsafe "windows.h SetBkMode"
   c_SetBkMode :: HDC ->  BackgroundMode  -> IO  BackgroundMode
 
 getBkMode :: HDC -> IO BackgroundMode
 getBkMode dc =
   failIfZero "GetBkMode" $ c_GetBkMode dc
-foreign import stdcall unsafe "windows.h GetBkMode"
+foreign import WINDOWS_CCONV unsafe "windows.h GetBkMode"
   c_GetBkMode :: HDC -> IO  BackgroundMode
 
 setBrushOrgEx :: HDC -> Int -> Int -> IO POINT
@@ -115,7 +117,7 @@
   allocaPOINT $ \ pt -> do
   failIfFalse_ "SetBrushOrgEx" $ c_SetBrushOrgEx dc x y pt
   peekPOINT pt
-foreign import stdcall unsafe "windows.h SetBrushOrgEx"
+foreign import WINDOWS_CCONV unsafe "windows.h SetBrushOrgEx"
   c_SetBrushOrgEx :: HDC -> Int -> Int -> Ptr POINT -> IO Bool
 
 getBrushOrgEx :: HDC -> IO POINT
@@ -123,32 +125,32 @@
   allocaPOINT $ \ pt -> do
   failIfFalse_ "GetBrushOrgEx" $ c_GetBrushOrgEx dc pt
   peekPOINT pt
-foreign import stdcall unsafe "windows.h GetBrushOrgEx"
+foreign import WINDOWS_CCONV unsafe "windows.h GetBrushOrgEx"
   c_GetBrushOrgEx :: HDC -> Ptr POINT -> IO Bool
 
 setTextAlign :: HDC -> TextAlignment -> IO TextAlignment
 setTextAlign dc align =
   failIf (== gDI_ERROR) "SetTextAlign" $ c_SetTextAlign dc align
-foreign import stdcall unsafe "windows.h SetTextAlign"
+foreign import WINDOWS_CCONV unsafe "windows.h SetTextAlign"
   c_SetTextAlign :: HDC ->  TextAlignment  -> IO  TextAlignment
 
 getTextAlign :: HDC -> IO TextAlignment
 getTextAlign dc =
   failIf (== gDI_ERROR) "GetTextAlign" $ c_GetTextAlign dc
-foreign import stdcall unsafe "windows.h GetTextAlign"
+foreign import WINDOWS_CCONV unsafe "windows.h GetTextAlign"
   c_GetTextAlign :: HDC -> IO  TextAlignment
 
 setTextCharacterExtra :: HDC -> Int -> IO Int
 setTextCharacterExtra dc extra =
   failIf (== 0x80000000) "SetTextCharacterExtra" $
     c_SetTextCharacterExtra dc extra
-foreign import stdcall unsafe "windows.h SetTextCharacterExtra"
+foreign import WINDOWS_CCONV unsafe "windows.h SetTextCharacterExtra"
   c_SetTextCharacterExtra :: HDC ->  Int  -> IO  Int
 
 getTextCharacterExtra :: HDC -> IO Int
 getTextCharacterExtra dc =
   failIf (== 0x80000000) "GetTextCharacterExtra" $ c_GetTextCharacterExtra dc
-foreign import stdcall unsafe "windows.h GetTextCharacterExtra"
+foreign import WINDOWS_CCONV unsafe "windows.h GetTextCharacterExtra"
   c_GetTextCharacterExtra :: HDC -> IO  Int
 
 getMiterLimit :: HDC -> IO Float
@@ -156,7 +158,7 @@
   alloca $ \ p_res -> do
   failIfFalse_ "GetMiterLimit" $ c_GetMiterLimit dc p_res
   peek p_res
-foreign import stdcall unsafe "windows.h GetMiterLimit"
+foreign import WINDOWS_CCONV unsafe "windows.h GetMiterLimit"
   c_GetMiterLimit :: HDC -> Ptr FLOAT -> IO Bool
 
 setMiterLimit :: HDC -> Float -> IO Float
@@ -164,7 +166,7 @@
   alloca $ \ p_old_limit -> do
   failIfFalse_ "SetMiterLimit" $ c_SetMiterLimit dc new_limit p_old_limit
   peek p_old_limit
-foreign import stdcall unsafe "windows.h SetMiterLimit"
+foreign import WINDOWS_CCONV unsafe "windows.h SetMiterLimit"
   c_SetMiterLimit :: HDC -> FLOAT -> Ptr FLOAT -> IO Bool
 
 ----------------------------------------------------------------
@@ -172,13 +174,13 @@
 saveDC :: HDC -> IO Int
 saveDC dc =
   failIfZero "SaveDC" $ c_SaveDC dc
-foreign import stdcall unsafe "windows.h SaveDC"
+foreign import WINDOWS_CCONV unsafe "windows.h SaveDC"
   c_SaveDC :: HDC -> IO Int
 
 restoreDC :: HDC -> Int -> IO ()
 restoreDC dc saved =
   failIfFalse_ "RestoreDC" $ c_RestoreDC dc saved
-foreign import stdcall unsafe "windows.h RestoreDC"
+foreign import WINDOWS_CCONV unsafe "windows.h RestoreDC"
   c_RestoreDC :: HDC -> Int -> IO Bool
 
 ----------------------------------------------------------------
@@ -186,55 +188,55 @@
 getCurrentBitmap :: HDC -> IO HBITMAP
 getCurrentBitmap dc =
   failIfNull "GetCurrentBitmap" $ c_GetCurrentBitmap dc oBJ_BITMAP
-foreign import stdcall unsafe "windows.h GetCurrentObject"
+foreign import WINDOWS_CCONV unsafe "windows.h GetCurrentObject"
   c_GetCurrentBitmap :: HDC -> UINT -> IO  HBITMAP
 
 getCurrentBrush :: HDC -> IO HBRUSH
 getCurrentBrush dc =
   failIfNull "GetCurrentBrush" $ c_GetCurrentBrush dc oBJ_BRUSH
-foreign import stdcall unsafe "windows.h GetCurrentObject"
+foreign import WINDOWS_CCONV unsafe "windows.h GetCurrentObject"
   c_GetCurrentBrush :: HDC -> UINT -> IO   HBRUSH
 
 getCurrentFont :: HDC -> IO HFONT
 getCurrentFont dc =
   failIfNull "GetCurrentFont" $ c_GetCurrentFont dc oBJ_FONT
-foreign import stdcall unsafe "windows.h GetCurrentObject"
+foreign import WINDOWS_CCONV unsafe "windows.h GetCurrentObject"
   c_GetCurrentFont :: HDC -> UINT -> IO    HFONT
 
 getCurrentPalette :: HDC -> IO HPALETTE
 getCurrentPalette dc =
   failIfNull "GetCurrentPalette" $ c_GetCurrentPalette dc oBJ_PAL
-foreign import stdcall unsafe "windows.h GetCurrentObject"
+foreign import WINDOWS_CCONV unsafe "windows.h GetCurrentObject"
   c_GetCurrentPalette :: HDC -> UINT -> IO     HPALETTE
 
 getCurrentPen :: HDC -> IO HPEN
 getCurrentPen dc =
   failIfNull "GetCurrentPen" $ c_GetCurrentPen dc oBJ_PEN
-foreign import stdcall unsafe "windows.h GetCurrentObject"
+foreign import WINDOWS_CCONV unsafe "windows.h GetCurrentObject"
   c_GetCurrentPen :: HDC -> UINT -> IO     HPEN
 
 selectBitmap :: HDC -> HBITMAP -> IO HBITMAP
 selectBitmap dc bitmap =
   failIfNull "SelectBitmap" $ c_SelectBitmap dc bitmap
-foreign import stdcall unsafe "windows.h SelectObject"
+foreign import WINDOWS_CCONV unsafe "windows.h SelectObject"
   c_SelectBitmap :: HDC ->   HBITMAP  -> IO   HBITMAP
 
 selectBrush :: HDC -> HBRUSH -> IO HBRUSH
 selectBrush dc brush =
   failIfNull "SelectBrush" $ c_SelectBrush dc brush
-foreign import stdcall unsafe "windows.h SelectObject"
+foreign import WINDOWS_CCONV unsafe "windows.h SelectObject"
   c_SelectBrush :: HDC ->    HBRUSH  -> IO    HBRUSH
 
 selectFont :: HDC -> HFONT -> IO HFONT
 selectFont dc font =
   failIfNull "SelectFont" $ c_SelectFont dc font
-foreign import stdcall unsafe "windows.h SelectObject"
+foreign import WINDOWS_CCONV unsafe "windows.h SelectObject"
   c_SelectFont :: HDC ->     HFONT  -> IO     HFONT
 
 selectPen :: HDC -> HPEN -> IO HPEN
 selectPen dc pen =
   failIfNull "SelectPen" $ c_SelectPen dc pen
-foreign import stdcall unsafe "windows.h SelectObject"
+foreign import WINDOWS_CCONV unsafe "windows.h SelectObject"
   c_SelectPen :: HDC ->      HPEN  -> IO      HPEN
 
 ----------------------------------------------------------------
@@ -244,7 +246,7 @@
 selectPalette :: HDC -> HPALETTE -> Bool -> IO HPALETTE
 selectPalette dc palette force_bg =
   failIfNull "SelectPalette" $ c_SelectPalette dc palette force_bg
-foreign import stdcall unsafe "windows.h SelectPalette"
+foreign import WINDOWS_CCONV unsafe "windows.h SelectPalette"
   c_SelectPalette :: HDC -> HPALETTE -> Bool -> IO HPALETTE
 
 selectRgn :: HDC -> HRGN -> IO RegionType
@@ -260,20 +262,20 @@
 selectClipRgn dc mb_rgn =
   maybeWith withForeignPtr mb_rgn $ \ p_rgn ->
   failIfZero "SelectClipRgn" $ c_SelectClipRgn dc p_rgn
-foreign import stdcall unsafe "windows.h SelectClipRgn"
+foreign import WINDOWS_CCONV unsafe "windows.h SelectClipRgn"
   c_SelectClipRgn :: HDC -> PRGN -> IO RegionType
 
 extSelectClipRgn :: HDC -> Maybe HRGN -> ClippingMode -> IO RegionType
 extSelectClipRgn dc mb_rgn mode =
   maybeWith withForeignPtr mb_rgn $ \ p_rgn ->
   failIfZero "ExtSelectClipRgn" $ c_ExtSelectClipRgn dc p_rgn mode
-foreign import stdcall unsafe "windows.h ExtSelectClipRgn"
+foreign import WINDOWS_CCONV unsafe "windows.h ExtSelectClipRgn"
   c_ExtSelectClipRgn :: HDC -> PRGN -> ClippingMode -> IO RegionType
 
 selectClipPath :: HDC -> ClippingMode -> IO RegionType
 selectClipPath dc mode =
   failIfZero "SelectClipPath" $ c_SelectClipPath dc mode
-foreign import stdcall unsafe "windows.h SelectClipPath"
+foreign import WINDOWS_CCONV unsafe "windows.h SelectClipPath"
   c_SelectClipPath :: HDC -> ClippingMode -> IO RegionType
 
 ----------------------------------------------------------------
@@ -283,19 +285,19 @@
 cancelDC :: HDC -> IO ()
 cancelDC dc =
   failIfFalse_ "CancelDC" $ c_CancelDC dc
-foreign import stdcall unsafe "windows.h CancelDC"
+foreign import WINDOWS_CCONV unsafe "windows.h CancelDC"
   c_CancelDC :: HDC -> IO Bool
 
 createCompatibleDC :: Maybe HDC -> IO HDC
 createCompatibleDC mb_dc =
   failIfNull "CreateCompatibleDC" $ c_CreateCompatibleDC (maybePtr mb_dc)
-foreign import stdcall unsafe "windows.h CreateCompatibleDC"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateCompatibleDC"
   c_CreateCompatibleDC :: HDC -> IO HDC
 
 deleteDC :: HDC -> IO ()
 deleteDC dc =
   failIfFalse_ "DeleteDC" $ c_DeleteDC dc
-foreign import stdcall unsafe "windows.h DeleteDC"
+foreign import WINDOWS_CCONV unsafe "windows.h DeleteDC"
   c_DeleteDC :: HDC -> IO Bool
 
 ----------------------------------------------------------------
diff --git a/Graphics/Win32/GDI/Palette.hsc b/Graphics/Win32/GDI/Palette.hsc
--- a/Graphics/Win32/GDI/Palette.hsc
+++ b/Graphics/Win32/GDI/Palette.hsc
@@ -20,6 +20,7 @@
 import System.Win32.Types
 import Graphics.Win32.GDI.Types
 
+##include "windows_cconv.h"
 #include <windows.h>
 
 ----------------------------------------------------------------
@@ -35,13 +36,13 @@
 getStockPalette :: StockPalette -> IO HPALETTE
 getStockPalette sp =
   failIfNull "GetStockPalette" $ c_GetStockPalette sp
-foreign import stdcall unsafe "windows.h GetStockObject"
+foreign import WINDOWS_CCONV unsafe "windows.h GetStockObject"
   c_GetStockPalette :: StockPalette -> IO HPALETTE
 
 deletePalette :: HPALETTE -> IO ()
 deletePalette p =
   failIfFalse_ "DeletePalette" $ c_DeletePalette p
-foreign import stdcall unsafe "windows.h DeleteObject"
+foreign import WINDOWS_CCONV unsafe "windows.h DeleteObject"
   c_DeletePalette :: HPALETTE -> IO Bool
 
 ----------------------------------------------------------------
diff --git a/Graphics/Win32/GDI/Path.hs b/Graphics/Win32/GDI/Path.hs
--- a/Graphics/Win32/GDI/Path.hs
+++ b/Graphics/Win32/GDI/Path.hs
@@ -23,6 +23,8 @@
 import Graphics.Win32.GDI.Types
 import System.Win32.Types
 
+#include "windows_cconv.h"
+
 ----------------------------------------------------------------
 -- Paths
 ----------------------------------------------------------------
@@ -32,56 +34,56 @@
 beginPath :: HDC -> IO ()
 beginPath dc =
   failIfFalse_ "BeginPath" $ c_BeginPath dc
-foreign import stdcall unsafe "windows.h BeginPath"
+foreign import WINDOWS_CCONV unsafe "windows.h BeginPath"
   c_BeginPath :: HDC -> IO Bool
 
 closeFigure :: HDC -> IO ()
 closeFigure dc =
   failIfFalse_ "CloseFigure" $ c_CloseFigure dc
-foreign import stdcall unsafe "windows.h CloseFigure"
+foreign import WINDOWS_CCONV unsafe "windows.h CloseFigure"
   c_CloseFigure :: HDC -> IO Bool
 
 endPath :: HDC -> IO ()
 endPath dc =
   failIfFalse_ "EndPath" $ c_EndPath dc
-foreign import stdcall unsafe "windows.h EndPath"
+foreign import WINDOWS_CCONV unsafe "windows.h EndPath"
   c_EndPath :: HDC -> IO Bool
 
 fillPath :: HDC -> IO ()
 fillPath dc =
   failIfFalse_ "FillPath" $ c_FillPath dc
-foreign import stdcall unsafe "windows.h FillPath"
+foreign import WINDOWS_CCONV unsafe "windows.h FillPath"
   c_FillPath :: HDC -> IO Bool
 
 flattenPath :: HDC -> IO ()
 flattenPath dc =
   failIfFalse_ "FlattenPath" $ c_FlattenPath dc
-foreign import stdcall unsafe "windows.h FlattenPath"
+foreign import WINDOWS_CCONV unsafe "windows.h FlattenPath"
   c_FlattenPath :: HDC -> IO Bool
 
 pathToRegion :: HDC -> IO HRGN
 pathToRegion dc = do
   ptr <- failIfNull "PathToRegion" $ c_PathToRegion dc
   newForeignHANDLE ptr
-foreign import stdcall unsafe "windows.h PathToRegion"
+foreign import WINDOWS_CCONV unsafe "windows.h PathToRegion"
   c_PathToRegion :: HDC -> IO PRGN
 
 strokeAndFillPath :: HDC -> IO ()
 strokeAndFillPath dc =
   failIfFalse_ "StrokeAndFillPath" $ c_StrokeAndFillPath dc
-foreign import stdcall unsafe "windows.h StrokeAndFillPath"
+foreign import WINDOWS_CCONV unsafe "windows.h StrokeAndFillPath"
   c_StrokeAndFillPath :: HDC -> IO Bool
 
 strokePath :: HDC -> IO ()
 strokePath dc =
   failIfFalse_ "StrokePath" $ c_StrokePath dc
-foreign import stdcall unsafe "windows.h StrokePath"
+foreign import WINDOWS_CCONV unsafe "windows.h StrokePath"
   c_StrokePath :: HDC -> IO Bool
 
 widenPath :: HDC -> IO ()
 widenPath dc =
   failIfFalse_ "WidenPath" $ c_WidenPath dc
-foreign import stdcall unsafe "windows.h WidenPath"
+foreign import WINDOWS_CCONV unsafe "windows.h WidenPath"
   c_WidenPath :: HDC -> IO Bool
 
 ----------------------------------------------------------------
diff --git a/Graphics/Win32/GDI/Pen.hsc b/Graphics/Win32/GDI/Pen.hsc
--- a/Graphics/Win32/GDI/Pen.hsc
+++ b/Graphics/Win32/GDI/Pen.hsc
@@ -20,6 +20,8 @@
 import System.Win32.Types
 import Graphics.Win32.GDI.Types
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 
 ----------------------------------------------------------------
@@ -37,13 +39,13 @@
 getStockPen :: StockPen -> IO HPEN
 getStockPen stockpen =
   failIfNull "GetStockPen" $ c_GetStockPen stockpen
-foreign import stdcall unsafe "windows.h GetStockObject"
+foreign import WINDOWS_CCONV unsafe "windows.h GetStockObject"
   c_GetStockPen :: StockPen -> IO HPEN
 
 deletePen :: HPEN -> IO ()
 deletePen pen =
   failIfFalse_ "DeletePen" $ c_DeletePen pen
-foreign import stdcall unsafe "windows.h DeleteObject"
+foreign import WINDOWS_CCONV unsafe "windows.h DeleteObject"
   c_DeletePen :: HPEN -> IO Bool
 
 ----------------------------------------------------------------
@@ -92,7 +94,7 @@
 createPen :: PenStyle -> INT -> COLORREF -> IO HPEN
 createPen style n color =
   failIfNull "CreatePen" $ c_CreatePen style n color
-foreign import stdcall unsafe "windows.h CreatePen"
+foreign import WINDOWS_CCONV unsafe "windows.h CreatePen"
   c_CreatePen :: PenStyle -> INT -> COLORREF -> IO HPEN
 
 -- Not very well supported on Win'95
diff --git a/Graphics/Win32/GDI/Region.hs b/Graphics/Win32/GDI/Region.hs
--- a/Graphics/Win32/GDI/Region.hs
+++ b/Graphics/Win32/GDI/Region.hs
@@ -22,6 +22,8 @@
 
 import Foreign
 
+#include "windows_cconv.h"
+
 ----------------------------------------------------------------
 -- Regions
 ----------------------------------------------------------------
@@ -35,56 +37,56 @@
   withForeignPtr src1 $ \ p_src1 ->
   withForeignPtr src2 $ \ p_src2 ->
   failIf badRegion "CombineRgn" $ c_CombineRgn p_dest p_src1 p_src2 mode
-foreign import stdcall unsafe "windows.h CombineRgn"
+foreign import WINDOWS_CCONV unsafe "windows.h CombineRgn"
   c_CombineRgn :: PRGN -> PRGN -> PRGN -> ClippingMode -> IO RegionType
 
 offsetRgn :: HRGN -> INT -> INT -> IO RegionType
 offsetRgn rgn xoff yoff =
   withForeignPtr rgn $ \ p_rgn ->
   failIf badRegion "OffsetRgn" $ c_OffsetRgn p_rgn xoff yoff
-foreign import stdcall unsafe "windows.h OffsetRgn"
+foreign import WINDOWS_CCONV unsafe "windows.h OffsetRgn"
   c_OffsetRgn :: PRGN -> INT -> INT -> IO RegionType
 
 getRgnBox :: HRGN -> LPRECT -> IO RegionType
 getRgnBox rgn p_rect =
   withForeignPtr rgn $ \ p_rgn ->
   failIf badRegion "GetRgnBox" $ c_GetRgnBox p_rgn p_rect
-foreign import stdcall unsafe "windows.h GetRgnBox"
+foreign import WINDOWS_CCONV unsafe "windows.h GetRgnBox"
   c_GetRgnBox :: PRGN -> LPRECT -> IO RegionType
 
 createEllipticRgn :: INT -> INT -> INT -> INT -> IO HRGN
 createEllipticRgn x0 y0 x1 y1 = do
   ptr <- failIfNull "CreateEllipticRgn" $ c_CreateEllipticRgn x0 y0 x1 y1
   newForeignHANDLE ptr
-foreign import stdcall unsafe "windows.h CreateEllipticRgn"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateEllipticRgn"
   c_CreateEllipticRgn :: INT -> INT -> INT -> INT -> IO PRGN
 
 createEllipticRgnIndirect :: LPRECT -> IO HRGN
 createEllipticRgnIndirect rp = do
   ptr <- failIfNull "CreateEllipticRgnIndirect" $ c_CreateEllipticRgnIndirect rp
   newForeignHANDLE ptr
-foreign import stdcall unsafe "windows.h CreateEllipticRgnIndirect"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateEllipticRgnIndirect"
   c_CreateEllipticRgnIndirect :: LPRECT -> IO PRGN
 
 createRectRgn :: INT -> INT -> INT -> INT -> IO HRGN
 createRectRgn x0 y0 x1 y1 = do
   ptr <- failIfNull "CreateRectRgn" $ c_CreateRectRgn x0 y0 x1 y1
   newForeignHANDLE ptr
-foreign import stdcall unsafe "windows.h CreateRectRgn"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateRectRgn"
   c_CreateRectRgn :: INT -> INT -> INT -> INT -> IO PRGN
 
 createRectRgnIndirect :: LPRECT -> IO HRGN
 createRectRgnIndirect rp = do
   ptr <- failIfNull "CreateRectRgnIndirect" $ c_CreateRectRgnIndirect rp
   newForeignHANDLE ptr
-foreign import stdcall unsafe "windows.h CreateRectRgnIndirect"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateRectRgnIndirect"
   c_CreateRectRgnIndirect :: LPRECT -> IO PRGN
 
 createRoundRectRgn :: INT -> INT -> INT -> INT -> INT -> INT -> IO HRGN
 createRoundRectRgn x0 y0 x1 y1 h w = do
   ptr <- failIfNull "CreateRoundRectRgn" $ c_CreateRoundRectRgn x0 y0 x1 y1 h w
   newForeignHANDLE ptr
-foreign import stdcall unsafe "windows.h CreateRoundRectRgn"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateRoundRectRgn"
   c_CreateRoundRectRgn :: INT -> INT -> INT -> INT -> INT -> INT -> IO PRGN
 
 createPolygonRgn :: [POINT] -> PolyFillMode -> IO HRGN
@@ -93,54 +95,54 @@
   ptr <- failIfNull "CreatePolygonRgn" $
     c_CreatePolygonRgn point_array npoints mode
   newForeignHANDLE ptr
-foreign import stdcall unsafe "windows.h CreatePolygonRgn"
+foreign import WINDOWS_CCONV unsafe "windows.h CreatePolygonRgn"
   c_CreatePolygonRgn :: Ptr POINT -> Int -> PolyFillMode -> IO PRGN
 
 -- Needs to do proper error test for EqualRgn; GSL ???
 
-foreign import stdcall unsafe "windows.h EqualRgn"
+foreign import WINDOWS_CCONV unsafe "windows.h EqualRgn"
   equalRgn :: PRGN -> PRGN -> IO Bool
 
 fillRgn :: HDC -> HRGN -> HBRUSH -> IO ()
 fillRgn dc rgn brush =
   withForeignPtr rgn $ \ p_rgn ->
   failIfFalse_ "FillRgn" $ c_FillRgn dc p_rgn brush
-foreign import stdcall unsafe "windows.h FillRgn"
+foreign import WINDOWS_CCONV unsafe "windows.h FillRgn"
   c_FillRgn :: HDC -> PRGN -> HBRUSH -> IO Bool
 
 invertRgn :: HDC -> HRGN -> IO ()
 invertRgn dc rgn =
   withForeignPtr rgn $ \ p_rgn ->
   failIfFalse_ "InvertRgn" $ c_InvertRgn dc p_rgn
-foreign import stdcall unsafe "windows.h InvertRgn"
+foreign import WINDOWS_CCONV unsafe "windows.h InvertRgn"
   c_InvertRgn :: HDC -> PRGN -> IO Bool
 
 paintRgn :: HDC -> HRGN -> IO ()
 paintRgn dc rgn =
   withForeignPtr rgn $ \ p_rgn ->
   failIfFalse_ "PaintRgn" $ c_PaintRgn dc p_rgn
-foreign import stdcall unsafe "windows.h PaintRgn"
+foreign import WINDOWS_CCONV unsafe "windows.h PaintRgn"
   c_PaintRgn :: HDC -> PRGN -> IO Bool
 
 frameRgn :: HDC -> HRGN -> HBRUSH -> Int -> Int -> IO ()
 frameRgn dc rgn brush w h =
   withForeignPtr rgn $ \ p_rgn ->
   failIfFalse_ "FrameRgn" $ c_FrameRgn dc p_rgn brush w h
-foreign import stdcall unsafe "windows.h FrameRgn"
+foreign import WINDOWS_CCONV unsafe "windows.h FrameRgn"
   c_FrameRgn :: HDC -> PRGN -> HBRUSH -> Int -> Int -> IO Bool
 
 ptInRegion :: HRGN -> Int -> Int -> IO Bool
 ptInRegion rgn x y =
   withForeignPtr rgn $ \ p_rgn ->
   c_PtInRegion p_rgn x y
-foreign import stdcall unsafe "windows.h PtInRegion"
+foreign import WINDOWS_CCONV unsafe "windows.h PtInRegion"
   c_PtInRegion :: PRGN -> Int -> Int -> IO Bool
 
 rectInRegion :: HRGN -> RECT -> IO Bool
 rectInRegion rgn rect =
   withForeignPtr rgn $ \ p_rgn ->
   withRECT rect $ c_RectInRegion p_rgn
-foreign import stdcall unsafe "windows.h RectInRegion"
+foreign import WINDOWS_CCONV unsafe "windows.h RectInRegion"
   c_RectInRegion :: PRGN -> Ptr RECT -> IO Bool
 
 ----------------------------------------------------------------
diff --git a/Graphics/Win32/GDI/Types.hsc b/Graphics/Win32/GDI/Types.hsc
--- a/Graphics/Win32/GDI/Types.hsc
+++ b/Graphics/Win32/GDI/Types.hsc
@@ -215,11 +215,11 @@
 type   HWND       = HANDLE
 type MbHWND       = Maybe HWND
 
-#{enum HWND, castUINTToPtr
- , hWND_BOTTOM    = HWND_BOTTOM
- , hWND_NOTOPMOST = HWND_NOTOPMOST
- , hWND_TOP       = HWND_TOP
- , hWND_TOPMOST   = HWND_TOPMOST
+#{enum HWND, castUINTPtrToPtr
+ , hWND_BOTTOM    = (UINT_PTR)HWND_BOTTOM
+ , hWND_NOTOPMOST = (UINT_PTR)HWND_NOTOPMOST
+ , hWND_TOP       = (UINT_PTR)HWND_TOP
+ , hWND_TOPMOST   = (UINT_PTR)HWND_TOPMOST
  }
 
 type   HMENU      = HANDLE
diff --git a/Graphics/Win32/Icon.hs b/Graphics/Win32/Icon.hs
--- a/Graphics/Win32/Icon.hs
+++ b/Graphics/Win32/Icon.hs
@@ -20,6 +20,8 @@
 import Graphics.Win32.GDI.Types
 import System.Win32.Types
 
+#include "windows_cconv.h"
+
 ----------------------------------------------------------------
 -- Icons
 ----------------------------------------------------------------
@@ -27,19 +29,19 @@
 copyIcon :: HICON -> IO HICON
 copyIcon icon =
   failIfNull "CopyIcon" $ c_CopyIcon icon
-foreign import stdcall unsafe "windows.h CopyIcon"
+foreign import WINDOWS_CCONV unsafe "windows.h CopyIcon"
   c_CopyIcon :: HICON -> IO HICON
 
 drawIcon :: HDC -> Int -> Int -> HICON -> IO ()
 drawIcon dc x y icon =
   failIfFalse_ "DrawIcon" $ c_DrawIcon dc x y icon
-foreign import stdcall unsafe "windows.h DrawIcon"
+foreign import WINDOWS_CCONV unsafe "windows.h DrawIcon"
   c_DrawIcon :: HDC -> Int -> Int -> HICON -> IO Bool
 
 destroyIcon :: HICON -> IO ()
 destroyIcon icon =
   failIfFalse_ "DestroyIcon" $ c_DestroyIcon icon
-foreign import stdcall unsafe "windows.h DestroyIcon"
+foreign import WINDOWS_CCONV unsafe "windows.h DestroyIcon"
   c_DestroyIcon :: HICON -> IO Bool
 
 ----------------------------------------------------------------
diff --git a/Graphics/Win32/Key.hsc b/Graphics/Win32/Key.hsc
--- a/Graphics/Win32/Key.hsc
+++ b/Graphics/Win32/Key.hsc
@@ -22,6 +22,8 @@
 
 import Control.Monad (liftM)
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 
 type VKey   = DWORD
@@ -100,24 +102,24 @@
  , vK_SCROLL    = VK_SCROLL
  }
 
-foreign import stdcall unsafe "windows.h EnableWindow"
+foreign import WINDOWS_CCONV unsafe "windows.h EnableWindow"
   enableWindow :: HWND -> Bool -> IO Bool
 
 getActiveWindow :: IO (Maybe HWND)
 getActiveWindow = liftM ptrToMaybe c_GetActiveWindow
-foreign import stdcall unsafe "windows.h GetActiveWindow"
+foreign import WINDOWS_CCONV unsafe "windows.h GetActiveWindow"
   c_GetActiveWindow :: IO HWND
 
-foreign import stdcall unsafe "windows.h GetAsyncKeyState"
+foreign import WINDOWS_CCONV unsafe "windows.h GetAsyncKeyState"
   getAsyncKeyState :: Int -> IO WORD
 
 getFocus :: IO (Maybe HWND)
 getFocus = liftM ptrToMaybe c_GetFocus
-foreign import stdcall unsafe "windows.h GetFocus"
+foreign import WINDOWS_CCONV unsafe "windows.h GetFocus"
   c_GetFocus :: IO HWND
 
-foreign import stdcall unsafe "windows.h GetKBCodePage"
+foreign import WINDOWS_CCONV unsafe "windows.h GetKBCodePage"
   getKBCodePage :: IO UINT
 
-foreign import stdcall unsafe "windows.h IsWindowEnabled"
+foreign import WINDOWS_CCONV unsafe "windows.h IsWindowEnabled"
   isWindowEnabled :: HWND -> IO Bool
diff --git a/Graphics/Win32/Menu.hsc b/Graphics/Win32/Menu.hsc
--- a/Graphics/Win32/Menu.hsc
+++ b/Graphics/Win32/Menu.hsc
@@ -69,6 +69,8 @@
 import Foreign
 import Control.Monad (liftM)
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 
 type MenuName = LPCTSTR
@@ -77,32 +79,32 @@
 checkMenuItem menu item check = do
   rv <- failIf (== -1) "CheckMenuItem" $ c_CheckMenuItem menu item check
   return (rv == mF_CHECKED)
-foreign import stdcall unsafe "windows.h CheckMenuItem"
+foreign import WINDOWS_CCONV unsafe "windows.h CheckMenuItem"
   c_CheckMenuItem :: HMENU -> UINT -> UINT -> IO DWORD
 
 checkMenuRadioItem :: HMENU -> MenuItem -> MenuItem -> MenuItem -> MenuFlag -> IO ()
 checkMenuRadioItem menu first_id last_id check flags =
   failIfFalse_ "CheckMenuRadioItem" $
     c_CheckMenuRadioItem menu first_id last_id check flags
-foreign import stdcall unsafe "windows.h CheckMenuRadioItem"
+foreign import WINDOWS_CCONV unsafe "windows.h CheckMenuRadioItem"
   c_CheckMenuRadioItem :: HMENU -> UINT -> UINT -> UINT -> UINT -> IO Bool
 
 createMenu :: IO HMENU
 createMenu =
   failIfNull "CreateMenu" $ c_CreateMenu
-foreign import stdcall unsafe "windows.h CreateMenu"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateMenu"
   c_CreateMenu :: IO HMENU
 
 createPopupMenu :: IO HMENU
 createPopupMenu =
   failIfNull "CreatePopupMenu" $ c_CreatePopupMenu
-foreign import stdcall unsafe "windows.h CreatePopupMenu"
+foreign import WINDOWS_CCONV unsafe "windows.h CreatePopupMenu"
   c_CreatePopupMenu :: IO HMENU
 
 drawMenuBar :: HWND -> IO ()
 drawMenuBar wnd =
   failIfFalse_ "DrawMenuBar" $ c_DrawMenuBar wnd
-foreign import stdcall unsafe "windows.h DrawMenuBar"
+foreign import WINDOWS_CCONV unsafe "windows.h DrawMenuBar"
   c_DrawMenuBar :: HWND -> IO Bool
 
 type MenuState = MenuFlag
@@ -110,7 +112,7 @@
 enableMenuItem :: HMENU -> MenuItem -> MenuFlag -> IO MenuState
 enableMenuItem menu item flag =
   failIf (== 0xffffffff) "EnableMenuItem" $ c_EnableMenuItem menu item flag
-foreign import stdcall unsafe "windows.h EnableMenuItem"
+foreign import WINDOWS_CCONV unsafe "windows.h EnableMenuItem"
   c_EnableMenuItem :: HMENU -> UINT -> UINT -> IO MenuState
 
 type GMDIFlag = UINT
@@ -210,48 +212,48 @@
  , sC_SEPARATOR         = SC_SEPARATOR
  }
 
-foreign import stdcall unsafe "windows.h IsMenu" isMenu :: HMENU -> IO Bool
+foreign import WINDOWS_CCONV unsafe "windows.h IsMenu" isMenu :: HMENU -> IO Bool
 
 getSystemMenu :: HWND  -> Bool ->     IO (Maybe HMENU)
 getSystemMenu wnd revert =
   liftM ptrToMaybe $ c_GetSystemMenu wnd revert
-foreign import stdcall unsafe "windows.h GetSystemMenu"
+foreign import WINDOWS_CCONV unsafe "windows.h GetSystemMenu"
   c_GetSystemMenu :: HWND  -> Bool ->     IO HMENU
 
 getMenu :: HWND  ->             IO (Maybe HMENU)
 getMenu wnd =
   liftM ptrToMaybe $ c_GetMenu wnd
-foreign import stdcall unsafe "windows.h GetMenu"
+foreign import WINDOWS_CCONV unsafe "windows.h GetMenu"
   c_GetMenu :: HWND  ->             IO HMENU
 
 getMenuDefaultItem :: HMENU -> Bool -> GMDIFlag -> IO MenuItem
 getMenuDefaultItem menu bypos flags =
   failIf (== -1) "GetMenuDefaultItem" $ c_GetMenuDefaultItem menu bypos flags
-foreign import stdcall unsafe "windows.h GetMenuDefaultItem"
+foreign import WINDOWS_CCONV unsafe "windows.h GetMenuDefaultItem"
   c_GetMenuDefaultItem :: HMENU -> Bool -> UINT -> IO UINT
 
 getMenuState :: HMENU -> MenuItem -> MenuFlag -> IO MenuState
 getMenuState menu item flags =
   failIf (== -1) "GetMenuState" $ c_GetMenuState menu item flags
-foreign import stdcall unsafe "windows.h GetMenuState"
+foreign import WINDOWS_CCONV unsafe "windows.h GetMenuState"
   c_GetMenuState :: HMENU -> UINT -> UINT -> IO MenuState
 
 getSubMenu :: HMENU -> MenuItem -> IO (Maybe HMENU)
 getSubMenu menu pos =
   liftM ptrToMaybe $ c_GetSubMenu menu pos
-foreign import stdcall unsafe "windows.h GetSubMenu"
+foreign import WINDOWS_CCONV unsafe "windows.h GetSubMenu"
   c_GetSubMenu :: HMENU -> UINT -> IO HMENU
 
 setMenu :: HWND -> HMENU -> IO ()
 setMenu wnd menu =
   failIfFalse_ "SetMenu" $ c_SetMenu wnd menu
-foreign import stdcall unsafe "windows.h SetMenu"
+foreign import WINDOWS_CCONV unsafe "windows.h SetMenu"
   c_SetMenu :: HWND -> HMENU -> IO Bool
 
 getMenuItemCount :: HMENU -> IO Int
 getMenuItemCount menu =
   failIf (== -1) "GetMenuItemCount" $ c_GetMenuItemCount menu
-foreign import stdcall unsafe "windows.h GetMenuItemCount"
+foreign import WINDOWS_CCONV unsafe "windows.h GetMenuItemCount"
   c_GetMenuItemCount :: HMENU -> IO Int
 
 type MenuID = UINT
@@ -259,7 +261,7 @@
 getMenuItemID :: HMENU -> MenuItem -> IO MenuID
 getMenuItemID menu item =
   failIf (== -1) "GetMenuItemID" $ c_GetMenuItemID menu item
-foreign import stdcall unsafe "windows.h GetMenuItemID"
+foreign import WINDOWS_CCONV unsafe "windows.h GetMenuItemID"
   c_GetMenuItemID :: HMENU -> UINT -> IO MenuID
 
 data MenuItemInfo
@@ -341,7 +343,7 @@
   pokeFMask p_info mask
   failIfFalse_ "GetMenuItemInfo" $ c_GetMenuItemInfo menu item bypos p_info
   peekMenuItemInfo p_info
-foreign import stdcall unsafe "windows.h GetMenuItemInfoW"
+foreign import WINDOWS_CCONV unsafe "windows.h GetMenuItemInfoW"
   c_GetMenuItemInfo :: HMENU -> UINT -> Bool -> Ptr MenuItemInfo -> IO Bool
 
 getMenuItemRect :: HWND -> HMENU -> MenuItem -> IO RECT
@@ -349,17 +351,17 @@
   allocaRECT $ \ p_rect -> do
   failIfFalse_ "GetMenuItemRect" $ c_GetMenuItemRect wnd menu item p_rect
   peekRECT p_rect
-foreign import stdcall unsafe "windows.h GetMenuItemRect"
+foreign import WINDOWS_CCONV unsafe "windows.h GetMenuItemRect"
   c_GetMenuItemRect :: HWND -> HMENU -> UINT -> LPRECT -> IO Bool
 
-foreign import stdcall unsafe "windows.h HiliteMenuItem"
+foreign import WINDOWS_CCONV unsafe "windows.h HiliteMenuItem"
   hiliteMenuItem :: HWND  -> HMENU -> MenuItem -> MenuFlag -> IO Bool
 
 insertMenuItem :: HMENU -> MenuItem -> Bool -> MenuItemInfo -> IO ()
 insertMenuItem menu item bypos info =
   withMenuItemInfo info $ \ p_info ->
   failIfFalse_ "InsertMenuItem" $ c_InsertMenuItem menu item bypos p_info
-foreign import stdcall unsafe "windows.h InsertMenuItemW"
+foreign import WINDOWS_CCONV unsafe "windows.h InsertMenuItemW"
   c_InsertMenuItem :: HMENU -> UINT -> Bool -> Ptr MenuItemInfo -> IO Bool
 
 type Menu = LPCTSTR
@@ -369,7 +371,7 @@
 loadMenu :: Maybe HINSTANCE -> Menu -> IO HMENU
 loadMenu mb_inst menu =
   failIfNull "LoadMenu" $ c_LoadMenu (maybePtr mb_inst) menu
-foreign import stdcall unsafe "windows.h LoadMenuW"
+foreign import WINDOWS_CCONV unsafe "windows.h LoadMenuW"
   c_LoadMenu :: HINSTANCE -> Menu -> IO HMENU
 
 -- Dealing with mappings to/from structs is a pain in GC,
@@ -385,26 +387,26 @@
 setMenuDefaultItem :: HMENU -> MenuItem -> Bool -> IO ()
 setMenuDefaultItem menu item bypos =
   failIfFalse_ "SetMenuDefaultItem" $ c_SetMenuDefaultItem menu item bypos
-foreign import stdcall unsafe "windows.h SetMenuDefaultItem"
+foreign import WINDOWS_CCONV unsafe "windows.h SetMenuDefaultItem"
   c_SetMenuDefaultItem :: HMENU -> MenuItem -> Bool -> IO Bool
 
 setMenuItemBitmaps :: HMENU -> MenuItem -> MenuFlag -> HBITMAP -> HBITMAP -> IO ()
 setMenuItemBitmaps menu pos flags bm_unchecked bm_checked =
   failIfFalse_ "SetMenuItemBitmaps" $
     c_SetMenuItemBitmaps menu pos flags bm_unchecked bm_checked
-foreign import stdcall unsafe "windows.h SetMenuItemBitmaps"
+foreign import WINDOWS_CCONV unsafe "windows.h SetMenuItemBitmaps"
   c_SetMenuItemBitmaps :: HMENU -> UINT -> UINT -> HBITMAP -> HBITMAP -> IO Bool
 
 destroyMenu :: HMENU -> IO ()
 destroyMenu menu =
   failIfFalse_ "DestroyMenu" $ c_DestroyMenu menu
-foreign import stdcall unsafe "windows.h DestroyMenu"
+foreign import WINDOWS_CCONV unsafe "windows.h DestroyMenu"
   c_DestroyMenu :: HMENU -> IO Bool
 
 deleteMenu :: HMENU -> MenuItem -> MenuFlag -> IO ()
 deleteMenu menu item flag =
   failIfFalse_ "DeleteMenu" $ c_DeleteMenu menu item flag
-foreign import stdcall unsafe "windows.h DeleteMenu"
+foreign import WINDOWS_CCONV unsafe "windows.h DeleteMenu"
   c_DeleteMenu :: HMENU -> UINT -> UINT -> IO Bool
 
 setMenuItemInfo :: HMENU -> MenuItem -> Bool -> MenuItemMask -> MenuItemInfo -> IO ()
@@ -412,14 +414,14 @@
   withMenuItemInfo info $ \ p_info -> do
   pokeFMask p_info mask
   failIfFalse_ "SetMenuItemInfo" $ c_SetMenuItemInfo menu item bypos p_info
-foreign import stdcall unsafe "windows.h SetMenuItemInfoW"
+foreign import WINDOWS_CCONV unsafe "windows.h SetMenuItemInfoW"
   c_SetMenuItemInfo :: HMENU -> UINT -> Bool -> Ptr MenuItemInfo -> IO Bool
 
 trackPopupMenu :: HMENU -> TrackMenuFlag -> Int -> Int -> HWND -> RECT -> IO ()
 trackPopupMenu menu flags x y wnd rect =
   withRECT rect $ \ p_rect ->
   failIfFalse_ "TrackPopupMenu" $ c_TrackPopupMenu menu flags x y 0 wnd p_rect
-foreign import stdcall unsafe "windows.h TrackPopupMenu"
+foreign import WINDOWS_CCONV unsafe "windows.h TrackPopupMenu"
   c_TrackPopupMenu :: HMENU -> TrackMenuFlag -> Int -> Int -> Int -> HWND -> LPRECT -> IO Bool
 
 type TPMPARAMS = ()
@@ -436,7 +438,7 @@
 trackPopupMenuEx menu flags x y wnd mb_p_rect =
   maybeWith withTPMPARAMS mb_p_rect $ \ p_ptmp ->
   failIfFalse_ "TrackPopupMenuEx" $ c_TrackPopupMenuEx menu flags x y wnd p_ptmp
-foreign import stdcall unsafe "windows.h TrackPopupMenuEx"
+foreign import WINDOWS_CCONV unsafe "windows.h TrackPopupMenuEx"
   c_TrackPopupMenuEx :: HMENU -> TrackMenuFlag -> Int -> Int -> HWND -> Ptr TPMPARAMS -> IO Bool
 
 -- Note: these 3 assume the flags don't include MF_BITMAP or MF_OWNERDRAW
@@ -446,27 +448,27 @@
 appendMenu menu flags id_item name =
   withTString name $ \ c_name ->
   failIfFalse_ "AppendMenu" $ c_AppendMenu menu flags id_item c_name
-foreign import stdcall unsafe "windows.h AppendMenuW"
+foreign import WINDOWS_CCONV unsafe "windows.h AppendMenuW"
   c_AppendMenu :: HMENU -> UINT -> MenuID -> LPCTSTR -> IO Bool
 
 insertMenu :: HMENU -> MenuItem -> MenuFlag -> MenuID -> String -> IO ()
 insertMenu menu item flags id_item name =
   withTString name $ \ c_name ->
   failIfFalse_ "InsertMenu" $ c_InsertMenu menu item flags id_item c_name
-foreign import stdcall unsafe "windows.h InsertMenuW"
+foreign import WINDOWS_CCONV unsafe "windows.h InsertMenuW"
   c_InsertMenu :: HMENU -> UINT -> UINT -> MenuID -> LPCTSTR -> IO Bool
 
 modifyMenu :: HMENU -> MenuItem -> MenuFlag -> MenuID -> String -> IO ()
 modifyMenu menu item flags id_item name =
   withTString name $ \ c_name ->
   failIfFalse_ "ModifyMenu" $ c_ModifyMenu menu item flags id_item c_name
-foreign import stdcall unsafe "windows.h ModifyMenuW"
+foreign import WINDOWS_CCONV unsafe "windows.h ModifyMenuW"
   c_ModifyMenu :: HMENU -> UINT -> UINT -> MenuID -> LPCTSTR -> IO Bool
 
 removeMenu :: HMENU -> MenuItem -> MenuFlag -> IO ()
 removeMenu menu pos flags =
   failIfFalse_ "RemoveMenu" $ c_RemoveMenu menu pos flags
-foreign import stdcall unsafe "windows.h RemoveMenu"
+foreign import WINDOWS_CCONV unsafe "windows.h RemoveMenu"
   c_RemoveMenu :: HMENU -> UINT -> UINT -> IO Bool
 
 ----------------------------------------------------------------
diff --git a/Graphics/Win32/Message.hsc b/Graphics/Win32/Message.hsc
--- a/Graphics/Win32/Message.hsc
+++ b/Graphics/Win32/Message.hsc
@@ -19,6 +19,8 @@
 
 import System.Win32.Types
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 
 type WindowMessage   = DWORD
@@ -159,7 +161,7 @@
 registerWindowMessage :: String -> IO WindowMessage
 registerWindowMessage msg =
   withTString msg c_RegisterWindowMessage
-foreign import stdcall unsafe "windows.h RegisterWindowMessageW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegisterWindowMessageW"
   c_RegisterWindowMessage :: LPCTSTR -> IO WindowMessage
 
 -- These are WM_SIZE specific
diff --git a/Graphics/Win32/Misc.hsc b/Graphics/Win32/Misc.hsc
--- a/Graphics/Win32/Misc.hsc
+++ b/Graphics/Win32/Misc.hsc
@@ -23,8 +23,9 @@
 import Data.Maybe
 import Foreign
 
+##include "windows_cconv.h"
+
 #include <windows.h>
-#include "gettime.h"
 
 ----------------------------------------------------------------
 -- Resources
@@ -48,39 +49,39 @@
 loadAccelerators :: Maybe HINSTANCE -> Accelerator -> IO HACCEL
 loadAccelerators mb_inst accel =
   failIfNull "LoadAccelerators" $ c_LoadAccelerators (maybePtr mb_inst) accel
-foreign import stdcall unsafe "windows.h LoadAcceleratorsW"
+foreign import WINDOWS_CCONV unsafe "windows.h LoadAcceleratorsW"
   c_LoadAccelerators :: HINSTANCE -> Accelerator -> IO HACCEL
 
 loadCursor :: Maybe HINSTANCE -> Cursor -> IO HCURSOR
 loadCursor mb_inst cursor =
   failIfNull "LoadCursor" $ c_LoadCursor (maybePtr mb_inst) cursor
-foreign import stdcall unsafe "windows.h LoadCursorW"
+foreign import WINDOWS_CCONV unsafe "windows.h LoadCursorW"
   c_LoadCursor :: HINSTANCE -> Cursor -> IO HCURSOR
 
 loadIcon :: Maybe HINSTANCE -> Icon -> IO HICON
 loadIcon mb_inst icon =
   failIfNull "LoadIcon" $ c_LoadIcon (maybePtr mb_inst) icon
-foreign import stdcall unsafe "windows.h LoadIconW"
+foreign import WINDOWS_CCONV unsafe "windows.h LoadIconW"
   c_LoadIcon :: HINSTANCE -> Icon -> IO HICON
 
-#{enum Cursor, castUINTToPtr
- , iDC_ARROW        = (UINT)IDC_ARROW
- , iDC_IBEAM        = (UINT)IDC_IBEAM
- , iDC_WAIT         = (UINT)IDC_WAIT
- , iDC_CROSS        = (UINT)IDC_CROSS
- , iDC_UPARROW      = (UINT)IDC_UPARROW
- , iDC_SIZENWSE     = (UINT)IDC_SIZENWSE
- , iDC_SIZENESW     = (UINT)IDC_SIZENESW
- , iDC_SIZEWE       = (UINT)IDC_SIZEWE
- , iDC_SIZENS       = (UINT)IDC_SIZENS
+#{enum Cursor, castUINTPtrToPtr
+ , iDC_ARROW        = (UINT_PTR)IDC_ARROW
+ , iDC_IBEAM        = (UINT_PTR)IDC_IBEAM
+ , iDC_WAIT         = (UINT_PTR)IDC_WAIT
+ , iDC_CROSS        = (UINT_PTR)IDC_CROSS
+ , iDC_UPARROW      = (UINT_PTR)IDC_UPARROW
+ , iDC_SIZENWSE     = (UINT_PTR)IDC_SIZENWSE
+ , iDC_SIZENESW     = (UINT_PTR)IDC_SIZENESW
+ , iDC_SIZEWE       = (UINT_PTR)IDC_SIZEWE
+ , iDC_SIZENS       = (UINT_PTR)IDC_SIZENS
  }
 
-#{enum Icon, castUINTToPtr
- , iDI_APPLICATION  = (UINT)IDI_APPLICATION
- , iDI_HAND         = (UINT)IDI_HAND
- , iDI_QUESTION     = (UINT)IDI_QUESTION
- , iDI_EXCLAMATION  = (UINT)IDI_EXCLAMATION
- , iDI_ASTERISK     = (UINT)IDI_ASTERISK
+#{enum Icon, castUINTPtrToPtr
+ , iDI_APPLICATION  = (UINT_PTR)IDI_APPLICATION
+ , iDI_HAND         = (UINT_PTR)IDI_HAND
+ , iDI_QUESTION     = (UINT_PTR)IDI_QUESTION
+ , iDI_EXCLAMATION  = (UINT_PTR)IDI_EXCLAMATION
+ , iDI_ASTERISK     = (UINT_PTR)IDI_ASTERISK
  }
 
 ----------------------------------------------------------------
@@ -130,7 +131,7 @@
   withTString text $ \ c_text ->
   withTString caption $ \ c_caption ->
   failIfZero "MessageBox" $ c_MessageBox wnd c_text c_caption style
-foreign import stdcall unsafe "windows.h MessageBoxW"
+foreign import WINDOWS_CCONV unsafe "windows.h MessageBoxW"
   c_MessageBox :: HWND -> LPCTSTR -> LPCTSTR -> MBStyle -> IO MBStatus
 
 ----------------------------------------------------------------
@@ -148,7 +149,7 @@
 getStdHandle :: StdHandleId -> IO HANDLE
 getStdHandle hid =
   failIf (== iNVALID_HANDLE_VALUE) "GetStdHandle" $ c_GetStdHandle hid
-foreign import stdcall unsafe "windows.h GetStdHandle"
+foreign import WINDOWS_CCONV unsafe "windows.h GetStdHandle"
   c_GetStdHandle :: StdHandleId -> IO HANDLE
 
 ----------------------------------------------------------------
@@ -181,20 +182,20 @@
   allocaPOINT $ \ p_pt -> do
   failIfFalse_ "GetCursorPos" $ c_GetCursorPos p_pt
   peekPOINT p_pt
-foreign import stdcall unsafe "windows.h GetCursorPos"
+foreign import WINDOWS_CCONV unsafe "windows.h GetCursorPos"
   c_GetCursorPos :: Ptr POINT -> IO Bool
 
 setCursorPos :: POINT -> IO ()
 setCursorPos (x,y) =
   failIfFalse_ "setCursorPos" $ c_SetCursorPos x y
-foreign import stdcall unsafe "windows.h SetCursorPos"
+foreign import WINDOWS_CCONV unsafe "windows.h SetCursorPos"
   c_SetCursorPos :: LONG -> LONG -> IO Bool
 
 clipCursor :: RECT -> IO ()
 clipCursor rect =
   withRECT rect $ \ p_rect ->
   failIfFalse_ "ClipCursor" $ c_ClipCursor p_rect
-foreign import stdcall unsafe "windows.h ClipCursor"
+foreign import WINDOWS_CCONV unsafe "windows.h ClipCursor"
   c_ClipCursor :: Ptr RECT -> IO Bool
 
 getClipCursor :: IO RECT
@@ -202,7 +203,7 @@
   allocaRECT $ \ p_rect -> do
   failIfFalse_ "GetClipCursor" $ c_GetClipCursor p_rect
   peekRECT p_rect
-foreign import stdcall unsafe "windows.h GetClipCursor"
+foreign import WINDOWS_CCONV unsafe "windows.h GetClipCursor"
   c_GetClipCursor :: Ptr RECT -> IO Bool
 
 ----------------------------------------------------------------
@@ -222,7 +223,7 @@
 exitWindowsEx :: ExitOption -> IO ()
 exitWindowsEx opt =
   failIfFalse_ "ExitWindowsEx" $ c_ExitWindowsEx opt 0
-foreign import stdcall unsafe "windows.h ExitWindowsEx"
+foreign import WINDOWS_CCONV unsafe "windows.h ExitWindowsEx"
   c_ExitWindowsEx :: ExitOption -> DWORD -> IO Bool
 
 exitWindows :: IO ()
@@ -248,13 +249,13 @@
 messageBeep :: Maybe Beep -> IO ()
 messageBeep mb_beep =
   c_MessageBeep (maybeBeep mb_beep)
-foreign import stdcall unsafe "windows.h MessageBeep"
+foreign import WINDOWS_CCONV unsafe "windows.h MessageBeep"
   c_MessageBeep :: Beep -> IO ()
 
 beep :: WORD -> MbDuration -> IO ()
 beep freq mb_dur =
   failIfFalse_ "Beep" $ c_Beep freq (maybeDuration mb_dur)
-foreign import stdcall unsafe "windows.h Beep"
+foreign import WINDOWS_CCONV unsafe "windows.h Beep"
   c_Beep :: WORD -> Duration -> IO Bool
 
 ----------------------------------------------------------------
@@ -272,19 +273,19 @@
 setWinTimer :: HWND -> TimerId -> UINT -> IO TimerId
 setWinTimer wnd timer elapse =
   failIfZero "SetTimer" $ c_SetTimer wnd timer elapse nullFunPtr
-foreign import stdcall unsafe "windows.h SetTimer"
+foreign import WINDOWS_CCONV unsafe "windows.h SetTimer"
   c_SetTimer :: HWND -> TimerId -> UINT -> TIMERPROC -> IO TimerId
 
 killTimer :: Maybe HWND -> TimerId -> IO ()
 killTimer mb_wnd timer =
   failIfFalse_ "KillTimer" $ c_KillTimer (maybePtr mb_wnd) timer
-foreign import stdcall unsafe "windows.h KillTimer"
+foreign import WINDOWS_CCONV unsafe "windows.h KillTimer"
   c_KillTimer :: HWND -> TimerId -> IO Bool
 
 -- For documentation purposes:
 type MilliSeconds = DWORD
 
-foreign import stdcall unsafe "windows.h timeGetTime"
+foreign import WINDOWS_CCONV unsafe "windows.h timeGetTime"
   timeGetTime :: IO MilliSeconds
 
 ----------------------------------------------------------------
diff --git a/Graphics/Win32/Resource.hsc b/Graphics/Win32/Resource.hsc
--- a/Graphics/Win32/Resource.hsc
+++ b/Graphics/Win32/Resource.hsc
@@ -21,13 +21,15 @@
 
 import Foreign
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 
 beginUpdateResource :: String -> Bool -> IO HANDLE
 beginUpdateResource name del =
   withTString name $ \ c_name ->
   failIfNull "BeginUpdateResource" $ c_BeginUpdateResource c_name del
-foreign import stdcall unsafe "windows.h BeginUpdateResourceW"
+foreign import WINDOWS_CCONV unsafe "windows.h BeginUpdateResourceW"
   c_BeginUpdateResource :: LPCTSTR -> Bool -> IO HANDLE
 
 type ResourceImageType = UINT
@@ -45,42 +47,42 @@
 copyImage :: HANDLE -> ResourceImageType -> Int -> Int -> UINT -> IO HANDLE
 copyImage h ty x y flags =
   failIfNull "CopyImage" $ c_CopyImage h ty x y flags
-foreign import stdcall unsafe "windows.h CopyImage"
+foreign import WINDOWS_CCONV unsafe "windows.h CopyImage"
   c_CopyImage :: HANDLE -> ResourceImageType -> Int -> Int -> UINT -> IO HANDLE
 
 endUpdateResource :: HANDLE -> BOOL -> IO ()
 endUpdateResource h discard =
   failIfFalse_ "EndUpdateResource" $ c_EndUpdateResource h discard
-foreign import stdcall unsafe "windows.h EndUpdateResourceW"
+foreign import WINDOWS_CCONV unsafe "windows.h EndUpdateResourceW"
   c_EndUpdateResource :: HANDLE -> BOOL -> IO Bool
 
 type ResourceType = LPCTSTR
 
-#{enum ResourceType, castUINTToPtr
- , rT_ACCELERATOR  = (UINT)RT_ACCELERATOR // Accelerator table
- , rT_ANICURSOR    = (UINT)RT_ANICURSOR // Animated cursor
- , rT_ANIICON      = (UINT)RT_ANIICON   // Animated icon
- , rT_BITMAP       = (UINT)RT_BITMAP    // Bitmap resource
- , rT_CURSOR       = (UINT)RT_CURSOR    // Hardware-dependent cursor resource
- , rT_DIALOG       = (UINT)RT_DIALOG    // Dialog box
- , rT_FONT         = (UINT)RT_FONT      // Font resource
- , rT_FONTDIR      = (UINT)RT_FONTDIR    // Font directory resource
- , rT_GROUP_CURSOR = (UINT)RT_GROUP_CURSOR // Hardware-independent cursor resource
- , rT_GROUP_ICON   = (UINT)RT_GROUP_ICON // Hardware-independent icon resource
- , rT_HTML         = (UINT)RT_HTML      // HTML document
- , rT_ICON         = (UINT)RT_ICON      // Hardware-dependent icon resource
- , rT_MENU         = (UINT)RT_MENU      // Menu resource
- , rT_MESSAGETABLE = (UINT)RT_MESSAGETABLE // Message-table entry
- , rT_RCDATA       = (UINT)RT_RCDATA    // Application-defined resource (raw data)
- , rT_STRING       = (UINT)RT_STRING    // String-table entry
- , rT_VERSION      = (UINT)RT_VERSION   // Version resource
+#{enum ResourceType, castUINTPtrToPtr
+ , rT_ACCELERATOR  = (UINT_PTR)RT_ACCELERATOR // Accelerator table
+ , rT_ANICURSOR    = (UINT_PTR)RT_ANICURSOR // Animated cursor
+ , rT_ANIICON      = (UINT_PTR)RT_ANIICON   // Animated icon
+ , rT_BITMAP       = (UINT_PTR)RT_BITMAP    // Bitmap resource
+ , rT_CURSOR       = (UINT_PTR)RT_CURSOR    // Hardware-dependent cursor resource
+ , rT_DIALOG       = (UINT_PTR)RT_DIALOG    // Dialog box
+ , rT_FONT         = (UINT_PTR)RT_FONT      // Font resource
+ , rT_FONTDIR      = (UINT_PTR)RT_FONTDIR    // Font directory resource
+ , rT_GROUP_CURSOR = (UINT_PTR)RT_GROUP_CURSOR // Hardware-independent cursor resource
+ , rT_GROUP_ICON   = (UINT_PTR)RT_GROUP_ICON // Hardware-independent icon resource
+ , rT_HTML         = (UINT_PTR)RT_HTML      // HTML document
+ , rT_ICON         = (UINT_PTR)RT_ICON      // Hardware-dependent icon resource
+ , rT_MENU         = (UINT_PTR)RT_MENU      // Menu resource
+ , rT_MESSAGETABLE = (UINT_PTR)RT_MESSAGETABLE // Message-table entry
+ , rT_RCDATA       = (UINT_PTR)RT_RCDATA    // Application-defined resource (raw data)
+ , rT_STRING       = (UINT_PTR)RT_STRING    // String-table entry
+ , rT_VERSION      = (UINT_PTR)RT_VERSION   // Version resource
  }
 
 findResource :: HMODULE -> String -> ResourceType -> IO HRSRC
 findResource hmod name ty =
   withTString name $ \ c_name ->
   failIfNull "FindResource" $ c_FindResource hmod c_name ty
-foreign import stdcall unsafe "windows.h FindResourceW"
+foreign import WINDOWS_CCONV unsafe "windows.h FindResourceW"
   c_FindResource :: HMODULE -> LPCTSTR -> LPCTSTR -> IO HRSRC
 
 -- was: LPCTSTR_
@@ -88,7 +90,7 @@
 findResourceEx hmod name ty lang =
   withTString name $ \ c_name ->
   failIfNull "FindResourceEx" $ c_FindResourceEx hmod c_name ty lang
-foreign import stdcall unsafe "windows.h FindResourceExW"
+foreign import WINDOWS_CCONV unsafe "windows.h FindResourceExW"
   c_FindResourceEx :: HMODULE -> LPCTSTR -> LPCTSTR -> WORD -> IO HRSRC
 
 type ResourceSize = Int
@@ -115,25 +117,25 @@
 loadImage inst name ty x y load =
   withTString name $ \ c_name ->
   failIfNull "LoadImage" $ c_LoadImage inst c_name ty x y load
-foreign import stdcall unsafe "windows.h LoadImageW"
+foreign import WINDOWS_CCONV unsafe "windows.h LoadImageW"
   c_LoadImage :: HINSTANCE -> LPCTSTR -> ResourceImageType -> ResourceSize -> ResourceSize -> LoadImageFlags -> IO HANDLE
 
 loadResource :: HMODULE -> HRSRC -> IO HGLOBAL
 loadResource hmod res =
   failIfNull "LoadResource" $ c_LoadResource hmod res
-foreign import stdcall unsafe "windows.h LoadResource"
+foreign import WINDOWS_CCONV unsafe "windows.h LoadResource"
   c_LoadResource :: HMODULE -> HRSRC -> IO HGLOBAL
 
 lockResource :: HGLOBAL -> IO Addr
 lockResource res =
   failIfNull "LockResource" $ c_LockResource res
-foreign import stdcall unsafe "windows.h LockResource"
+foreign import WINDOWS_CCONV unsafe "windows.h LockResource"
   c_LockResource :: HGLOBAL -> IO Addr
 
 sizeofResource :: HMODULE -> HRSRC -> IO DWORD
 sizeofResource hmod res =
   failIfZero "SizeofResource" $ c_SizeofResource hmod res
-foreign import stdcall unsafe "windows.h SizeofResource"
+foreign import WINDOWS_CCONV unsafe "windows.h SizeofResource"
   c_SizeofResource :: HMODULE -> HRSRC -> IO DWORD
 
 -- was: LPCTSTR_
@@ -142,5 +144,5 @@
   withTString name $ \ c_name ->
   failIfFalse_ "UpdateResource" $
     c_UpdateResource h ty c_name lang p_data data_len
-foreign import stdcall unsafe "windows.h UpdateResourceW"
+foreign import WINDOWS_CCONV unsafe "windows.h UpdateResourceW"
   c_UpdateResource :: HANDLE -> LPCTSTR -> LPCTSTR -> WORD -> Addr -> DWORD -> IO Bool
diff --git a/Graphics/Win32/Window.hsc b/Graphics/Win32/Window.hsc
--- a/Graphics/Win32/Window.hsc
+++ b/Graphics/Win32/Window.hsc
@@ -1,3 +1,4 @@
+{-# LANGUAGE CApiFFI #-}
 #if __GLASGOW_HASKELL__ >= 701
 {-# LANGUAGE Trustworthy #-}
 #endif
@@ -26,6 +27,8 @@
 import Foreign hiding (unsafePerformIO)
 import System.IO.Unsafe
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 
 ----------------------------------------------------------------
@@ -91,7 +94,7 @@
   #{poke WNDCLASS,lpszClassName} p cls
   f p
 
-foreign import stdcall unsafe "WndProc.h &genericWndProc"
+foreign import WINDOWS_CCONV unsafe "WndProc.h &genericWndProc"
   genericWndProc_p :: FunPtr WindowClosure
 
 {-# CFILES cbits/WndProc.c #-}
@@ -100,10 +103,10 @@
 registerClass cls =
   withWNDCLASS cls $ \ p ->
   liftM numToMaybe $ c_RegisterClass p
-foreign import stdcall unsafe "windows.h RegisterClassW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegisterClassW"
   c_RegisterClass :: Ptr WNDCLASS -> IO ATOM
 
-foreign import stdcall unsafe "windows.h UnregisterClassW"
+foreign import WINDOWS_CCONV unsafe "windows.h UnregisterClassW"
   unregisterClass :: ClassName -> HINSTANCE -> IO ()
 
 ----------------------------------------------------------------
@@ -180,16 +183,17 @@
 
 type WindowClosure = HWND -> WindowMessage -> WPARAM -> LPARAM -> IO LRESULT
 
-foreign import stdcall "wrapper"
+foreign import WINDOWS_CCONV "wrapper"
   mkWindowClosure :: WindowClosure -> IO (FunPtr WindowClosure)
 
 setWindowClosure :: HWND -> WindowClosure -> IO ()
 setWindowClosure wnd closure = do
   fp <- mkWindowClosure closure
-  _ <- c_SetWindowLong wnd (#{const GWL_USERDATA}) (castFunPtrToLONG fp)
+  _ <- c_SetWindowLongPtr wnd (#{const GWLP_USERDATA})
+                              (castPtr (castFunPtrToPtr fp))
   return ()
-foreign import stdcall unsafe "windows.h SetWindowLongW"
-  c_SetWindowLong :: HWND -> INT -> LONG -> IO LONG
+foreign import capi unsafe "windows.h SetWindowLongPtrW"
+  c_SetWindowLongPtr :: HWND -> INT -> Ptr LONG -> IO (Ptr LONG)
 
 createWindow
   :: ClassName -> String -> WindowStyle ->
@@ -215,7 +219,7 @@
       (maybePtr mb_parent) (maybePtr mb_menu) inst nullPtr
   setWindowClosure wnd closure
   return wnd
-foreign import stdcall "windows.h CreateWindowExW"
+foreign import WINDOWS_CCONV "windows.h CreateWindowExW"
   c_CreateWindowEx
     :: WindowStyle -> ClassName -> LPCTSTR -> WindowStyle
     -> Pos -> Pos -> Pos -> Pos
@@ -227,7 +231,7 @@
 defWindowProc :: Maybe HWND -> WindowMessage -> WPARAM -> LPARAM -> IO LRESULT
 defWindowProc mb_wnd msg w l =
   c_DefWindowProc (maybePtr mb_wnd) msg w l
-foreign import stdcall "windows.h DefWindowProcW"
+foreign import WINDOWS_CCONV "windows.h DefWindowProcW"
   c_DefWindowProc :: HWND -> WindowMessage -> WPARAM -> LPARAM -> IO LRESULT
 
 ----------------------------------------------------------------
@@ -237,7 +241,7 @@
   allocaRECT $ \ p_rect -> do
   failIfFalse_ "GetClientRect" $ c_GetClientRect wnd p_rect
   peekRECT p_rect
-foreign import stdcall unsafe "windows.h GetClientRect"
+foreign import WINDOWS_CCONV unsafe "windows.h GetClientRect"
   c_GetClientRect :: HWND -> Ptr RECT -> IO Bool
 
 getWindowRect :: HWND -> IO RECT
@@ -245,7 +249,7 @@
   allocaRECT $ \ p_rect -> do
   failIfFalse_ "GetWindowRect" $ c_GetWindowRect wnd p_rect
   peekRECT p_rect
-foreign import stdcall unsafe "windows.h GetWindowRect"
+foreign import WINDOWS_CCONV unsafe "windows.h GetWindowRect"
   c_GetWindowRect :: HWND -> Ptr RECT -> IO Bool
 
 -- Should it be Maybe RECT instead?
@@ -254,7 +258,7 @@
 invalidateRect wnd p_mb_rect erase =
   failIfFalse_ "InvalidateRect" $
     c_InvalidateRect (maybePtr wnd) (maybePtr p_mb_rect) erase
-foreign import stdcall "windows.h InvalidateRect"
+foreign import WINDOWS_CCONV "windows.h InvalidateRect"
   c_InvalidateRect :: HWND -> LPRECT -> Bool -> IO Bool
 
 screenToClient :: HWND -> POINT -> IO POINT
@@ -262,7 +266,7 @@
   withPOINT pt $ \ p_pt -> do
   failIfFalse_ "ScreenToClient" $ c_ScreenToClient wnd p_pt
   peekPOINT p_pt
-foreign import stdcall unsafe "windows.h ScreenToClient"
+foreign import WINDOWS_CCONV unsafe "windows.h ScreenToClient"
   c_ScreenToClient :: HWND -> Ptr POINT -> IO Bool
 
 clientToScreen :: HWND -> POINT -> IO POINT
@@ -270,7 +274,7 @@
   withPOINT pt $ \ p_pt -> do
   failIfFalse_ "ClientToScreen" $ c_ClientToScreen wnd p_pt
   peekPOINT p_pt
-foreign import stdcall unsafe "windows.h ClientToScreen"
+foreign import WINDOWS_CCONV unsafe "windows.h ClientToScreen"
   c_ClientToScreen :: HWND -> Ptr POINT -> IO Bool
 
 ----------------------------------------------------------------
@@ -282,7 +286,7 @@
 setWindowText wnd text =
   withTString text $ \ c_text ->
   failIfFalse_ "SetWindowText" $ c_SetWindowText wnd c_text
-foreign import stdcall "windows.h SetWindowTextW"
+foreign import WINDOWS_CCONV "windows.h SetWindowTextW"
   c_SetWindowText :: HWND -> LPCTSTR -> IO Bool
 
 ----------------------------------------------------------------
@@ -306,10 +310,10 @@
 beginPaint :: HWND -> LPPAINTSTRUCT -> IO HDC
 beginPaint wnd paint =
   failIfNull "BeginPaint" $ c_BeginPaint wnd paint
-foreign import stdcall "windows.h BeginPaint"
+foreign import WINDOWS_CCONV "windows.h BeginPaint"
   c_BeginPaint :: HWND -> LPPAINTSTRUCT -> IO HDC
 
-foreign import stdcall "windows.h EndPaint"
+foreign import WINDOWS_CCONV "windows.h EndPaint"
   endPaint :: HWND -> LPPAINTSTRUCT -> IO ()
 -- Apparently always succeeds (return non-zero)
 
@@ -333,7 +337,7 @@
  , sW_RESTORE           = SW_RESTORE
  }
 
-foreign import stdcall "windows.h ShowWindow"
+foreign import WINDOWS_CCONV "windows.h ShowWindow"
   showWindow :: HWND  -> ShowWindowControl  -> IO Bool
 
 ----------------------------------------------------------------
@@ -345,7 +349,7 @@
   withRECT rect $ \ p_rect -> do
   failIfFalse_ "AdjustWindowRect" $ c_AdjustWindowRect p_rect style menu
   peekRECT p_rect
-foreign import stdcall unsafe "windows.h AdjustWindowRect"
+foreign import WINDOWS_CCONV unsafe "windows.h AdjustWindowRect"
   c_AdjustWindowRect :: Ptr RECT -> WindowStyle -> Bool -> IO Bool
 
 adjustWindowRectEx :: RECT -> WindowStyle -> Bool -> WindowStyleEx -> IO RECT
@@ -354,7 +358,7 @@
   failIfFalse_ "AdjustWindowRectEx" $
     c_AdjustWindowRectEx p_rect style menu exstyle
   peekRECT p_rect
-foreign import stdcall unsafe "windows.h AdjustWindowRectEx"
+foreign import WINDOWS_CCONV unsafe "windows.h AdjustWindowRectEx"
   c_AdjustWindowRectEx :: Ptr RECT -> WindowStyle -> Bool -> WindowStyleEx -> IO Bool
 
 -- Win2K and later:
@@ -381,25 +385,25 @@
 -- %code BOOL success = AnimateWindow(arg1,arg2,arg3)
 -- %fail { !success } { ErrorWin("AnimateWindow") }
 
-foreign import stdcall unsafe "windows.h AnyPopup"
+foreign import WINDOWS_CCONV unsafe "windows.h AnyPopup"
   anyPopup :: IO Bool
 
 arrangeIconicWindows :: HWND -> IO ()
 arrangeIconicWindows wnd =
   failIfFalse_ "ArrangeIconicWindows" $ c_ArrangeIconicWindows wnd
-foreign import stdcall unsafe "windows.h ArrangeIconicWindows"
+foreign import WINDOWS_CCONV unsafe "windows.h ArrangeIconicWindows"
   c_ArrangeIconicWindows :: HWND -> IO Bool
 
 beginDeferWindowPos :: Int -> IO HDWP
 beginDeferWindowPos n =
   failIfNull "BeginDeferWindowPos" $ c_BeginDeferWindowPos n
-foreign import stdcall unsafe "windows.h BeginDeferWindowPos"
+foreign import WINDOWS_CCONV unsafe "windows.h BeginDeferWindowPos"
   c_BeginDeferWindowPos :: Int -> IO HDWP
 
 bringWindowToTop :: HWND -> IO ()
 bringWindowToTop wnd =
   failIfFalse_ "BringWindowToTop" $ c_BringWindowToTop wnd
-foreign import stdcall "windows.h BringWindowToTop"
+foreign import WINDOWS_CCONV "windows.h BringWindowToTop"
   c_BringWindowToTop :: HWND -> IO Bool
 
 -- Can't pass structs with current FFI, so use a C wrapper (in Types)
@@ -421,19 +425,19 @@
 deferWindowPos :: HDWP -> HWND -> HWND -> Int -> Int -> Int -> Int -> SetWindowPosFlags -> IO HDWP
 deferWindowPos wp wnd after x y cx cy flags =
   failIfNull "DeferWindowPos" $ c_DeferWindowPos wp wnd after x y cx cy flags
-foreign import stdcall unsafe "windows.h DeferWindowPos"
+foreign import WINDOWS_CCONV unsafe "windows.h DeferWindowPos"
   c_DeferWindowPos :: HDWP -> HWND -> HWND -> Int -> Int -> Int -> Int -> SetWindowPosFlags -> IO HDWP
 
 destroyWindow :: HWND -> IO ()
 destroyWindow wnd =
   failIfFalse_ "DestroyWindow" $ c_DestroyWindow wnd
-foreign import stdcall "windows.h DestroyWindow"
+foreign import WINDOWS_CCONV "windows.h DestroyWindow"
   c_DestroyWindow :: HWND -> IO Bool
 
 endDeferWindowPos :: HDWP -> IO ()
 endDeferWindowPos pos =
   failIfFalse_ "EndDeferWindowPos" $ c_EndDeferWindowPos pos
-foreign import stdcall unsafe "windows.h EndDeferWindowPos"
+foreign import WINDOWS_CCONV unsafe "windows.h EndDeferWindowPos"
   c_EndDeferWindowPos :: HDWP -> IO Bool
 
 findWindow :: String -> String -> IO (Maybe HWND)
@@ -441,7 +445,7 @@
   withTString cname $ \ c_cname ->
   withTString wname $ \ c_wname ->
   liftM ptrToMaybe $ c_FindWindow c_cname c_wname
-foreign import stdcall unsafe "windows.h FindWindowW"
+foreign import WINDOWS_CCONV unsafe "windows.h FindWindowW"
   c_FindWindow :: LPCTSTR -> LPCTSTR -> IO HWND
 
 findWindowEx :: HWND -> HWND -> String -> String -> IO (Maybe HWND)
@@ -449,35 +453,35 @@
   withTString cname $ \ c_cname ->
   withTString wname $ \ c_wname ->
   liftM ptrToMaybe $ c_FindWindowEx parent after c_cname c_wname
-foreign import stdcall unsafe "windows.h FindWindowExW"
+foreign import WINDOWS_CCONV unsafe "windows.h FindWindowExW"
   c_FindWindowEx :: HWND -> HWND -> LPCTSTR -> LPCTSTR -> IO HWND
 
-foreign import stdcall unsafe "windows.h FlashWindow"
+foreign import WINDOWS_CCONV unsafe "windows.h FlashWindow"
   flashWindow :: HWND -> Bool -> IO Bool
 -- No error code
 
 moveWindow :: HWND -> Int -> Int -> Int -> Int -> Bool -> IO ()
 moveWindow wnd x y w h repaint =
   failIfFalse_ "MoveWindow" $ c_MoveWindow wnd x y w h repaint
-foreign import stdcall "windows.h MoveWindow"
+foreign import WINDOWS_CCONV "windows.h MoveWindow"
   c_MoveWindow :: HWND -> Int -> Int -> Int -> Int -> Bool -> IO Bool
 
-foreign import stdcall unsafe "windows.h GetDesktopWindow"
+foreign import WINDOWS_CCONV unsafe "windows.h GetDesktopWindow"
   getDesktopWindow :: IO HWND
 
-foreign import stdcall unsafe "windows.h GetForegroundWindow"
+foreign import WINDOWS_CCONV unsafe "windows.h GetForegroundWindow"
   getForegroundWindow :: IO HWND
 
 getParent :: HWND -> IO HWND
 getParent wnd =
   failIfNull "GetParent" $ c_GetParent wnd
-foreign import stdcall unsafe "windows.h GetParent"
+foreign import WINDOWS_CCONV unsafe "windows.h GetParent"
   c_GetParent :: HWND -> IO HWND
 
 getTopWindow :: HWND -> IO HWND
 getTopWindow wnd =
   failIfNull "GetTopWindow" $ c_GetTopWindow wnd
-foreign import stdcall unsafe "windows.h GetTopWindow"
+foreign import WINDOWS_CCONV unsafe "windows.h GetTopWindow"
   c_GetTopWindow :: HWND -> IO HWND
 
 
@@ -522,25 +526,25 @@
 getDCEx wnd rgn flags =
   withForeignPtr rgn $ \ p_rgn ->
   failIfNull "GetDCEx" $ c_GetDCEx wnd p_rgn flags
-foreign import stdcall unsafe "windows.h GetDCEx"
+foreign import WINDOWS_CCONV unsafe "windows.h GetDCEx"
   c_GetDCEx :: HWND -> PRGN -> GetDCExFlags -> IO HDC
 
 getDC :: Maybe HWND -> IO HDC
 getDC mb_wnd =
   failIfNull "GetDC" $ c_GetDC (maybePtr mb_wnd)
-foreign import stdcall unsafe "windows.h GetDC"
+foreign import WINDOWS_CCONV unsafe "windows.h GetDC"
   c_GetDC :: HWND -> IO HDC
 
 getWindowDC :: Maybe HWND -> IO HDC
 getWindowDC mb_wnd =
   failIfNull "GetWindowDC" $ c_GetWindowDC (maybePtr mb_wnd)
-foreign import stdcall unsafe "windows.h GetWindowDC"
+foreign import WINDOWS_CCONV unsafe "windows.h GetWindowDC"
   c_GetWindowDC :: HWND -> IO HDC
 
 releaseDC :: Maybe HWND -> HDC -> IO ()
 releaseDC mb_wnd dc =
   failIfFalse_ "ReleaseDC" $ c_ReleaseDC (maybePtr mb_wnd) dc
-foreign import stdcall unsafe "windows.h ReleaseDC"
+foreign import WINDOWS_CCONV unsafe "windows.h ReleaseDC"
   c_ReleaseDC :: HWND -> HDC -> IO Bool
 
 getDCOrgEx :: HDC -> IO POINT
@@ -548,7 +552,7 @@
   allocaPOINT $ \ p_pt -> do
   failIfFalse_ "GetDCOrgEx" $ c_GetDCOrgEx dc p_pt
   peekPOINT p_pt
-foreign import stdcall unsafe "windows.h GetDCOrgEx"
+foreign import WINDOWS_CCONV unsafe "windows.h GetDCOrgEx"
   c_GetDCOrgEx :: HDC -> Ptr POINT -> IO Bool
 
 ----------------------------------------------------------------
@@ -558,13 +562,13 @@
 hideCaret :: HWND -> IO ()
 hideCaret wnd =
   failIfFalse_ "HideCaret" $ c_HideCaret wnd
-foreign import stdcall unsafe "windows.h HideCaret"
+foreign import WINDOWS_CCONV unsafe "windows.h HideCaret"
   c_HideCaret :: HWND -> IO Bool
 
 showCaret :: HWND -> IO ()
 showCaret wnd =
   failIfFalse_ "ShowCaret" $ c_ShowCaret wnd
-foreign import stdcall unsafe "windows.h ShowCaret"
+foreign import WINDOWS_CCONV unsafe "windows.h ShowCaret"
   c_ShowCaret :: HWND -> IO Bool
 
 -- ToDo: allow arg2 to be NULL or {(HBITMAP)1}
@@ -573,13 +577,13 @@
 createCaret wnd bm mb_w mb_h =
   failIfFalse_ "CreateCaret" $
     c_CreateCaret wnd bm (maybeNum mb_w) (maybeNum mb_h)
-foreign import stdcall unsafe "windows.h CreateCaret"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateCaret"
   c_CreateCaret :: HWND -> HBITMAP -> INT -> INT -> IO Bool
 
 destroyCaret :: IO ()
 destroyCaret =
   failIfFalse_ "DestroyCaret" $ c_DestroyCaret
-foreign import stdcall unsafe "windows.h DestroyCaret"
+foreign import WINDOWS_CCONV unsafe "windows.h DestroyCaret"
   c_DestroyCaret :: IO Bool
 
 getCaretPos :: IO POINT
@@ -587,13 +591,13 @@
   allocaPOINT $ \ p_pt -> do
   failIfFalse_ "GetCaretPos" $ c_GetCaretPos p_pt
   peekPOINT p_pt
-foreign import stdcall unsafe "windows.h GetCaretPos"
+foreign import WINDOWS_CCONV unsafe "windows.h GetCaretPos"
   c_GetCaretPos :: Ptr POINT -> IO Bool
 
 setCaretPos :: POINT -> IO ()
 setCaretPos (x,y) =
   failIfFalse_ "SetCaretPos" $ c_SetCaretPos x y
-foreign import stdcall unsafe "windows.h SetCaretPos"
+foreign import WINDOWS_CCONV unsafe "windows.h SetCaretPos"
   c_SetCaretPos :: LONG -> LONG -> IO Bool
 
 -- The remarks on SetCaretBlinkTime are either highly risible or very sad -
@@ -643,7 +647,7 @@
   res <- failIf (== -1) "GetMessage" $
     c_GetMessage msg (maybePtr mb_wnd) 0 0
   return (res /= 0)
-foreign import stdcall "windows.h GetMessageW"
+foreign import WINDOWS_CCONV "windows.h GetMessageW"
   c_GetMessage :: LPMSG -> HWND -> UINT -> UINT -> IO LONG
 
 -- A NULL window requests messages for any window belonging to this thread.
@@ -654,26 +658,26 @@
 peekMessage msg mb_wnd filterMin filterMax remove = do
   failIf_ (== -1) "PeekMessage" $
     c_PeekMessage msg (maybePtr mb_wnd) filterMin filterMax remove
-foreign import stdcall "windows.h PeekMessageW"
+foreign import WINDOWS_CCONV "windows.h PeekMessageW"
   c_PeekMessage :: LPMSG -> HWND -> UINT -> UINT -> UINT -> IO LONG
 
 -- Note: you're not supposed to call this if you're using accelerators
 
-foreign import stdcall "windows.h TranslateMessage"
+foreign import WINDOWS_CCONV "windows.h TranslateMessage"
   translateMessage :: LPMSG -> IO BOOL
 
 updateWindow :: HWND -> IO ()
 updateWindow wnd =
   failIfFalse_ "UpdateWindow" $ c_UpdateWindow wnd
-foreign import stdcall "windows.h UpdateWindow"
+foreign import WINDOWS_CCONV "windows.h UpdateWindow"
   c_UpdateWindow :: HWND -> IO Bool
 
 -- Return value of DispatchMessage is usually ignored
 
-foreign import stdcall "windows.h DispatchMessageW"
+foreign import WINDOWS_CCONV "windows.h DispatchMessageW"
   dispatchMessage :: LPMSG -> IO LONG
 
-foreign import stdcall "windows.h SendMessageW"
+foreign import WINDOWS_CCONV "windows.h SendMessageW"
   sendMessage :: HWND -> WindowMessage -> WPARAM -> LPARAM -> IO LRESULT
 
 ----------------------------------------------------------------
diff --git a/System/Win32/Console.hsc b/System/Win32/Console.hsc
--- a/System/Win32/Console.hsc
+++ b/System/Win32/Console.hsc
@@ -26,18 +26,20 @@
 	generateConsoleCtrlEvent
   ) where
 
+##include "windows_cconv.h"
+
 import System.Win32.Types
 
-foreign import stdcall unsafe "windows.h GetConsoleCP"
+foreign import WINDOWS_CCONV unsafe "windows.h GetConsoleCP"
 	getConsoleCP :: IO UINT
 
-foreign import stdcall unsafe "windows.h SetConsoleCP"
+foreign import WINDOWS_CCONV unsafe "windows.h SetConsoleCP"
 	setConsoleCP :: UINT -> IO ()
 
-foreign import stdcall unsafe "windows.h GetConsoleOutputCP"
+foreign import WINDOWS_CCONV unsafe "windows.h GetConsoleOutputCP"
 	getConsoleOutputCP :: IO UINT
 
-foreign import stdcall unsafe "windows.h SetConsoleOutputCP"
+foreign import WINDOWS_CCONV unsafe "windows.h SetConsoleOutputCP"
 	setConsoleOutputCP :: UINT -> IO ()
 
 type CtrlEvent = DWORD
@@ -52,7 +54,7 @@
         "generateConsoleCtrlEvent"
         $ c_GenerateConsoleCtrlEvent e p
 
-foreign import stdcall safe "windows.h GenerateConsoleCtrlEvent"
+foreign import WINDOWS_CCONV safe "windows.h GenerateConsoleCtrlEvent"
     c_GenerateConsoleCtrlEvent :: CtrlEvent -> DWORD -> IO BOOL
 
 -- ToDo: lots more
diff --git a/System/Win32/DLL.hsc b/System/Win32/DLL.hsc
--- a/System/Win32/DLL.hsc
+++ b/System/Win32/DLL.hsc
@@ -22,18 +22,20 @@
 import Foreign
 import Foreign.C
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 
 disableThreadLibraryCalls :: HMODULE -> IO ()
 disableThreadLibraryCalls hmod =
   failIfFalse_ "DisableThreadLibraryCalls" $ c_DisableThreadLibraryCalls hmod
-foreign import stdcall unsafe "windows.h DisableThreadLibraryCalls"
+foreign import WINDOWS_CCONV unsafe "windows.h DisableThreadLibraryCalls"
   c_DisableThreadLibraryCalls :: HMODULE -> IO Bool
 
 freeLibrary :: HMODULE -> IO ()
 freeLibrary hmod =
   failIfFalse_ "FreeLibrary" $ c_FreeLibrary hmod
-foreign import stdcall unsafe "windows.h FreeLibrary"
+foreign import WINDOWS_CCONV unsafe "windows.h FreeLibrary"
   c_FreeLibrary :: HMODULE -> IO Bool
 
 {-# CFILES cbits/HsWin32.c #-}
@@ -45,28 +47,28 @@
   allocaArray 512 $ \ c_str -> do
   failIfFalse_ "GetModuleFileName" $ c_GetModuleFileName hmod c_str 512
   peekTString c_str
-foreign import stdcall unsafe "windows.h GetModuleFileNameW"
+foreign import WINDOWS_CCONV unsafe "windows.h GetModuleFileNameW"
   c_GetModuleFileName :: HMODULE -> LPTSTR -> Int -> IO Bool
 
 getModuleHandle :: Maybe String -> IO HMODULE
 getModuleHandle mb_name =
   maybeWith withTString mb_name $ \ c_name ->
   failIfNull "GetModuleHandle" $ c_GetModuleHandle c_name
-foreign import stdcall unsafe "windows.h GetModuleHandleW"
+foreign import WINDOWS_CCONV unsafe "windows.h GetModuleHandleW"
   c_GetModuleHandle :: LPCTSTR -> IO HMODULE
 
 getProcAddress :: HMODULE -> String -> IO Addr
 getProcAddress hmod procname =
   withCAString procname $ \ c_procname ->
   failIfNull "GetProcAddress" $ c_GetProcAddress hmod c_procname
-foreign import stdcall unsafe "windows.h GetProcAddress"
+foreign import WINDOWS_CCONV unsafe "windows.h GetProcAddress"
   c_GetProcAddress :: HMODULE -> LPCSTR -> IO Addr
 
 loadLibrary :: String -> IO HINSTANCE
 loadLibrary name =
   withTString name $ \ c_name ->
   failIfNull "LoadLibrary" $ c_LoadLibrary c_name
-foreign import stdcall unsafe "windows.h LoadLibraryW"
+foreign import WINDOWS_CCONV unsafe "windows.h LoadLibraryW"
   c_LoadLibrary :: LPCTSTR -> IO HINSTANCE
 
 type LoadLibraryFlags = DWORD
@@ -80,5 +82,5 @@
 loadLibraryEx name h flags =
   withTString name $ \ c_name ->
   failIfNull "LoadLibraryEx" $ c_LoadLibraryEx c_name h flags
-foreign import stdcall unsafe "windows.h LoadLibraryExW"
+foreign import WINDOWS_CCONV unsafe "windows.h LoadLibraryExW"
   c_LoadLibraryEx :: LPCTSTR -> HANDLE -> LoadLibraryFlags -> IO HINSTANCE
diff --git a/System/Win32/DebugApi.hsc b/System/Win32/DebugApi.hsc
--- a/System/Win32/DebugApi.hsc
+++ b/System/Win32/DebugApi.hsc
@@ -25,6 +25,7 @@
 import System.Win32.Types   ( HANDLE, BOOL, WORD, DWORD, failIf_, failWith
                             , getLastError, failIf, LPTSTR, withTString )
 
+##include "windows_cconv.h"
 #include "windows.h"
 
 type PID = DWORD
@@ -287,12 +288,10 @@
             (act buf)
 
 
+#if __i386__
 eax, ebx, ecx, edx :: Int
 esi, edi :: Int
 ebp, eip, esp :: Int
-segCs, segDs, segEs, segFs, segGs :: Int
-eFlags :: Int
-
 eax = (#offset CONTEXT, Eax)
 ebx = (#offset CONTEXT, Ebx)
 ecx = (#offset CONTEXT, Ecx)
@@ -302,11 +301,31 @@
 ebp = (#offset CONTEXT, Ebp)
 eip = (#offset CONTEXT, Eip)
 esp = (#offset CONTEXT, Esp)
+#elif __x86_64__
+rax, rbx, rcx, rdx :: Int
+rsi, rdi :: Int
+rbp, rip, rsp :: Int
+rax = (#offset CONTEXT, Rax)
+rbx = (#offset CONTEXT, Rbx)
+rcx = (#offset CONTEXT, Rcx)
+rdx = (#offset CONTEXT, Rdx)
+rsi = (#offset CONTEXT, Rsi)
+rdi = (#offset CONTEXT, Rdi)
+rbp = (#offset CONTEXT, Rbp)
+rip = (#offset CONTEXT, Rip)
+rsp = (#offset CONTEXT, Rsp)
+#else
+#error Unsupported architecture
+#endif
+
+segCs, segDs, segEs, segFs, segGs :: Int
 segCs = (#offset CONTEXT, SegCs)
 segDs = (#offset CONTEXT, SegDs)
 segEs = (#offset CONTEXT, SegEs)
 segFs = (#offset CONTEXT, SegFs)
 segGs = (#offset CONTEXT, SegGs)
+
+eFlags :: Int
 eFlags  = (#offset CONTEXT, EFlags)
 
 dr :: Int -> Int
@@ -346,45 +365,45 @@
 --------------------------------------------------------------------------
 -- Raw imports
 
-foreign import stdcall "windows.h SuspendThread"
+foreign import WINDOWS_CCONV "windows.h SuspendThread"
     c_SuspendThread :: THANDLE -> IO DWORD
 
-foreign import stdcall "windows.h ResumeThread"
+foreign import WINDOWS_CCONV "windows.h ResumeThread"
     c_ResumeThread :: THANDLE -> IO DWORD
 
-foreign import stdcall "windows.h WaitForDebugEvent"
+foreign import WINDOWS_CCONV "windows.h WaitForDebugEvent"
     c_WaitForDebugEvent :: Ptr () -> DWORD -> IO BOOL
 
-foreign import stdcall "windows.h ContinueDebugEvent"
+foreign import WINDOWS_CCONV "windows.h ContinueDebugEvent"
     c_ContinueDebugEvent :: DWORD -> DWORD -> DWORD -> IO BOOL
 
-foreign import stdcall "windows.h DebugActiveProcess"
+foreign import WINDOWS_CCONV "windows.h DebugActiveProcess"
     c_DebugActiveProcess :: DWORD -> IO Bool
     
 -- Windows XP
--- foreign import stdcall "windows.h DebugActiveProcessStop"
+-- foreign import WINDOWS_CCONV "windows.h DebugActiveProcessStop"
 --     c_DebugActiveProcessStop :: DWORD -> IO Bool
 
-foreign import stdcall "windows.h ReadProcessMemory" c_ReadProcessMemory :: 
+foreign import WINDOWS_CCONV "windows.h ReadProcessMemory" c_ReadProcessMemory :: 
     PHANDLE -> Ptr () -> Ptr Word8 -> DWORD -> Ptr DWORD -> IO BOOL
 
-foreign import stdcall "windows.h WriteProcessMemory" c_WriteProcessMemory ::
+foreign import WINDOWS_CCONV "windows.h WriteProcessMemory" c_WriteProcessMemory ::
     PHANDLE -> Ptr () -> Ptr Word8 -> DWORD -> Ptr DWORD -> IO BOOL
 
-foreign import stdcall "windows.h GetThreadContext"
+foreign import WINDOWS_CCONV "windows.h GetThreadContext"
     c_GetThreadContext :: THANDLE -> Ptr () -> IO BOOL
 
-foreign import stdcall "windows.h SetThreadContext"
+foreign import WINDOWS_CCONV "windows.h SetThreadContext"
     c_SetThreadContext :: THANDLE -> Ptr () -> IO BOOL
 
---foreign import stdcall "windows.h GetThreadId"
+--foreign import WINDOWS_CCONV "windows.h GetThreadId"
 --    c_GetThreadId :: THANDLE -> IO TID
 
-foreign import stdcall "windows.h OutputDebugStringW"
+foreign import WINDOWS_CCONV "windows.h OutputDebugStringW"
     c_OutputDebugString :: LPTSTR -> IO ()
 
-foreign import stdcall "windows.h IsDebuggerPresent"
+foreign import WINDOWS_CCONV "windows.h IsDebuggerPresent"
     isDebuggerPresent :: IO BOOL
 
-foreign import stdcall "windows.h  DebugBreak"
+foreign import WINDOWS_CCONV "windows.h  DebugBreak"
     debugBreak :: IO ()
diff --git a/System/Win32/File.hsc b/System/Win32/File.hsc
--- a/System/Win32/File.hsc
+++ b/System/Win32/File.hsc
@@ -31,6 +31,8 @@
 import Control.Monad
 import Control.Concurrent
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 
 ----------------------------------------------------------------
@@ -292,7 +294,7 @@
   withTString name $ \ c_name ->
     failIfFalseWithRetry_ (unwords ["DeleteFile",show name]) $
       c_DeleteFile c_name
-foreign import stdcall unsafe "windows.h DeleteFileW"
+foreign import WINDOWS_CCONV unsafe "windows.h DeleteFileW"
   c_DeleteFile :: LPCTSTR -> IO Bool
 
 copyFile :: String -> String -> Bool -> IO ()
@@ -301,7 +303,7 @@
   withTString dest $ \ c_dest ->
   failIfFalseWithRetry_ (unwords ["CopyFile",show src,show dest]) $
     c_CopyFile c_src c_dest over
-foreign import stdcall unsafe "windows.h CopyFileW"
+foreign import WINDOWS_CCONV unsafe "windows.h CopyFileW"
   c_CopyFile :: LPCTSTR -> LPCTSTR -> Bool -> IO Bool
 
 moveFile :: String -> String -> IO ()
@@ -310,7 +312,7 @@
   withTString dest $ \ c_dest ->
   failIfFalseWithRetry_ (unwords ["MoveFile",show src,show dest]) $
     c_MoveFile c_src c_dest
-foreign import stdcall unsafe "windows.h MoveFileW"
+foreign import WINDOWS_CCONV unsafe "windows.h MoveFileW"
   c_MoveFile :: LPCTSTR -> LPCTSTR -> IO Bool
 
 moveFileEx :: String -> String -> MoveFileFlag -> IO ()
@@ -319,7 +321,7 @@
   withTString dest $ \ c_dest ->
   failIfFalseWithRetry_ (unwords ["MoveFileEx",show src,show dest]) $
     c_MoveFileEx c_src c_dest flags
-foreign import stdcall unsafe "windows.h MoveFileExW"
+foreign import WINDOWS_CCONV unsafe "windows.h MoveFileExW"
   c_MoveFileEx :: LPCTSTR -> LPCTSTR -> MoveFileFlag -> IO Bool
 
 setCurrentDirectory :: String -> IO ()
@@ -327,7 +329,7 @@
   withTString name $ \ c_name ->
   failIfFalse_ (unwords ["SetCurrentDirectory",show name]) $
     c_SetCurrentDirectory c_name
-foreign import stdcall unsafe "windows.h SetCurrentDirectoryW"
+foreign import WINDOWS_CCONV unsafe "windows.h SetCurrentDirectoryW"
   c_SetCurrentDirectory :: LPCTSTR -> IO Bool
 
 createDirectory :: String -> Maybe LPSECURITY_ATTRIBUTES -> IO ()
@@ -335,7 +337,7 @@
   withTString name $ \ c_name ->
   failIfFalseWithRetry_ (unwords ["CreateDirectory",show name]) $
     c_CreateDirectory c_name (maybePtr mb_attr)
-foreign import stdcall unsafe "windows.h CreateDirectoryW"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateDirectoryW"
   c_CreateDirectory :: LPCTSTR -> LPSECURITY_ATTRIBUTES -> IO Bool
 
 createDirectoryEx :: String -> String -> Maybe LPSECURITY_ATTRIBUTES -> IO ()
@@ -344,7 +346,7 @@
   withTString name $ \ c_name ->
   failIfFalseWithRetry_ (unwords ["CreateDirectoryEx",show template,show name]) $
     c_CreateDirectoryEx c_template c_name (maybePtr mb_attr)
-foreign import stdcall unsafe "windows.h CreateDirectoryExW"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateDirectoryExW"
   c_CreateDirectoryEx :: LPCTSTR -> LPCTSTR -> LPSECURITY_ATTRIBUTES -> IO Bool
 
 removeDirectory :: String -> IO ()
@@ -352,7 +354,7 @@
   withTString name $ \ c_name ->
   failIfFalseWithRetry_ (unwords ["RemoveDirectory",show name]) $
     c_RemoveDirectory c_name
-foreign import stdcall unsafe "windows.h RemoveDirectoryW"
+foreign import WINDOWS_CCONV unsafe "windows.h RemoveDirectoryW"
   c_RemoveDirectory :: LPCTSTR -> IO Bool
 
 getBinaryType :: String -> IO BinaryType
@@ -362,7 +364,7 @@
   failIfFalse_ (unwords ["GetBinaryType",show name]) $
     c_GetBinaryType c_name p_btype
   peek p_btype
-foreign import stdcall unsafe "windows.h GetBinaryTypeW"
+foreign import WINDOWS_CCONV unsafe "windows.h GetBinaryTypeW"
   c_GetBinaryType :: LPCTSTR -> Ptr DWORD -> IO Bool
 
 ----------------------------------------------------------------
@@ -374,33 +376,33 @@
   withTString name $ \ c_name ->
   failIfWithRetry (==iNVALID_HANDLE_VALUE) (unwords ["CreateFile",show name]) $
     c_CreateFile c_name access share (maybePtr mb_attr) mode flag (maybePtr mb_h)
-foreign import stdcall unsafe "windows.h CreateFileW"
+foreign import WINDOWS_CCONV unsafe "windows.h CreateFileW"
   c_CreateFile :: LPCTSTR -> AccessMode -> ShareMode -> LPSECURITY_ATTRIBUTES -> CreateMode -> FileAttributeOrFlag -> HANDLE -> IO HANDLE
 
 closeHandle :: HANDLE -> IO ()
 closeHandle h =
   failIfFalse_ "CloseHandle" $ c_CloseHandle h
-foreign import stdcall unsafe "windows.h CloseHandle"
+foreign import WINDOWS_CCONV unsafe "windows.h CloseHandle"
   c_CloseHandle :: HANDLE -> IO Bool
 
 {-# CFILES cbits/HsWin32.c #-}
 foreign import ccall "HsWin32.h &CloseHandleFinaliser"
     c_CloseHandleFinaliser :: FunPtr (Ptr a -> IO ())
 
-foreign import stdcall unsafe "windows.h GetFileType"
+foreign import WINDOWS_CCONV unsafe "windows.h GetFileType"
   getFileType :: HANDLE -> IO FileType
 --Apparently no error code
 
 flushFileBuffers :: HANDLE -> IO ()
 flushFileBuffers h =
   failIfFalse_ "FlushFileBuffers" $ c_FlushFileBuffers h
-foreign import stdcall unsafe "windows.h FlushFileBuffers"
+foreign import WINDOWS_CCONV unsafe "windows.h FlushFileBuffers"
   c_FlushFileBuffers :: HANDLE -> IO Bool
 
 setEndOfFile :: HANDLE -> IO ()
 setEndOfFile h =
   failIfFalse_ "SetEndOfFile" $ c_SetEndOfFile h
-foreign import stdcall unsafe "windows.h SetEndOfFile"
+foreign import WINDOWS_CCONV unsafe "windows.h SetEndOfFile"
   c_SetEndOfFile :: HANDLE -> IO Bool
 
 setFileAttributes :: String -> FileAttributeOrFlag -> IO ()
@@ -408,7 +410,7 @@
   withTString name $ \ c_name ->
   failIfFalseWithRetry_ (unwords ["SetFileAttributes",show name])
     $ c_SetFileAttributes c_name attr
-foreign import stdcall unsafe "windows.h SetFileAttributesW"
+foreign import WINDOWS_CCONV unsafe "windows.h SetFileAttributesW"
   c_SetFileAttributes :: LPCTSTR -> FileAttributeOrFlag -> IO Bool
 
 getFileAttributes :: String -> IO FileAttributeOrFlag
@@ -416,14 +418,14 @@
   withTString name $ \ c_name ->
   failIfWithRetry (== 0xFFFFFFFF) (unwords ["GetFileAttributes",show name]) $
     c_GetFileAttributes c_name
-foreign import stdcall unsafe "windows.h GetFileAttributesW"
+foreign import WINDOWS_CCONV unsafe "windows.h GetFileAttributesW"
   c_GetFileAttributes :: LPCTSTR -> IO FileAttributeOrFlag
 
 getFileInformationByHandle :: HANDLE -> IO BY_HANDLE_FILE_INFORMATION
 getFileInformationByHandle h = alloca $ \res -> do
     failIfFalseWithRetry_ "GetFileInformationByHandle" $ c_GetFileInformationByHandle h res
     peek res
-foreign import stdcall unsafe "windows.h GetFileInformationByHandle"
+foreign import WINDOWS_CCONV unsafe "windows.h GetFileInformationByHandle"
     c_GetFileInformationByHandle :: HANDLE -> Ptr BY_HANDLE_FILE_INFORMATION -> IO BOOL
 
 ----------------------------------------------------------------
@@ -448,7 +450,7 @@
   alloca $ \ p_n -> do
   failIfFalse_ "ReadFile" $ c_ReadFile h buf n p_n (maybePtr mb_over)
   peek p_n
-foreign import stdcall unsafe "windows.h ReadFile"
+foreign import WINDOWS_CCONV unsafe "windows.h ReadFile"
   c_ReadFile :: HANDLE -> Ptr a -> DWORD -> Ptr DWORD -> LPOVERLAPPED -> IO Bool
 
 win32_WriteFile :: HANDLE -> Ptr a -> DWORD -> Maybe LPOVERLAPPED -> IO DWORD
@@ -456,7 +458,7 @@
   alloca $ \ p_n -> do
   failIfFalse_ "WriteFile" $ c_WriteFile h buf n p_n (maybePtr mb_over)
   peek p_n
-foreign import stdcall unsafe "windows.h WriteFile"
+foreign import WINDOWS_CCONV unsafe "windows.h WriteFile"
   c_WriteFile :: HANDLE -> Ptr a -> DWORD -> Ptr DWORD -> LPOVERLAPPED -> IO Bool
 
 -- missing Seek functioinality; GSL ???
@@ -475,19 +477,19 @@
   withTString path $ \ c_path ->
   failIfNull (unwords ["FindFirstChangeNotification",show path]) $
     c_FindFirstChangeNotification c_path watch flag
-foreign import stdcall unsafe "windows.h FindFirstChangeNotificationW"
+foreign import WINDOWS_CCONV unsafe "windows.h FindFirstChangeNotificationW"
   c_FindFirstChangeNotification :: LPCTSTR -> Bool -> FileNotificationFlag -> IO HANDLE
 
 findNextChangeNotification :: HANDLE -> IO ()
 findNextChangeNotification h =
   failIfFalse_ "FindNextChangeNotification" $ c_FindNextChangeNotification h
-foreign import stdcall unsafe "windows.h FindNextChangeNotification"
+foreign import WINDOWS_CCONV unsafe "windows.h FindNextChangeNotification"
   c_FindNextChangeNotification :: HANDLE -> IO Bool
 
 findCloseChangeNotification :: HANDLE -> IO ()
 findCloseChangeNotification h =
   failIfFalse_ "FindCloseChangeNotification" $ c_FindCloseChangeNotification h
-foreign import stdcall unsafe "windows.h FindCloseChangeNotification"
+foreign import WINDOWS_CCONV unsafe "windows.h FindCloseChangeNotification"
   c_FindCloseChangeNotification :: HANDLE -> IO Bool
 
 ----------------------------------------------------------------
@@ -511,7 +513,7 @@
                 failIf (== iNVALID_HANDLE_VALUE) "findFirstFile" $ 
                   c_FindFirstFile tstr p_finddata
     return (handle, FindData fp_finddata)
-foreign import stdcall unsafe "windows.h FindFirstFileW"
+foreign import WINDOWS_CCONV unsafe "windows.h FindFirstFileW"
   c_FindFirstFile :: LPCTSTR -> Ptr WIN32_FIND_DATA -> IO HANDLE
 
 findNextFile :: HANDLE -> FindData -> IO Bool -- False -> no more files
@@ -525,12 +527,12 @@
              if err_code == (# const ERROR_NO_MORE_FILES )
                 then return False
                 else failWith "findNextFile" err_code
-foreign import stdcall unsafe "windows.h FindNextFileW"
+foreign import WINDOWS_CCONV unsafe "windows.h FindNextFileW"
   c_FindNextFile :: HANDLE -> Ptr WIN32_FIND_DATA -> IO BOOL
 
 findClose :: HANDLE -> IO ()
 findClose h = failIfFalse_ "findClose" $ c_FindClose h
-foreign import stdcall unsafe "windows.h FindClose"
+foreign import WINDOWS_CCONV unsafe "windows.h FindClose"
   c_FindClose :: HANDLE -> IO BOOL
 
 ----------------------------------------------------------------
@@ -542,7 +544,7 @@
   withTString path $ \ c_path ->
   withTString name $ \ c_name ->
   failIfFalse_ "DefineDosDevice" $ c_DefineDosDevice flags c_name c_path
-foreign import stdcall unsafe "windows.h DefineDosDeviceW"
+foreign import WINDOWS_CCONV unsafe "windows.h DefineDosDeviceW"
   c_DefineDosDevice :: DefineDosDeviceFlags -> LPCTSTR -> LPCTSTR -> IO Bool
 
 ----------------------------------------------------------------
@@ -550,16 +552,16 @@
 -- These functions are very unusual in the Win32 API:
 -- They dont return error codes
 
-foreign import stdcall unsafe "windows.h AreFileApisANSI"
+foreign import WINDOWS_CCONV unsafe "windows.h AreFileApisANSI"
   areFileApisANSI :: IO Bool
 
-foreign import stdcall unsafe "windows.h SetFileApisToOEM"
+foreign import WINDOWS_CCONV unsafe "windows.h SetFileApisToOEM"
   setFileApisToOEM :: IO ()
 
-foreign import stdcall unsafe "windows.h SetFileApisToANSI"
+foreign import WINDOWS_CCONV unsafe "windows.h SetFileApisToANSI"
   setFileApisToANSI :: IO ()
 
-foreign import stdcall unsafe "windows.h SetHandleCount"
+foreign import WINDOWS_CCONV unsafe "windows.h SetHandleCount"
   setHandleCount :: UINT -> IO UINT
 
 ----------------------------------------------------------------
@@ -567,7 +569,7 @@
 getLogicalDrives :: IO DWORD
 getLogicalDrives =
   failIfZero "GetLogicalDrives" $ c_GetLogicalDrives
-foreign import stdcall unsafe "windows.h GetLogicalDrives"
+foreign import WINDOWS_CCONV unsafe "windows.h GetLogicalDrives"
   c_GetLogicalDrives :: IO DWORD
 
 -- %fun GetDriveType :: Maybe String -> IO DriveType
@@ -586,7 +588,7 @@
   nfree <- peek p_nfree
   nclusters <- peek p_nclusters
   return (sectors, bytes, nfree, nclusters)
-foreign import stdcall unsafe "windows.h GetDiskFreeSpaceW"
+foreign import WINDOWS_CCONV unsafe "windows.h GetDiskFreeSpaceW"
   c_GetDiskFreeSpace :: LPCTSTR -> Ptr DWORD -> Ptr DWORD -> Ptr DWORD -> Ptr DWORD -> IO Bool
 
 setVolumeLabel :: String -> String -> IO ()
@@ -594,7 +596,7 @@
   withTString path $ \ c_path ->
   withTString name $ \ c_name ->
   failIfFalse_ "SetVolumeLabel" $ c_SetVolumeLabel c_path c_name
-foreign import stdcall unsafe "windows.h SetVolumeLabelW"
+foreign import WINDOWS_CCONV unsafe "windows.h SetVolumeLabelW"
   c_SetVolumeLabel :: LPCTSTR -> LPCTSTR -> IO Bool
 
 ----------------------------------------------------------------
diff --git a/System/Win32/FileMapping.hsc b/System/Win32/FileMapping.hsc
--- a/System/Win32/FileMapping.hsc
+++ b/System/Win32/FileMapping.hsc
@@ -29,6 +29,8 @@
 import Foreign                  ( Ptr, nullPtr, plusPtr, maybeWith, FunPtr
                                 , ForeignPtr, newForeignPtr )
 
+##include "windows_cconv.h"
+
 #include "windows.h"
 
 ---------------------------------------------------------------------------
@@ -155,16 +157,16 @@
 ---------------------------------------------------------------------------
 -- Imports
 ---------------------------------------------------------------------------
-foreign import stdcall "windows.h OpenFileMappingW"
+foreign import WINDOWS_CCONV "windows.h OpenFileMappingW"
     c_OpenFileMapping :: DWORD -> BOOL -> LPCTSTR -> IO HANDLE
 
-foreign import stdcall "windows.h CreateFileMappingW"
+foreign import WINDOWS_CCONV "windows.h CreateFileMappingW"
     c_CreateFileMapping :: HANDLE -> Ptr () -> DWORD -> DWORD -> DWORD -> LPCTSTR -> IO HANDLE 
 
-foreign import stdcall "windows.h MapViewOfFileEx"
+foreign import WINDOWS_CCONV "windows.h MapViewOfFileEx"
     c_MapViewOfFileEx :: HANDLE -> DWORD -> DWORD -> DWORD -> SIZE_T -> Ptr a -> IO (Ptr b)
 
-foreign import stdcall "windows.h UnmapViewOfFile"
+foreign import WINDOWS_CCONV "windows.h UnmapViewOfFile"
     c_UnmapViewOfFile :: Ptr a -> IO BOOL
 
 {-# CFILES cbits/HsWin32.c #-}
diff --git a/System/Win32/Info.hsc b/System/Win32/Info.hsc
--- a/System/Win32/Info.hsc
+++ b/System/Win32/Info.hsc
@@ -19,13 +19,14 @@
 
 import System.Win32.Types
 
-import Prelude hiding (catch)
 import Control.Exception (catch)
-import System.IO.Error hiding (catch, try)
+import System.IO.Error
 import Foreign      ( Storable(sizeOf, alignment, peekByteOff, pokeByteOff,
                                peek, poke)
                     , Ptr, alloca, allocaArray )
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 
 ----------------------------------------------------------------
@@ -137,22 +138,22 @@
 	Left n    -> try loc f n   
 	Right str -> return str
 
-foreign import stdcall unsafe "GetWindowsDirectoryW"
+foreign import WINDOWS_CCONV unsafe "GetWindowsDirectoryW"
   c_getWindowsDirectory :: LPTSTR -> UINT -> IO UINT
 
-foreign import stdcall unsafe "GetSystemDirectoryW"
+foreign import WINDOWS_CCONV unsafe "GetSystemDirectoryW"
   c_getSystemDirectory :: LPTSTR -> UINT -> IO UINT
 
-foreign import stdcall unsafe "GetCurrentDirectoryW"
+foreign import WINDOWS_CCONV unsafe "GetCurrentDirectoryW"
   c_getCurrentDirectory :: DWORD -> LPTSTR -> IO UINT
 
-foreign import stdcall unsafe "GetTempPathW"
+foreign import WINDOWS_CCONV unsafe "GetTempPathW"
   c_getTempPath :: DWORD -> LPTSTR -> IO UINT
 
-foreign import stdcall unsafe "GetFullPathNameW"
+foreign import WINDOWS_CCONV unsafe "GetFullPathNameW"
   c_GetFullPathName :: LPCTSTR -> DWORD -> LPTSTR -> Ptr LPTSTR -> IO DWORD
 
-foreign import stdcall unsafe "SearchPathW"
+foreign import WINDOWS_CCONV unsafe "SearchPathW"
   c_SearchPath :: LPCTSTR -> LPCTSTR -> LPCTSTR -> DWORD -> LPTSTR -> Ptr LPTSTR
                -> IO DWORD
 
@@ -246,7 +247,7 @@
             siProcessorRevision         = processorRevision
             }
 
-foreign import stdcall unsafe "windows.h GetSystemInfo"
+foreign import WINDOWS_CCONV unsafe "windows.h GetSystemInfo"
     c_GetSystemInfo :: Ptr SYSTEM_INFO -> IO ()
 
 getSystemInfo :: IO SYSTEM_INFO
diff --git a/System/Win32/Mem.hsc b/System/Win32/Mem.hsc
--- a/System/Win32/Mem.hsc
+++ b/System/Win32/Mem.hsc
@@ -22,6 +22,8 @@
 import Foreign
 import Foreign.C.Types
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 
 copyMemory :: Ptr a -> Ptr a -> DWORD -> IO ()
@@ -39,11 +41,11 @@
 
 foreign import ccall unsafe "string.h" memset :: Ptr a -> CInt -> CSize -> IO ()
 
-foreign import stdcall unsafe "windows.h GetProcessHeap"
+foreign import WINDOWS_CCONV unsafe "windows.h GetProcessHeap"
   getProcessHeap :: IO HANDLE
 
 #ifndef __WINE_WINDOWS_H
-foreign import stdcall unsafe "windows.h GetProcessHeaps"
+foreign import WINDOWS_CCONV unsafe "windows.h GetProcessHeaps"
   getProcessHeaps :: DWORD -> Addr -> IO DWORD
 #endif
 
@@ -72,7 +74,7 @@
 globalAlloc :: GlobalAllocFlags -> DWORD -> IO HGLOBAL
 globalAlloc flags size =
   failIfNull "GlobalAlloc" $ c_GlobalAlloc flags size
-foreign import stdcall unsafe "windows.h GlobalAlloc"
+foreign import WINDOWS_CCONV unsafe "windows.h GlobalAlloc"
   c_GlobalAlloc :: GlobalAllocFlags -> DWORD -> IO HGLOBAL
 
 -- %fun GlobalDiscard :: HGLOBAL -> IO HGLOBAL
@@ -81,25 +83,25 @@
 globalFlags :: HGLOBAL -> IO GlobalAllocFlags
 globalFlags mem =
   failIf (== gMEM_INVALID_HANDLE) "GlobalFlags" $ c_GlobalFlags mem
-foreign import stdcall unsafe "windows.h GlobalFlags"
+foreign import WINDOWS_CCONV unsafe "windows.h GlobalFlags"
   c_GlobalFlags :: HGLOBAL -> IO GlobalAllocFlags
 
 globalFree :: HGLOBAL -> IO HGLOBAL
 globalFree mem =
   failIfNull "GlobalFree" $ c_GlobalFree mem
-foreign import stdcall unsafe "windows.h GlobalFree"
+foreign import WINDOWS_CCONV unsafe "windows.h GlobalFree"
   c_GlobalFree :: HGLOBAL -> IO HGLOBAL
 
 globalHandle :: Addr -> IO HGLOBAL
 globalHandle addr =
   failIfNull "GlobalHandle" $ c_GlobalHandle addr
-foreign import stdcall unsafe "windows.h GlobalHandle"
+foreign import WINDOWS_CCONV unsafe "windows.h GlobalHandle"
   c_GlobalHandle :: Addr -> IO HGLOBAL
 
 globalLock :: HGLOBAL -> IO Addr
 globalLock mem =
   failIfNull "GlobalLock" $ c_GlobalLock mem
-foreign import stdcall unsafe "windows.h GlobalLock"
+foreign import WINDOWS_CCONV unsafe "windows.h GlobalLock"
   c_GlobalLock :: HGLOBAL -> IO Addr
 
 -- %fun GlobalMemoryStatus :: IO MEMORYSTATUS
@@ -107,19 +109,19 @@
 globalReAlloc :: HGLOBAL -> DWORD -> GlobalAllocFlags -> IO HGLOBAL
 globalReAlloc mem size flags =
   failIfNull "GlobalReAlloc" $ c_GlobalReAlloc mem size flags
-foreign import stdcall unsafe "windows.h GlobalReAlloc"
+foreign import WINDOWS_CCONV unsafe "windows.h GlobalReAlloc"
   c_GlobalReAlloc :: HGLOBAL -> DWORD -> GlobalAllocFlags -> IO HGLOBAL
 
 globalSize :: HGLOBAL -> IO DWORD
 globalSize mem =
   failIfZero "GlobalSize" $ c_GlobalSize mem
-foreign import stdcall unsafe "windows.h GlobalSize"
+foreign import WINDOWS_CCONV unsafe "windows.h GlobalSize"
   c_GlobalSize :: HGLOBAL -> IO DWORD
 
 globalUnlock :: HGLOBAL -> IO ()
 globalUnlock mem =
   failIfFalse_ "GlobalUnlock" $ c_GlobalUnlock mem
-foreign import stdcall unsafe "windows.h GlobalUnlock"
+foreign import WINDOWS_CCONV unsafe "windows.h GlobalUnlock"
   c_GlobalUnlock :: HGLOBAL -> IO Bool
 
 type HeapAllocFlags = DWORD
@@ -133,58 +135,58 @@
 heapAlloc :: HANDLE -> HeapAllocFlags -> DWORD -> IO Addr
 heapAlloc heap flags size =
   failIfNull "HeapAlloc" $ c_HeapAlloc heap flags size
-foreign import stdcall unsafe "windows.h HeapAlloc"
+foreign import WINDOWS_CCONV unsafe "windows.h HeapAlloc"
   c_HeapAlloc :: HANDLE -> HeapAllocFlags -> DWORD -> IO Addr
 
 heapCompact :: HANDLE -> HeapAllocFlags -> IO UINT
 heapCompact heap flags =
   failIfZero "HeapCompact" $ c_HeapCompact heap flags
-foreign import stdcall unsafe "windows.h HeapCompact"
+foreign import WINDOWS_CCONV unsafe "windows.h HeapCompact"
   c_HeapCompact :: HANDLE -> HeapAllocFlags -> IO UINT
 
 heapCreate :: HeapAllocFlags -> DWORD -> DWORD -> IO HANDLE
 heapCreate flags initSize maxSize =
   failIfNull "HeapCreate" $ c_HeapCreate flags initSize maxSize
-foreign import stdcall unsafe "windows.h HeapCreate"
+foreign import WINDOWS_CCONV unsafe "windows.h HeapCreate"
   c_HeapCreate :: HeapAllocFlags -> DWORD -> DWORD -> IO HANDLE
 
 heapDestroy :: HANDLE -> IO ()
 heapDestroy heap =
   failIfFalse_ "HeapDestroy" $ c_HeapDestroy heap
-foreign import stdcall unsafe "windows.h HeapDestroy"
+foreign import WINDOWS_CCONV unsafe "windows.h HeapDestroy"
   c_HeapDestroy :: HANDLE -> IO Bool
 
 heapFree :: HANDLE -> HeapAllocFlags -> Addr -> IO ()
 heapFree heap flags addr =
   failIfFalse_ "HeapFree" $ c_HeapFree heap flags addr
-foreign import stdcall unsafe "windows.h HeapFree"
+foreign import WINDOWS_CCONV unsafe "windows.h HeapFree"
   c_HeapFree :: HANDLE -> HeapAllocFlags -> Addr -> IO Bool
 
 heapLock :: HANDLE -> IO ()
 heapLock heap =
   failIfFalse_ "HeapLock" $ c_HeapLock heap
-foreign import stdcall unsafe "windows.h HeapLock"
+foreign import WINDOWS_CCONV unsafe "windows.h HeapLock"
   c_HeapLock :: HANDLE -> IO Bool
 
 heapReAlloc :: HANDLE -> HeapAllocFlags -> Addr -> DWORD -> IO Addr
 heapReAlloc heap flags addr size =
   failIfNull "HeapReAlloc" $ c_HeapReAlloc heap flags addr size
-foreign import stdcall unsafe "windows.h HeapReAlloc"
+foreign import WINDOWS_CCONV unsafe "windows.h HeapReAlloc"
   c_HeapReAlloc :: HANDLE -> HeapAllocFlags -> Addr -> DWORD -> IO Addr
 
 heapSize :: HANDLE -> HeapAllocFlags -> Addr -> IO DWORD
 heapSize heap flags addr =
   failIfZero "HeapSize" $ c_HeapSize heap flags addr
-foreign import stdcall unsafe "windows.h HeapSize"
+foreign import WINDOWS_CCONV unsafe "windows.h HeapSize"
   c_HeapSize :: HANDLE -> HeapAllocFlags -> Addr -> IO DWORD
 
 heapUnlock :: HANDLE -> IO ()
 heapUnlock heap =
   failIfFalse_ "HeapUnlock" $ c_HeapUnlock heap
-foreign import stdcall unsafe "windows.h HeapUnlock"
+foreign import WINDOWS_CCONV unsafe "windows.h HeapUnlock"
   c_HeapUnlock :: HANDLE -> IO Bool
 
-foreign import stdcall unsafe "windows.h HeapValidate"
+foreign import WINDOWS_CCONV unsafe "windows.h HeapValidate"
   heapValidate :: HANDLE -> HeapAllocFlags -> Addr -> IO Bool
 
 type VirtualAllocFlags = DWORD
@@ -219,7 +221,7 @@
 virtualAlloc :: Addr -> DWORD -> VirtualAllocFlags -> ProtectFlags -> IO Addr
 virtualAlloc addt size ty flags =
   failIfNull "VirtualAlloc" $ c_VirtualAlloc addt size ty flags
-foreign import stdcall unsafe "windows.h VirtualAlloc"
+foreign import WINDOWS_CCONV unsafe "windows.h VirtualAlloc"
   c_VirtualAlloc :: Addr -> DWORD -> DWORD -> DWORD -> IO Addr
 
 -- %fun VirtualAllocEx :: HANDLE -> Addr -> DWORD -> VirtualAllocFlags -> ProtectFlags ->IO Addr
@@ -230,7 +232,7 @@
 virtualFree :: Addr -> DWORD -> FreeFlags -> IO ()
 virtualFree addr size flags =
   failIfFalse_ "VirtualFree" $ c_VirtualFree addr size flags
-foreign import stdcall unsafe "windows.h VirtualFree"
+foreign import WINDOWS_CCONV unsafe "windows.h VirtualFree"
   c_VirtualFree :: Addr -> DWORD -> FreeFlags -> IO Bool
 
 -- %fun VirtualFreeEx :: HANDLE -> Addr -> DWORD -> FreeFlags -> IO ()
@@ -241,7 +243,7 @@
 virtualLock :: Addr -> DWORD -> IO ()
 virtualLock addr size =
   failIfFalse_ "VirtualLock" $ c_VirtualLock addr size
-foreign import stdcall unsafe "windows.h VirtualLock"
+foreign import WINDOWS_CCONV unsafe "windows.h VirtualLock"
   c_VirtualLock :: Addr -> DWORD -> IO Bool
 
 virtualProtect :: Addr -> DWORD -> ProtectFlags -> IO ProtectFlags
@@ -249,7 +251,7 @@
   alloca $ \ p_old -> do
   failIfFalse_ "VirtualProtect" $ c_VirtualProtect addr size new_prot p_old
   peek p_old
-foreign import stdcall unsafe "windows.h VirtualProtect"
+foreign import WINDOWS_CCONV unsafe "windows.h VirtualProtect"
   c_VirtualProtect :: Addr -> DWORD -> DWORD -> Ptr DWORD -> IO Bool
 
 virtualProtectEx :: HANDLE -> Addr -> DWORD -> ProtectFlags -> IO ProtectFlags
@@ -258,7 +260,7 @@
   failIfFalse_ "VirtualProtectEx" $
     c_VirtualProtectEx proc addr size new_prot p_old
   peek p_old
-foreign import stdcall unsafe "windows.h VirtualProtectEx"
+foreign import WINDOWS_CCONV unsafe "windows.h VirtualProtectEx"
   c_VirtualProtectEx :: HANDLE -> Addr -> DWORD -> DWORD -> Ptr DWORD -> IO Bool
 
 -- No VirtualQuery..()
@@ -266,5 +268,5 @@
 virtualUnlock :: Addr -> DWORD -> IO ()
 virtualUnlock addr size =
   failIfFalse_ "VirtualUnlock" $ c_VirtualUnlock addr size
-foreign import stdcall unsafe "windows.h VirtualUnlock"
+foreign import WINDOWS_CCONV unsafe "windows.h VirtualUnlock"
   c_VirtualUnlock :: Addr -> DWORD -> IO Bool
diff --git a/System/Win32/NLS.hsc b/System/Win32/NLS.hsc
--- a/System/Win32/NLS.hsc
+++ b/System/Win32/NLS.hsc
@@ -29,6 +29,8 @@
 import Foreign
 import Foreign.C
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 #include "errors.h"
 #include "win32debug.h"
@@ -39,7 +41,7 @@
  , lOCALE_NEUTRAL        = LOCALE_NEUTRAL
  }
 
-foreign import stdcall unsafe "windows.h ConvertDefaultLocale"
+foreign import WINDOWS_CCONV unsafe "windows.h ConvertDefaultLocale"
   convertDefaultLocale :: LCID -> IO LCID
 
 -- ToDo: various enum functions.
@@ -52,10 +54,10 @@
  , cP_OEMCP     = CP_OEMCP
  }
 
-foreign import stdcall unsafe "windows.h GetACP"
+foreign import WINDOWS_CCONV unsafe "windows.h GetACP"
   getACP :: IO CodePage
 
-foreign import stdcall unsafe "windows.h SetThreadLocale"
+foreign import WINDOWS_CCONV unsafe "windows.h SetThreadLocale"
   setThreadLocale :: LCID -> IO ()
 
 type LCTYPE = UINT
@@ -95,7 +97,7 @@
 setLocaleInfo locale ty info =
   withTString info $ \ c_info ->
   failIfFalse_ "SetLocaleInfo" $ c_SetLocaleInfo locale ty c_info
-foreign import stdcall unsafe "windows.h SetLocaleInfoW"
+foreign import WINDOWS_CCONV unsafe "windows.h SetLocaleInfoW"
   c_SetLocaleInfo :: LCID -> LCTYPE -> LPCTSTR -> IO Bool
 
 type LCMapFlags = DWORD
@@ -127,7 +129,7 @@
   _ <- failIfZero "LCMapString" $
     c_LCMapString locale flags c_src src_len c_dest dest_size
   peekTString c_dest
-foreign import stdcall unsafe "windows.h LCMapStringW"
+foreign import WINDOWS_CCONV unsafe "windows.h LCMapStringW"
   c_LCMapString :: LCID -> LCMapFlags -> LPCTSTR -> Int -> LPCTSTR -> Int -> IO Int
 
 type LocaleTestFlags = DWORD
@@ -137,28 +139,28 @@
  , lCID_SUPPORTED       = LCID_SUPPORTED
  }
 
-foreign import stdcall unsafe "windows.h IsValidLocale"
+foreign import WINDOWS_CCONV unsafe "windows.h IsValidLocale"
   isValidLocale :: LCID -> LocaleTestFlags -> IO Bool
 
-foreign import stdcall unsafe "windows.h IsValidCodePage"
+foreign import WINDOWS_CCONV unsafe "windows.h IsValidCodePage"
   isValidCodePage :: CodePage -> IO Bool
 
-foreign import stdcall unsafe "windows.h GetUserDefaultLCID"
+foreign import WINDOWS_CCONV unsafe "windows.h GetUserDefaultLCID"
   getUserDefaultLCID :: LCID
 
-foreign import stdcall unsafe "windows.h GetUserDefaultLangID"
+foreign import WINDOWS_CCONV unsafe "windows.h GetUserDefaultLangID"
   getUserDefaultLangID :: LANGID
 
-foreign import stdcall unsafe "windows.h GetThreadLocale"
+foreign import WINDOWS_CCONV unsafe "windows.h GetThreadLocale"
   getThreadLocale :: IO LCID
 
-foreign import stdcall unsafe "windows.h GetSystemDefaultLCID"
+foreign import WINDOWS_CCONV unsafe "windows.h GetSystemDefaultLCID"
   getSystemDefaultLCID :: LCID
 
-foreign import stdcall unsafe "windows.h GetSystemDefaultLangID"
+foreign import WINDOWS_CCONV unsafe "windows.h GetSystemDefaultLangID"
   getSystemDefaultLangID :: LANGID
 
-foreign import stdcall unsafe "windows.h GetOEMCP"
+foreign import WINDOWS_CCONV unsafe "windows.h GetOEMCP"
   getOEMCP :: CodePage
 
 #{enum PrimaryLANGID,
@@ -370,7 +372,7 @@
                 cwstr wchars
       peekCWStringLen (cwstr,fromIntegral wchars)  -- converts UTF-16 to [Char]
 
-foreign import stdcall unsafe "MultiByteToWideChar"
+foreign import WINDOWS_CCONV unsafe "MultiByteToWideChar"
   multiByteToWideChar
         :: CodePage
         -> DWORD   -- dwFlags,
diff --git a/System/Win32/Process.hsc b/System/Win32/Process.hsc
--- a/System/Win32/Process.hsc
+++ b/System/Win32/Process.hsc
@@ -23,6 +23,8 @@
 import System.Win32.File    ( closeHandle )
 import System.Win32.Types
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 #include <tlhelp32.h>
 
@@ -30,7 +32,7 @@
 iNFINITE :: DWORD
 iNFINITE = #{const INFINITE}
 
-foreign import stdcall unsafe "windows.h Sleep"
+foreign import WINDOWS_CCONV unsafe "windows.h Sleep"
   sleep :: DWORD -> IO ()
 
 
@@ -52,14 +54,14 @@
     , sYNCHORNIZE                   = SYNCHRONIZE 
     }
 
-foreign import stdcall unsafe "windows.h OpenProcess"
+foreign import WINDOWS_CCONV unsafe "windows.h OpenProcess"
     c_OpenProcess :: ProcessAccessRights -> BOOL -> ProcessId -> IO ProcessHandle
 
 
 openProcess :: ProcessAccessRights -> BOOL -> ProcessId -> IO ProcessHandle
 openProcess r inh i = failIfNull "OpenProcess" $ c_OpenProcess r inh i
 
-foreign import stdcall unsafe "windows.h GetProcessId"
+foreign import WINDOWS_CCONV unsafe "windows.h GetProcessId"
     c_GetProcessId :: ProcessHandle -> IO ProcessId
 
 getProcessId :: ProcessHandle -> IO ProcessId
@@ -82,13 +84,13 @@
     , tH32CS_SNAPNOHEAPS    = TH32CS_SNAPNOHEAPS 
 -}
 
-foreign import stdcall unsafe "tlhelp32.h CreateToolhelp32Snapshot"
+foreign import WINDOWS_CCONV unsafe "tlhelp32.h CreateToolhelp32Snapshot"
     c_CreateToolhelp32Snapshot :: Th32SnapFlags -> ProcessId -> IO Th32SnapHandle
 
-foreign import stdcall unsafe "tlhelp32.h Process32FirstW"
+foreign import WINDOWS_CCONV unsafe "tlhelp32.h Process32FirstW"
     c_Process32First :: Th32SnapHandle -> Ptr ProcessEntry32 -> IO BOOL
 
-foreign import stdcall unsafe "tlhelp32.h Process32NextW"
+foreign import WINDOWS_CCONV unsafe "tlhelp32.h Process32NextW"
     c_Process32Next :: Th32SnapHandle -> Ptr ProcessEntry32 -> IO BOOL
 
 -- | Create a snapshot of specified resources.  Call closeHandle to close snapshot.
diff --git a/System/Win32/Registry.hsc b/System/Win32/Registry.hsc
--- a/System/Win32/Registry.hsc
+++ b/System/Win32/Registry.hsc
@@ -67,14 +67,16 @@
 import System.IO.Unsafe
 import Foreign hiding (unsafePerformIO)
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 
-#{enum HKEY, (unsafePerformIO . newForeignHANDLE . castUINTToPtr)
- , hKEY_CLASSES_ROOT    = (UINT)HKEY_CLASSES_ROOT
- , hKEY_CURRENT_CONFIG  = (UINT)HKEY_CURRENT_CONFIG
- , hKEY_CURRENT_USER    = (UINT)HKEY_CURRENT_USER
- , hKEY_LOCAL_MACHINE   = (UINT)HKEY_LOCAL_MACHINE
- , hKEY_USERS           = (UINT)HKEY_USERS
+#{enum HKEY, (unsafePerformIO . newForeignHANDLE . castUINTPtrToPtr)
+ , hKEY_CLASSES_ROOT    = (UINT_PTR)HKEY_CLASSES_ROOT
+ , hKEY_CURRENT_CONFIG  = (UINT_PTR)HKEY_CURRENT_CONFIG
+ , hKEY_CURRENT_USER    = (UINT_PTR)HKEY_CURRENT_USER
+ , hKEY_LOCAL_MACHINE   = (UINT_PTR)HKEY_LOCAL_MACHINE
+ , hKEY_USERS           = (UINT_PTR)HKEY_USERS
  }
 -- , PKEYERFORMANCE_DATA  NT only
 -- , HKEY_DYN_DATA     95/98 only
@@ -83,7 +85,7 @@
 regCloseKey key =
   withForeignPtr key $ \ p_key ->
   failUnlessSuccess "RegCloseKey" $ c_RegCloseKey p_key
-foreign import stdcall unsafe "windows.h RegCloseKey"
+foreign import WINDOWS_CCONV unsafe "windows.h RegCloseKey"
   c_RegCloseKey :: PKEY -> IO ErrCode
 
 -- Connects to a predefined registry handle on another computer.
@@ -97,7 +99,7 @@
     c_RegConnectRegistry c_machine p_key p_out_key
   p_new_key <- peek p_out_key
   newForeignHANDLE p_new_key
-foreign import stdcall unsafe "windows.h RegConnectRegistryW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegConnectRegistryW"
   c_RegConnectRegistry :: LPCTSTR -> PKEY -> Ptr PKEY -> IO ErrCode
 
 regCreateKey :: HKEY -> String -> IO HKEY
@@ -109,7 +111,7 @@
     c_RegCreateKey p_key c_subkey p_out_key
   p_new_key <- peek p_out_key
   newForeignHANDLE p_new_key
-foreign import stdcall unsafe "windows.h RegCreateKeyW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegCreateKeyW"
   c_RegCreateKey :: PKEY -> LPCTSTR -> Ptr PKEY -> IO ErrCode
 
 type RegCreateOptions = DWORD
@@ -147,7 +149,7 @@
   out_key <- newForeignHANDLE p_out_key
   disp <- peek p_disp
   return (out_key, disp == #{const REG_CREATED_NEW_KEY})
-foreign import stdcall unsafe "windows.h RegCreateKeyExW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegCreateKeyExW"
   c_RegCreateKeyEx :: PKEY -> LPCTSTR -> DWORD -> LPCTSTR -> RegCreateOptions -> REGSAM -> LPSECURITY_ATTRIBUTES -> Ptr PKEY -> Ptr DWORD -> IO ErrCode
 
 regDeleteKey :: HKEY -> String -> IO ()
@@ -155,7 +157,7 @@
   withForeignPtr key $ \ p_key ->
   withTString subkey $ \ c_subkey ->
   failUnlessSuccess "RegDeleteKey" $ c_RegDeleteKey p_key c_subkey
-foreign import stdcall unsafe "windows.h RegDeleteKeyW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegDeleteKeyW"
   c_RegDeleteKey :: PKEY -> LPCTSTR -> IO ErrCode
 
 regDeleteValue :: HKEY -> String -> IO ()
@@ -163,7 +165,7 @@
   withForeignPtr key $ \ p_key ->
   withTString name $ \ c_name ->
   failUnlessSuccess "RegDeleteValue" $ c_RegDeleteValue p_key c_name
-foreign import stdcall unsafe "windows.h RegDeleteValueW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegDeleteValueW"
   c_RegDeleteValue :: PKEY -> LPCTSTR -> IO ErrCode
 
 -- XXX Not 100% sure this is right, but I think it is.
@@ -225,7 +227,7 @@
     c_RegEnumKey p_key index c_name len
   str <- peekTString c_name
   return (str, fromEnum no_more)
-foreign import stdcall unsafe "windows.h RegEnumKeyW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegEnumKeyW"
   c_RegEnumKey :: PKEY -> DWORD -> LPTSTR -> DWORD -> IO ErrCode
 
 regEnumValue :: HKEY -> DWORD -> LPTSTR -> DWORD -> LPBYTE -> DWORD -> IO (RegValueType, String, Int)
@@ -239,7 +241,7 @@
   reg_ty <- peek p_reg_ty
   str <- peekTString name
   return (reg_ty, str, fromEnum no_more)
-foreign import stdcall unsafe "windows.h RegEnumValueW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegEnumValueW"
   c_RegEnumValue :: PKEY -> DWORD -> LPTSTR -> Ptr DWORD -> Ptr DWORD -> Ptr DWORD -> LPBYTE -> Ptr DWORD -> IO ErrCode
 
 eRROR_NO_MORE_ITEMS :: ErrCode
@@ -249,7 +251,7 @@
 regFlushKey key =
   withForeignPtr key $ \ p_key ->
   failUnlessSuccess "RegFlushKey" $ c_RegFlushKey p_key
-foreign import stdcall unsafe "windows.h RegFlushKey"
+foreign import WINDOWS_CCONV unsafe "windows.h RegFlushKey"
   c_RegFlushKey :: PKEY -> IO ErrCode
 
 -- ifdef FOR_WINDOWS_NT
@@ -263,7 +265,7 @@
   withTString subkey $ \ c_subkey ->
   withTString file $ \ c_file ->
   failUnlessSuccess "RegLoadKey" $ c_RegLoadKey p_key c_subkey c_file
-foreign import stdcall unsafe "windows.h RegLoadKeyW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegLoadKeyW"
   c_RegLoadKey :: PKEY -> LPCTSTR -> LPCTSTR -> IO ErrCode
 
 -- ifdef FOR_WINDOWS_NT
@@ -282,7 +284,7 @@
   withForeignPtr key $ \ p_key ->
   failUnlessSuccess "RegNotifyChangeKeyValue" $
     c_RegNotifyChangeKeyValue p_key watch notifyFilter event async
-foreign import stdcall unsafe "windows.h RegNotifyChangeKeyValue"
+foreign import WINDOWS_CCONV unsafe "windows.h RegNotifyChangeKeyValue"
   c_RegNotifyChangeKeyValue :: PKEY -> Bool -> RegNotifyOptions -> HANDLE -> Bool -> IO ErrCode
 
 -- endif
@@ -297,7 +299,7 @@
   failUnlessSuccess "RegOpenKey" $ c_RegOpenKey p_key c_subkey p_res
   p_res_key <- peek p_res
   newForeignHANDLE p_res_key
-foreign import stdcall unsafe "windows.h RegOpenKeyW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegOpenKeyW"
   c_RegOpenKey :: PKEY -> LPCTSTR -> Ptr PKEY -> IO ErrCode
 
 regOpenKeyEx :: HKEY -> String -> REGSAM -> IO HKEY
@@ -308,7 +310,7 @@
   failUnlessSuccess "RegOpenKeyEx" $ c_RegOpenKeyEx p_key c_subkey 0 sam p_res
   p_res_key <- peek p_res
   newForeignHANDLE p_res_key
-foreign import stdcall unsafe "windows.h RegOpenKeyExW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegOpenKeyExW"
   c_RegOpenKeyEx :: PKEY -> LPCTSTR -> DWORD -> REGSAM -> Ptr PKEY -> IO ErrCode
 
 data RegInfoKey =
@@ -367,7 +369,7 @@
     , lastWrite_lo = lastWrite_lo
     , lastWrite_hi = lastWrite_hi
     }
-foreign import stdcall unsafe "windows.h RegQueryInfoKeyW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegQueryInfoKeyW"
   c_RegQueryInfoKey :: PKEY -> LPTSTR -> Ptr DWORD -> Ptr DWORD -> Ptr DWORD -> Ptr DWORD -> Ptr DWORD -> Ptr DWORD -> Ptr DWORD -> Ptr DWORD -> Ptr DWORD -> Ptr FILETIME -> IO ErrCode
 
 -- RegQueryMultipleValues :: HKEY -> IO ([VALENT],String)
@@ -389,7 +391,7 @@
     failUnlessSuccess "RegQueryValue" $
       c_RegQueryValue p_key c_subkey c_value p_value_len
     peekTString c_value
-foreign import stdcall unsafe "windows.h RegQueryValueW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegQueryValueW"
   c_RegQueryValue :: PKEY -> LPCTSTR -> LPTSTR -> Ptr LONG -> IO ErrCode
 
 regQueryValue :: HKEY -> Maybe String -> IO String
@@ -417,7 +419,7 @@
   failUnlessSuccess "RegQueryValueEx" $
     c_RegQueryValueEx p_key c_name nullPtr p_ty value p_value_len
   peek p_ty
-foreign import stdcall unsafe "windows.h RegQueryValueExW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegQueryValueExW"
   c_RegQueryValueEx :: PKEY -> LPCTSTR -> Ptr DWORD -> Ptr DWORD -> LPBYTE -> Ptr DWORD -> IO ErrCode
 
 regReplaceKey :: HKEY -> String -> String -> String -> IO ()
@@ -428,7 +430,7 @@
   withTString oldfile $ \ c_oldfile ->
   failUnlessSuccess "RegReplaceKey" $
     c_RegReplaceKey p_key c_subkey c_newfile c_oldfile
-foreign import stdcall unsafe "windows.h RegReplaceKeyW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegReplaceKeyW"
   c_RegReplaceKey :: PKEY -> LPCTSTR -> LPCTSTR -> LPCTSTR -> IO ErrCode
 
 type RegRestoreFlags = DWORD
@@ -444,7 +446,7 @@
   withForeignPtr key $ \ p_key ->
   withTString file $ \ c_file ->
   failUnlessSuccess "RegRestoreKey" $ c_RegRestoreKey p_key c_file flags
-foreign import stdcall unsafe "windows.h RegRestoreKeyW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegRestoreKeyW"
   c_RegRestoreKey :: PKEY -> LPCTSTR -> RegRestoreFlags -> IO ErrCode
 
 regSaveKey :: HKEY -> String -> Maybe LPSECURITY_ATTRIBUTES -> IO ()
@@ -452,7 +454,7 @@
   withForeignPtr key $ \ p_key ->
   withTString file $ \ c_file ->
   failUnlessSuccess "RegSaveKey" $ c_RegSaveKey p_key c_file (maybePtr mb_attr)
-foreign import stdcall unsafe "windows.h RegSaveKeyW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegSaveKeyW"
   c_RegSaveKey :: PKEY -> LPCTSTR -> LPSECURITY_ATTRIBUTES -> IO ErrCode
 
 -- ifdef FOR_WINDOWS_NT
@@ -470,7 +472,7 @@
   withTStringLen value $ \ (c_value, value_len) ->
   failUnlessSuccess "RegSetValue" $
     c_RegSetValue p_key c_subkey rEG_SZ c_value value_len
-foreign import stdcall unsafe "windows.h RegSetValueW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegSetValueW"
   c_RegSetValue :: PKEY -> LPCTSTR -> DWORD -> LPCTSTR -> Int -> IO ErrCode
 
 
@@ -503,7 +505,7 @@
   withTString subkey $ \ c_subkey ->
   failUnlessSuccess "RegSetValueEx" $
     c_RegSetValueEx p_key c_subkey 0 ty value value_len
-foreign import stdcall unsafe "windows.h RegSetValueExW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegSetValueExW"
   c_RegSetValueEx :: PKEY -> LPCTSTR -> DWORD -> RegValueType -> LPTSTR -> Int -> IO ErrCode
 
 regUnLoadKey :: HKEY -> String -> IO ()
@@ -511,5 +513,5 @@
   withForeignPtr key $ \ p_key ->
   withTString subkey $ \ c_subkey ->
   failUnlessSuccess "RegUnLoadKey" $ c_RegUnLoadKey p_key c_subkey
-foreign import stdcall unsafe "windows.h RegUnLoadKeyW"
+foreign import WINDOWS_CCONV unsafe "windows.h RegUnLoadKeyW"
   c_RegUnLoadKey :: PKEY -> LPCTSTR -> IO ErrCode
diff --git a/System/Win32/Security.hsc b/System/Win32/Security.hsc
--- a/System/Win32/Security.hsc
+++ b/System/Win32/Security.hsc
@@ -57,6 +57,8 @@
 -- import Foreign.C
 import System.Win32.Types
 
+##include "windows_cconv.h"
+
 #include <windows.h>
 
 -- --------------------------------------------------------------------------
@@ -89,14 +91,14 @@
 newtype SID = SID SID
 type PSID = Ptr SID
 
-foreign import stdcall unsafe "windows.h GetSecurityDescriptorControl"
+foreign import WINDOWS_CCONV unsafe "windows.h GetSecurityDescriptorControl"
   c_getSecurityDescriptorControl
     :: PSECURITY_DESCRIPTOR -- pSecurityDescriptor
     -> Ptr SECURITY_DESCRIPTOR_CONTROL -- pControl
     -> LPDWORD -- lpdwRevision
     -> IO BOOL 
 
-foreign import stdcall unsafe "windows.h GetSecurityDescriptorDacl"
+foreign import WINDOWS_CCONV unsafe "windows.h GetSecurityDescriptorDacl"
   c_getSecurityDescriptorDacl 
     :: PSECURITY_DESCRIPTOR -- pSecurityDescriptor
     -> LPBOOL -- lpbDaclPresent
@@ -104,26 +106,26 @@
     -> LPBOOL -- lpbDaclDefaulted
     -> IO BOOL 
 
-foreign import stdcall unsafe "windows.h GetSecurityDescriptorGroup"
+foreign import WINDOWS_CCONV unsafe "windows.h GetSecurityDescriptorGroup"
   c_getSecurityDescriptorGroup
     :: PSECURITY_DESCRIPTOR -- pSecurityDescriptor
     -> Ptr PSID -- pGroup
     -> LPBOOL -- lpbGroupDefaulted
     -> IO BOOL 
 
-foreign import stdcall unsafe "windows.h GetSecurityDescriptorLength"
+foreign import WINDOWS_CCONV unsafe "windows.h GetSecurityDescriptorLength"
   c_getSecurityDescriptorLength
     :: PSECURITY_DESCRIPTOR -- pSecurityDescriptor
     -> IO DWORD 
 
-foreign import stdcall unsafe "windows.h GetSecurityDescriptorOwner"
+foreign import WINDOWS_CCONV unsafe "windows.h GetSecurityDescriptorOwner"
   c_getSecurityDescriptorOwner
     :: PSECURITY_DESCRIPTOR -- pSecurityDescriptor
     -> Ptr PSID -- pOwner
     -> LPBOOL -- lpbOwnerDefaulted
     -> IO BOOL 
 
-foreign import stdcall unsafe "windows.h GetSecurityDescriptorSacl"
+foreign import WINDOWS_CCONV unsafe "windows.h GetSecurityDescriptorSacl"
   c_getSecurityDescriptorSacl
     :: PSECURITY_DESCRIPTOR -- pSecurityDescriptor
     -> LPBOOL -- lpbSaclPresent
@@ -131,18 +133,18 @@
     -> LPBOOL -- lpbSaclDefaulted
     -> IO BOOL 
 
-foreign import stdcall unsafe "windows.h InitializeSecurityDescriptor"
+foreign import WINDOWS_CCONV unsafe "windows.h InitializeSecurityDescriptor"
   c_initializeSecurityDescriptor
     :: PSECURITY_DESCRIPTOR -- pSecurityDescriptor
     -> DWORD -- dwRevision
     -> IO BOOL 
 
-foreign import stdcall unsafe "windows.h IsValidSecurityDescriptor"
+foreign import WINDOWS_CCONV unsafe "windows.h IsValidSecurityDescriptor"
   c_isValidSecurityDescriptor
     :: PSECURITY_DESCRIPTOR -- pSecurityDescriptor
     -> IO BOOL 
 
-foreign import stdcall unsafe "windows.h SetSecurityDescriptorDacl"
+foreign import WINDOWS_CCONV unsafe "windows.h SetSecurityDescriptorDacl"
   c_setSecurityDescriptorDacl
     :: PSECURITY_DESCRIPTOR -- pSecurityDescriptor
     -> BOOL -- bDaclPresent
@@ -150,21 +152,21 @@
     -> BOOL -- bDaclDefaulted
     -> IO BOOL 
 
-foreign import stdcall unsafe "windows.h SetSecurityDescriptorGroup"
+foreign import WINDOWS_CCONV unsafe "windows.h SetSecurityDescriptorGroup"
   c_setSecurityDescriptorGroup
     :: PSECURITY_DESCRIPTOR -- pSecurityDescriptor
     -> PSID -- pGroup
     -> BOOL -- bGroupDefaulted
     -> IO BOOL 
 
-foreign import stdcall unsafe "windows.h SetSecurityDescriptorOwner"
+foreign import WINDOWS_CCONV unsafe "windows.h SetSecurityDescriptorOwner"
   c_setSecurityDescriptorOwner
     :: PSECURITY_DESCRIPTOR -- pSecurityDescriptor
     -> PSID -- pOwner
     -> BOOL -- bOwnerDefaulted
     -> IO BOOL 
 
-foreign import stdcall unsafe "windows.h SetSecurityDescriptorSacl"
+foreign import WINDOWS_CCONV unsafe "windows.h SetSecurityDescriptorSacl"
   c_setSecurityDescriptorSacl
     :: PSECURITY_DESCRIPTOR -- pSecurityDescriptor
     -> BOOL -- bSaclPresent
@@ -205,7 +207,7 @@
     c_GetFileSecurity lpFileName si pSd needed lpnLengthNeeded
   return (SecurityDescriptor fpSd)
 
-foreign import stdcall unsafe "windows.h GetFileSecurityW"
+foreign import WINDOWS_CCONV unsafe "windows.h GetFileSecurityW"
   c_GetFileSecurity
     :: LPCWSTR -- lpFileName
     -> SECURITY_INFORMATION -- RequestedInformation
@@ -214,7 +216,7 @@
     -> LPDWORD -- lpnLengthNeeded
     -> IO BOOL 
 
---foreign import stdcall unsafe "windows.h AccessCheck"
+--foreign import WINDOWS_CCONV unsafe "windows.h AccessCheck"
 --  c_AccessCheck
 --    :: PSECURITY_DESCRIPTOR -- pSecurityDescriptor
 --    -> HANDLE -- ClientToken
@@ -226,7 +228,7 @@
 --    -> LPBOOL -- AccessStatus
 --    -> IO BOOL
 
--- foreign import stdcall unsafe "windows.h OpenThreadToken"
+-- foreign import WINDOWS_CCONV unsafe "windows.h OpenThreadToken"
 --    OpenThreadToken
 --      :: HANDLE -- ThreadHandle
 --      -> DWORD -- DesiredAccess
diff --git a/System/Win32/Shell.hsc b/System/Win32/Shell.hsc
--- a/System/Win32/Shell.hsc
+++ b/System/Win32/Shell.hsc
@@ -36,6 +36,8 @@
 import Control.Monad
 import System.IO.Error
 
+##include "windows_cconv.h"
+
 -- for SHGetFolderPath stuff
 #define _WIN32_IE 0x500
 #include <windows.h>
@@ -76,6 +78,6 @@
 raiseUnsupported loc = 
    ioError (ioeSetErrorString (mkIOError illegalOperationErrorType loc Nothing Nothing) "unsupported operation")
 
-foreign import stdcall unsafe "SHGetFolderPathW"
+foreign import WINDOWS_CCONV unsafe "SHGetFolderPathW"
   c_SHGetFolderPath :: HWND -> CInt -> HANDLE -> DWORD -> LPTSTR
                     -> IO HRESULT
diff --git a/System/Win32/SimpleMAPI.hsc b/System/Win32/SimpleMAPI.hsc
--- a/System/Win32/SimpleMAPI.hsc
+++ b/System/Win32/SimpleMAPI.hsc
@@ -16,6 +16,14 @@
 -----------------------------------------------------------------------------
 module System.Win32.SimpleMAPI
 where
+
+-- I am not sure why exactly, but with mingw64 mapi.h does not define
+-- some of the values we use, e.g. MAPI_LOGOFF_SHARED.
+-- mapix.h does define MAPI_LOGOFF_SHARED, but the various flags
+-- clash with each other.
+-- So for now we only define the module content on i386.
+#if __i386__
+
 import Control.Exception    ( bracket, handle, finally, onException
                             , IOException )
 import Control.Monad        ( liftM5 )
@@ -31,6 +39,8 @@
                             , c_FreeLibraryFinaliser )
 import System.Win32.Types   ( DWORD, LPSTR, HMODULE, failIfNull )
 
+##include "windows_cconv.h"
+
 #include "windows.h"
 #include "mapi.h"
 
@@ -109,21 +119,21 @@
 mapiFail_ n a = mapiFail n a >> return ()
 
 type MapiLogonType = ULONG -> LPSTR -> LPSTR -> MapiFlag -> ULONG -> Ptr LHANDLE -> IO ULONG
-foreign import stdcall "dynamic" mkMapiLogon :: FunPtr MapiLogonType -> MapiLogonType
+foreign import WINDOWS_CCONV "dynamic" mkMapiLogon :: FunPtr MapiLogonType -> MapiLogonType
 
 type MapiLogoffType = LHANDLE -> ULONG -> MapiFlag -> ULONG -> IO ULONG
-foreign import stdcall "dynamic" mkMapiLogoff :: FunPtr MapiLogoffType -> MapiLogoffType
+foreign import WINDOWS_CCONV "dynamic" mkMapiLogoff :: FunPtr MapiLogoffType -> MapiLogoffType
 
 type MapiResolveNameType =
     LHANDLE -> ULONG -> LPSTR -> MapiFlag -> ULONG
     -> Ptr (Ptr MapiRecipDesc) -> IO ULONG
-foreign import stdcall "dynamic" mkMapiResolveName :: FunPtr MapiResolveNameType -> MapiResolveNameType
+foreign import WINDOWS_CCONV "dynamic" mkMapiResolveName :: FunPtr MapiResolveNameType -> MapiResolveNameType
 
 type MapiFreeBufferType = Ptr () -> IO ULONG
-foreign import stdcall "dynamic" mkMapiFreeBuffer :: FunPtr MapiFreeBufferType -> MapiFreeBufferType
+foreign import WINDOWS_CCONV "dynamic" mkMapiFreeBuffer :: FunPtr MapiFreeBufferType -> MapiFreeBufferType
 
 type MapiSendMailType = LHANDLE -> ULONG -> Ptr Message -> MapiFlag -> ULONG -> IO ULONG
-foreign import stdcall "dynamic" mkMapiSendMail :: FunPtr MapiSendMailType -> MapiSendMailType
+foreign import WINDOWS_CCONV "dynamic" mkMapiSendMail :: FunPtr MapiSendMailType -> MapiSendMailType
 
 data MapiFuncs = MapiFuncs
     { mapifLogon    :: MapiLogonType
@@ -398,3 +408,4 @@
 handleIOException :: (IOException -> IO a) -> IO a -> IO a
 handleIOException = handle
 
+#endif
diff --git a/System/Win32/Time.hsc b/System/Win32/Time.hsc
--- a/System/Win32/Time.hsc
+++ b/System/Win32/Time.hsc
@@ -29,6 +29,8 @@
 import Foreign.C        ( CInt(..), CWchar(..)
                         , peekCWString, withCWStringLen, withCWString )
 
+##include "windows_cconv.h"
+
 #include "windows.h"
 
 ----------------------------------------------------------------
@@ -121,40 +123,40 @@
         dnam <- peekCWString (plusPtr buf (#offset TIME_ZONE_INFORMATION, DaylightName))
         return $ TIME_ZONE_INFORMATION bias snam sdat sbia dnam ddat dbia
 
-foreign import stdcall "windows.h GetSystemTime"
+foreign import WINDOWS_CCONV "windows.h GetSystemTime"
     c_GetSystemTime :: Ptr SYSTEMTIME -> IO ()
 getSystemTime :: IO SYSTEMTIME
 getSystemTime = alloca $ \res -> do
     c_GetSystemTime res
     peek res
 
-foreign import stdcall "windows.h SetSystemTime"
+foreign import WINDOWS_CCONV "windows.h SetSystemTime"
     c_SetSystemTime :: Ptr SYSTEMTIME -> IO BOOL
 setSystemTime :: SYSTEMTIME -> IO ()
 setSystemTime st = with st $ \st -> failIf_ not "setSystemTime: SetSystemTime" $
     c_SetSystemTime st
 
-foreign import stdcall "windows.h GetSystemTimeAsFileTime"
+foreign import WINDOWS_CCONV "windows.h GetSystemTimeAsFileTime"
     c_GetSystemTimeAsFileTime :: Ptr FILETIME -> IO ()
 getSystemTimeAsFileTime :: IO FILETIME
 getSystemTimeAsFileTime = alloca $ \ret -> do
     c_GetSystemTimeAsFileTime ret
     peek ret
 
-foreign import stdcall "windows.h GetLocalTime"
+foreign import WINDOWS_CCONV "windows.h GetLocalTime"
     c_GetLocalTime :: Ptr SYSTEMTIME -> IO ()
 getLocalTime :: IO SYSTEMTIME
 getLocalTime = alloca $ \res -> do
     c_GetLocalTime res
     peek res
 
-foreign import stdcall "windows.h SetLocalTime"
+foreign import WINDOWS_CCONV "windows.h SetLocalTime"
     c_SetLocalTime :: Ptr SYSTEMTIME -> IO BOOL
 setLocalTime :: SYSTEMTIME -> IO ()
 setLocalTime st = with st $ \st -> failIf_ not "setLocalTime: SetLocalTime" $
     c_SetLocalTime st
 
-foreign import stdcall "windows.h GetSystemTimeAdjustment"
+foreign import WINDOWS_CCONV "windows.h GetSystemTimeAdjustment"
     c_GetSystemTimeAdjustment :: Ptr DWORD -> Ptr DWORD -> Ptr BOOL -> IO BOOL
 getSystemTimeAdjustment :: IO (Maybe (Int, Int))
 getSystemTimeAdjustment = alloca $ \ta -> alloca $ \ti -> alloca $ \enabled -> do
@@ -168,9 +170,9 @@
             return $ Just (fromIntegral ta, fromIntegral ti)
         else return Nothing
 
-foreign import stdcall "windows.h GetTickCount" getTickCount :: IO DWORD
+foreign import WINDOWS_CCONV "windows.h GetTickCount" getTickCount :: IO DWORD
 
-foreign import stdcall "windows.h SetSystemTimeAdjustment"
+foreign import WINDOWS_CCONV "windows.h SetSystemTimeAdjustment"
     c_SetSystemTimeAdjustment :: DWORD -> BOOL -> IO BOOL
 setSystemTimeAdjustment :: Maybe Int -> IO ()
 setSystemTimeAdjustment ta =
@@ -181,7 +183,7 @@
             Nothing -> (0,True)
             Just x  -> (fromIntegral x,False)
 
-foreign import stdcall "windows.h GetTimeZoneInformation"
+foreign import WINDOWS_CCONV "windows.h GetTimeZoneInformation"
     c_GetTimeZoneInformation :: Ptr TIME_ZONE_INFORMATION -> IO DWORD
 getTimeZoneInformation :: IO (TimeZoneId, TIME_ZONE_INFORMATION)
 getTimeZoneInformation = alloca $ \tzi -> do
@@ -194,7 +196,7 @@
         (#const TIME_ZONE_ID_DAYLIGHT)  -> TzIdDaylight
         _                               -> TzIdUnknown   -- to remove warning
 
-foreign import stdcall "windows.h SystemTimeToFileTime"
+foreign import WINDOWS_CCONV "windows.h SystemTimeToFileTime"
     c_SystemTimeToFileTime :: Ptr SYSTEMTIME -> Ptr FILETIME -> IO BOOL
 systemTimeToFileTime :: SYSTEMTIME -> IO FILETIME
 systemTimeToFileTime s = with s $ \s -> alloca $ \ret -> do
@@ -202,7 +204,7 @@
         c_SystemTimeToFileTime s ret
     peek ret
 
-foreign import stdcall "windows.h FileTimeToSystemTime"
+foreign import WINDOWS_CCONV "windows.h FileTimeToSystemTime"
     c_FileTimeToSystemTime :: Ptr FILETIME -> Ptr SYSTEMTIME -> IO BOOL
 fileTimeToSystemTime :: FILETIME -> IO SYSTEMTIME
 fileTimeToSystemTime s = with s $ \s -> alloca $ \ret -> do
@@ -210,20 +212,20 @@
         c_FileTimeToSystemTime s ret
     peek ret
 
-foreign import stdcall "windows.h GetFileTime"
+foreign import WINDOWS_CCONV "windows.h GetFileTime"
     c_GetFileTime :: HANDLE -> Ptr FILETIME -> Ptr FILETIME -> Ptr FILETIME -> IO BOOL
 getFileTime :: HANDLE -> IO (FILETIME,FILETIME,FILETIME)
 getFileTime h = alloca $ \crt -> alloca $ \acc -> alloca $ \wrt -> do
     failIf_ not "getFileTime: GetFileTime" $ c_GetFileTime h crt acc wrt
     liftM3 (,,) (peek crt) (peek acc) (peek wrt)
 
-foreign import stdcall "windows.h SetFileTime"
+foreign import WINDOWS_CCONV "windows.h SetFileTime"
     c_SetFileTime :: HANDLE -> Ptr FILETIME -> Ptr FILETIME -> Ptr FILETIME -> IO BOOL
 setFileTime :: HANDLE -> FILETIME -> FILETIME -> FILETIME -> IO ()
 setFileTime h crt acc wrt = with crt $ \crt -> with acc $ \acc -> with wrt $ \wrt -> do
     failIf_ not "setFileTime: SetFileTime" $ c_SetFileTime h crt acc wrt
 
-foreign import stdcall "windows.h FileTimeToLocalFileTime"
+foreign import WINDOWS_CCONV "windows.h FileTimeToLocalFileTime"
     c_FileTimeToLocalFileTime :: Ptr FILETIME -> Ptr FILETIME -> IO BOOL
 fileTimeToLocalFileTime :: FILETIME -> IO FILETIME
 fileTimeToLocalFileTime ft = with ft $ \ft -> alloca $ \res -> do
@@ -231,7 +233,7 @@
         $ c_FileTimeToLocalFileTime ft res
     peek res
 
-foreign import stdcall "windows.h LocalFileTimeToFileTime"
+foreign import WINDOWS_CCONV "windows.h LocalFileTimeToFileTime"
     c_LocalFileTimeToFileTime :: Ptr FILETIME -> Ptr FILETIME -> IO BOOL
 localFileTimeToFileTime :: FILETIME -> IO FILETIME
 localFileTimeToFileTime ft = with ft $ \ft -> alloca $ \res -> do
@@ -241,7 +243,7 @@
 
 {-
 -- Windows XP SP1
-foreign import stdcall "windows.h GetSystemTimes"
+foreign import WINDOWS_CCONV "windows.h GetSystemTimes"
     c_GetSystemTimes :: Ptr FILETIME -> Ptr FILETIME -> Ptr FILETIME -> IO BOOL
 getSystemTimes :: IO (FILETIME,FILETIME,FILETIME)
 getSystemTimes = alloca $ \idle -> alloca $ \kernel -> alloca $ \user -> do
@@ -251,7 +253,7 @@
 
 {-
 -- Windows XP
-foreign import stdcall "windows.h SystemTimeToTzSpecificLocalTime"
+foreign import WINDOWS_CCONV "windows.h SystemTimeToTzSpecificLocalTime"
     c_SystemTimeToTzSpecificLocalTime :: Ptr TIME_ZONE_INFORMATION -> Ptr SYSTEMTIME -> Ptr SYSTEMTIME -> IO BOOL
 systemTimeToTzSpecificLocalTime :: TIME_ZONE_INFORMATION -> SYSTEMTIME -> IO SYSTEMTIME
 systemTimeToTzSpecificLocalTime tzi st = with tzi $ \tzi -> with st $ \st -> alloca $ \res -> do
@@ -259,7 +261,7 @@
         c_SystemTimeToTzSpecificLocalTime tzi st res
     peek res
 
-foreign import stdcall "windows.h TzSpecificLocalTimeToSystemTime"
+foreign import WINDOWS_CCONV "windows.h TzSpecificLocalTimeToSystemTime"
     c_TzSpecificLocalTimeToSystemTime :: Ptr TIME_ZONE_INFORMATION -> Ptr SYSTEMTIME -> Ptr SYSTEMTIME -> IO BOOL
 tzSpecificLocalTimeToSystemTime :: TIME_ZONE_INFORMATION -> SYSTEMTIME -> IO SYSTEMTIME
 tzSpecificLocalTimeToSystemTime tzi st = with tzi $ \tzi -> with st $ \st -> alloca $ \res -> do
@@ -268,7 +270,7 @@
     peek res
 -}
 
-foreign import stdcall "windows.h QueryPerformanceFrequency"
+foreign import WINDOWS_CCONV "windows.h QueryPerformanceFrequency"
     c_QueryPerformanceFrequency :: Ptr LARGE_INTEGER -> IO BOOL
 queryPerformanceFrequency :: IO Integer
 queryPerformanceFrequency = alloca $ \res -> do
@@ -276,7 +278,7 @@
         c_QueryPerformanceFrequency res
     liftM fromIntegral $ peek res
 
-foreign import stdcall "windows.h QueryPerformanceCounter"
+foreign import WINDOWS_CCONV "windows.h QueryPerformanceCounter"
     c_QueryPerformanceCounter:: Ptr LARGE_INTEGER -> IO BOOL
 queryPerformanceCounter:: IO Integer
 queryPerformanceCounter= alloca $ \res -> do
@@ -294,7 +296,7 @@
     , tIME_FORCE24HOURFORMAT= TIME_FORCE24HOURFORMAT
     }
 
-foreign import stdcall "windows.h GetTimeFormatW"
+foreign import WINDOWS_CCONV "windows.h GetTimeFormatW"
     c_GetTimeFormat :: LCID -> GetTimeFormatFlags -> Ptr SYSTEMTIME -> LPCTSTR -> LPTSTR -> CInt -> IO CInt
 getTimeFormat :: LCID -> GetTimeFormatFlags -> SYSTEMTIME -> String -> IO String
 getTimeFormat locale flags st fmt =
diff --git a/System/Win32/Types.hs b/System/Win32/Types.hs
--- a/System/Win32/Types.hs
+++ b/System/Win32/Types.hs
@@ -29,6 +29,8 @@
 import Data.Char
 import Numeric (showHex)
 
+#include "windows_cconv.h"
+
 ----------------------------------------------------------------
 -- Platform specific definitions
 --
@@ -49,6 +51,8 @@
 type FLOAT         = Float
 type LARGE_INTEGER = Int64
 
+type UINT_PTR      = Word
+
 -- Not really a basic type, but used in many places
 type DDWORD        = Word64
 
@@ -141,8 +145,8 @@
 newForeignHANDLE :: HANDLE -> IO ForeignHANDLE
 newForeignHANDLE = newForeignPtr deleteObjectFinaliser
 
-handleToWord :: HANDLE -> UINT
-handleToWord = castPtrToUINT
+handleToWord :: HANDLE -> UINT_PTR
+handleToWord = castPtrToUINTPtr
 
 type   HKEY        = ForeignHANDLE
 type   PKEY        = HANDLE
@@ -162,7 +166,7 @@
 nullFinalHANDLE = unsafePerformIO (newForeignPtr_ nullPtr)
 
 iNVALID_HANDLE_VALUE :: HANDLE
-iNVALID_HANDLE_VALUE = castUINTToPtr 0xffffffff
+iNVALID_HANDLE_VALUE = castUINTPtrToPtr (-1)
 
 ----------------------------------------------------------------
 -- Errors
@@ -248,10 +252,10 @@
 foreign import ccall "HsWin32.h &DeleteObjectFinaliser"
   deleteObjectFinaliser :: FunPtr (Ptr a -> IO ())
 
-foreign import stdcall unsafe "windows.h LocalFree"
+foreign import WINDOWS_CCONV unsafe "windows.h LocalFree"
   localFree :: Ptr a -> IO (Ptr a)
 
-foreign import stdcall unsafe "windows.h GetLastError"
+foreign import WINDOWS_CCONV unsafe "windows.h GetLastError"
   getLastError :: IO ErrCode
 
 {-# CFILES cbits/errors.c #-}
@@ -268,13 +272,10 @@
   hIWORD :: DWORD -> WORD
 
 foreign import ccall unsafe "HsWin32.h"
-  castUINTToPtr :: UINT -> Ptr a
-
-foreign import ccall unsafe "HsWin32.h"
-  castPtrToUINT :: Ptr s -> UINT
+  castUINTPtrToPtr :: UINT_PTR -> Ptr a
 
 foreign import ccall unsafe "HsWin32.h"
-  castFunPtrToLONG :: FunPtr a -> LONG
+  castPtrToUINTPtr :: Ptr s -> UINT_PTR
 
 type LCID = DWORD
 
diff --git a/Win32.cabal b/Win32.cabal
--- a/Win32.cabal
+++ b/Win32.cabal
@@ -1,5 +1,5 @@
 name:		Win32
-version:	2.2.2.0
+version:	2.3.0.0
 license:	BSD3
 license-file:	LICENSE
 author:		Alastair Reid
@@ -14,7 +14,7 @@
 cabal-version:  >=1.6
 extra-source-files:
 	include/diatemp.h include/dumpBMP.h include/ellipse.h include/errors.h
-	include/gettime.h include/Win32Aux.h include/win32debug.h
+	include/Win32Aux.h include/win32debug.h include/windows_cconv.h
 
 Library
     build-depends:	base >= 3 && < 5, bytestring
diff --git a/cbits/WndProc.c b/cbits/WndProc.c
--- a/cbits/WndProc.c
+++ b/cbits/WndProc.c
@@ -71,7 +71,7 @@
     LRESULT lr;
 
     if (hwnd) {
-	LONG wndprocptr = GetWindowLong(hwnd,GWL_USERDATA);
+	LONG_PTR wndprocptr = GetWindowLongPtr(hwnd,GWLP_USERDATA);
 	if (wndprocptr) {
 	    lr = ((LRESULT (*)(HWND,UINT,WPARAM,LPARAM))(wndprocptr))(hwnd,msg,wParam,lParam);
 #if 0
diff --git a/cbits/dumpBMP.c b/cbits/dumpBMP.c
--- a/cbits/dumpBMP.c
+++ b/cbits/dumpBMP.c
@@ -38,7 +38,6 @@
 {
     HANDLE      hFile;
     HBITMAP     hTmpBmp, hBmpOld;
-    BOOL        bSuccess;
     BITMAPFILEHEADER    bfh;
     LPBITMAPINFO pbmi;
     PBYTE       pBits;
@@ -48,7 +47,6 @@
 	DWORD 		dwBytesWritten;
 
 
-    bSuccess = TRUE;
 #if 0
     if (ghPal) {
         SelectPalette(hDC, ghPal, FALSE);
@@ -112,7 +110,6 @@
         //
         if ((pbmi = (LPBITMAPINFO)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizBMI )) == NULL) {
             fprintf(stderr, "Failed in Memory Allocation for pbmi!");
-            bSuccess = FALSE;
             goto ErrExit1;
         }
         //
@@ -153,7 +150,6 @@
     //
     if (WriteFile(hFile, (LPCVOID)&bfh, sizeof(BITMAPFILEHEADER), &dwBytesWritten, NULL) == -1) {
         fprintf(stderr, "Failed in WriteFile!");
-        bSuccess = FALSE;
         goto ErrExit3;
     }
 
@@ -167,12 +163,10 @@
         hBmpOld = SelectObject(hDC, hTmpBmp);
         if ((GetDIBits(hDC, hBmp, 0, pbmi->bmiHeader.biHeight, (LPSTR)pBits, pbmi, DIB_RGB_COLORS))==0){
             fprintf(stderr, "Failed in GetDIBits!");
-            bSuccess = FALSE;
             goto ErrExit4;
         }
     } else {
         fprintf(stderr, "Failed in creating bitmap!");
-        bSuccess = FALSE;
         goto ErrExit3;
     }
 
@@ -181,7 +175,6 @@
     //
     if (WriteFile(hFile, (LPCVOID)pbmi, sizBMI, &dwBytesWritten, NULL) == -1) {
         fprintf(stderr, "Failed in WriteFile!");
-        bSuccess = FALSE;
         goto ErrExit4;
     }
 
@@ -190,7 +183,6 @@
     //
     if (WriteFile(hFile, (LPCVOID)pBits, pbmi->bmiHeader.biSizeImage, &dwBytesWritten, NULL) == -1) {
         fprintf(stderr, "Failed in WriteFile!");
-        bSuccess = FALSE;
         goto ErrExit4;
     }
 
diff --git a/include/HsWin32.h b/include/HsWin32.h
--- a/include/HsWin32.h
+++ b/include/HsWin32.h
@@ -12,9 +12,8 @@
 # endif
 #endif
 
-INLINE UINT castPtrToUINT(void *p) { return (UINT)p; }
-INLINE void *castUINTToPtr(UINT n) { return (void *)n; }
-INLINE LONG castFunPtrToLONG(void *p) { return (LONG)p; }
+INLINE UINT_PTR castPtrToUINTPtr(void *p) { return (UINT_PTR)p; }
+INLINE void *castUINTPtrToPtr(UINT_PTR n) { return (void *)n; }
 INLINE WORD hIWORD(DWORD w) { return HIWORD(w); }
 INLINE WORD lOWORD(DWORD w) { return LOWORD(w); }
 
diff --git a/include/gettime.h b/include/gettime.h
deleted file mode 100644
--- a/include/gettime.h
+++ /dev/null
@@ -1,5 +0,0 @@
-#include <windows.h>
-
-/* Prototype missing from Cygwin B20.1 */
-
-extern DWORD WINAPI timeGetTime();
diff --git a/include/windows_cconv.h b/include/windows_cconv.h
new file mode 100644
--- /dev/null
+++ b/include/windows_cconv.h
@@ -0,0 +1,13 @@
+#ifndef __WINDOWS_CCONV_H
+#define __WINDOWS_CCONV_H
+
+#if defined(i386_HOST_ARCH)
+# define WINDOWS_CCONV stdcall
+#elif defined(x86_64_HOST_ARCH)
+# define WINDOWS_CCONV ccall
+#else
+# error Unknown mingw32 arch
+#endif
+
+#endif
+
