Index: Contrib/InstallOptions/InstallerOptions.cpp
===================================================================
--- Contrib/InstallOptions/InstallerOptions.cpp	(revision 6035)
+++ Contrib/InstallOptions/InstallerOptions.cpp	(working copy)
@@ -33,6 +33,9 @@
 #define strdup(x) STRDUP(x)
 #define stricmp(x,y) lstrcmpi(x,y)
 //#define abs(x) ((x) < 0 ? -(x) : (x))
+#ifndef min
+#define min(x, y) ((x<y)?(x):(y))
+#endif
 
 char *WINAPI STRDUP(const char *c)
 {
Index: Contrib/zip2exe/main.cpp
===================================================================
--- Contrib/zip2exe/main.cpp	(revision 6035)
+++ Contrib/zip2exe/main.cpp	(working copy)
@@ -52,7 +52,7 @@
 
 char *g_options="";//"/V3";
 
-static BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
+static INT_PTR CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
 
 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,
@@ -601,7 +601,7 @@
   }
 }
 
-BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+INT_PTR CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
   static int ids[]={IDC_INFO,IDC_NSISICON,IDC_SZIPFRAME,IDC_BROWSE,IDC_ZIPFILE,IDC_ZIPINFO_SUMMARY,IDC_ZIPINFO_FILES,IDC_OFRAME,IDC_INAMEST,
                         IDC_INSTNAME,IDC_INSTPATH,IDC_OEFST,IDC_OUTFILE,IDC_BROWSE2,IDC_COMPRESSOR,IDC_ZLIB,IDC_BZIP2,IDC_LZMA,IDC_SOLID,IDC_INTERFACE,IDC_MODERNUI,IDC_CLASSICUI};
@@ -633,7 +633,7 @@
       SetDlgItemText(hwndDlg,IDC_INSTPATH,gp_poi);
 
       hIcon=LoadIcon(g_hInstance,MAKEINTRESOURCE(IDI_ICON1));
-      SetClassLong(hwndDlg,GCL_HICON,(long)hIcon);
+      SetClassLong(hwndDlg,GCLP_HICON,(LONG_PTR)hIcon);
 
       hFont=CreateFont(15,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,
               OUT_CHARACTER_PRECIS,
Index: Contrib/MakeLangId/MakeLangId.cpp
===================================================================
--- Contrib/MakeLangId/MakeLangId.cpp	(revision 6035)
+++ Contrib/MakeLangId/MakeLangId.cpp	(working copy)
@@ -184,7 +184,7 @@
 	CBL(SUBLANG_UZBEK_CYRILLIC)
 };
 
-BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
+INT_PTR CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
 	size_t i;
 	switch (uMsg) {
 	case WM_INITDIALOG:
Index: Contrib/Makensisw/utils.cpp
===================================================================
--- Contrib/Makensisw/utils.cpp	(revision 6035)
+++ Contrib/Makensisw/utils.cpp	(working copy)
@@ -627,7 +627,7 @@
   ti.cbSize = sizeof(TOOLINFO);
   ti.uFlags = TTF_IDISHWND;
   ti.hwnd   = g_tip.tip_p;
-  ti.uId = (UINT) hWnd;
+  ti.uId = (UINT_PTR) hWnd;
   ti.lpszText = lpszToolTip;
   SendMessage(g_tip.tip, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); 
 }
@@ -651,7 +651,7 @@
   path=my_strrchr(pathf,'\\');
   if(path!=NULL) *path=0;
   lstrcat(pathf,LOCALDOCS);
-  if ((int)ShellExecute(g_sdata.hwnd,"open",pathf,NULL,NULL,SW_SHOWNORMAL)<=32) 
+  if ((INT_PTR)ShellExecute(g_sdata.hwnd,"open",pathf,NULL,NULL,SW_SHOWNORMAL)<=32) 
   ShellExecute(g_sdata.hwnd,"open",DOCPATH,NULL,NULL,SW_SHOWNORMAL);
 }
 
Index: Contrib/Makensisw/makensisw.cpp
===================================================================
--- Contrib/Makensisw/makensisw.cpp	(revision 6035)
+++ Contrib/Makensisw/makensisw.cpp	(working copy)
@@ -166,13 +166,13 @@
     GlobalFree(argv);
 }
 
-BOOL CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
+INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
   switch (msg) {
     case WM_INITDIALOG:
     {
       g_sdata.hwnd=hwndDlg;
       HICON hIcon = LoadIcon(g_sdata.hInstance,MAKEINTRESOURCE(IDI_ICON));
-      SetClassLong(hwndDlg,GCL_HICON,(long)hIcon);
+      SetClassLong(hwndDlg,GCLP_HICON,(LONG_PTR)hIcon);
       // Altered by Darren Owen (DrO) on 29/9/2003
       // Added in receiving of mouse and key events from the richedit control
       SendMessage(GetDlgItem(hwndDlg,IDC_LOGWIN),EM_SETEVENTMASK,(WPARAM)NULL,ENM_SELCHANGE|ENM_MOUSEEVENTS|ENM_KEYEVENTS);
@@ -589,7 +589,7 @@
         case IDM_EDITSCRIPT:
         {
           if (g_sdata.input_script) {
-            if ((int)ShellExecute(g_sdata.hwnd,"open",g_sdata.input_script,NULL,NULL,SW_SHOWNORMAL)<=32) {
+            if ((INT_PTR)ShellExecute(g_sdata.hwnd,"open",g_sdata.input_script,NULL,NULL,SW_SHOWNORMAL)<=32) {
               char path[MAX_PATH];
               if (GetWindowsDirectory(path,sizeof(path))) {
                 lstrcat(path,"\\notepad.exe");
Index: Contrib/Makensisw/toolbar.cpp
===================================================================
--- Contrib/Makensisw/toolbar.cpp	(revision 6035)
+++ Contrib/Makensisw/toolbar.cpp	(working copy)
@@ -74,7 +74,7 @@
     NULL );
   
   SendMessage(g_toolbar.hwnd, TB_BUTTONSTRUCTSIZE, sizeof(tbButton[0]), 0);
-  SendMessage(g_toolbar.hwnd, TB_ADDBUTTONS, BUTTONCOUNT, (LONG) &tbButton);
+  SendMessage(g_toolbar.hwnd, TB_ADDBUTTONS, BUTTONCOUNT, (LONG_PTR) &tbButton);
 
   // For Comctl32.dll version detection
   HMODULE hMod = GetModuleHandle("comctl32.dll");
@@ -105,7 +105,7 @@
     tbBitmap.hInst = g_sdata.hInstance;
     tbBitmap.nID = IDB_TOOLBAR;
   
-    SendMessage(g_toolbar.hwnd, TB_ADDBITMAP, IMAGECOUNT, (LONG) &tbBitmap);
+    SendMessage(g_toolbar.hwnd, TB_ADDBITMAP, IMAGECOUNT, (LONG_PTR) &tbBitmap);
   }
 
   HMENU toolmenu = FindSubMenu(g_sdata.menu, IDM_SCRIPT);
Index: Contrib/Makensisw/jnetlib/httpget.cpp
===================================================================
--- Contrib/Makensisw/jnetlib/httpget.cpp	(revision 6035)
+++ Contrib/Makensisw/jnetlib/httpget.cpp	(working copy)
@@ -10,7 +10,7 @@
 #include "util.h"
 #include "httpget.h"
 
-void *operator new( unsigned int num_bytes ){return GlobalAlloc(GPTR,num_bytes);}
+void *operator new( size_t num_bytes ){return GlobalAlloc(GPTR,num_bytes);}
 void operator delete( void *p ) { if (p) GlobalFree(p); }
 
 JNL_HTTPGet::JNL_HTTPGet(JNL_AsyncDNS *dns, int recvbufsize, char *proxy)
Index: Contrib/Makensisw/SConscript
===================================================================
--- Contrib/Makensisw/SConscript	(revision 6035)
+++ Contrib/Makensisw/SConscript	(working copy)
@@ -36,7 +36,7 @@
 	shell32
 	comdlg32
 	comctl32
-	wsock32
+	ws2_32
 """)
 
 docs = Split("""
Index: Contrib/Makensisw/makensisw.h
===================================================================
--- Contrib/Makensisw/makensisw.h	(revision 6035)
+++ Contrib/Makensisw/makensisw.h	(working copy)
@@ -22,7 +22,9 @@
 #ifndef MAKENSIS_H
 #define MAKENSIS_H
 
+#ifndef _WIN32_IE
 #define _WIN32_IE 0x0400
+#endif
 #include <windows.h>
 #include <commctrl.h>
 #include "utils.h"
@@ -143,7 +145,7 @@
 extern const char* NSISW_VERSION;
 
 int WINAPI     WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *cmdParam, int cmdShow);
-BOOL           CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
+INT_PTR        CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 DWORD WINAPI   MakeNSISProc(LPVOID p);
 BOOL CALLBACK  DialogResize(HWND hWnd, LPARAM /* unused*/);
 BOOL CALLBACK  AboutNSISProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
Index: Contrib/Makensisw/afxres.h
===================================================================
--- Contrib/Makensisw/afxres.h	(revision 6035)
+++ Contrib/Makensisw/afxres.h	(working copy)
@@ -1,4 +1,6 @@
+#ifndef _WIN32_IE
 #define _WIN32_IE 0x0400
+#endif
 #include <windows.h>
 
 #ifndef IDC_STATIC
Index: Contrib/NSIS Menu/SConscript
===================================================================
--- Contrib/NSIS Menu/SConscript	(revision 6035)
+++ Contrib/NSIS Menu/SConscript	(working copy)
@@ -12,14 +12,14 @@
 rc = 'nsismenu/nsismenu.rc'
 
 libs = Split("""
+	wxmsw28_html
+	wxmsw28_core
+	wxbase28
 	advapi32
 	comctl32
 	gdi32
 	shell32
 	user32
-	wxbase28
-	wxmsw28_core
-	wxmsw28_html
 """)
 
 html = Split("""
@@ -66,10 +66,14 @@
 	# set directories
 
 	if nsis_menu[0].env['PLATFORM'] == 'win32':
-		wxlib = [join(env['WXWIN'], 'lib', 'vc_libnsis')]
+		wxlib = [
+			join(env['WXWIN'], 'lib', 'vc_libnsis'),
+			join(env['WXWIN'], 'lib', 'gcc_libnsis')
+		]
 		wxinc = [
 			join(env['WXWIN'], 'include'),
-			join(env['WXWIN'], 'lib', 'vc_libnsis', 'msw')
+			join(env['WXWIN'], 'lib', 'vc_libnsis', 'msw'),
+			join(env['WXWIN'], 'lib', 'gcc_libnsis', 'msw')
 		]
 		nsis_menu[0].env.Append(LIBPATH = wxlib)
 		nsis_menu[0].env.Append(CPPPATH = wxinc)
Index: Source/zlib/DEFLATE.H (deleted)
===================================================================
Index: Source/SConscript
===================================================================
--- Source/SConscript	(revision 6035)
+++ Source/SConscript	(working copy)
@@ -67,7 +67,7 @@
 
 ##### Defines
 
-env.Append(CPPDEFINES = ['_WIN32_IE=0x0500'])
+env.SetDefault(CPPDEFINES = ['_WIN32_IE=0x0500'])
 
 ##### Set PCH
 
Index: SCons/Tools/crossmingw.py
===================================================================
--- SCons/Tools/crossmingw.py	(revision 6035)
+++ SCons/Tools/crossmingw.py	(working copy)
@@ -36,6 +36,7 @@
 import os
 import os.path
 import string
+import re
 
 import SCons.Action
 import SCons.Builder
@@ -61,6 +62,11 @@
 """)
 
 def find(env):
+    # Explicitly specified toolchain to build Windows executables
+    # takes predominance.
+    prefix = SCons.Script.ARGUMENTS.get('CROSS_W32', None)
+    if prefix:
+        prefixes.insert(0, prefix)
     for prefix in prefixes:
         # First search in the SCons path and then the OS path:
         if env.WhereIs(prefix + 'gcc') or SCons.Util.WhereIs(prefix + 'gcc'):
@@ -177,5 +183,9 @@
     env['LIBPREFIXES']    = [ '$LIBPREFIX' ]
     env['LIBSUFFIXES']    = [ '$LIBSUFFIX' ]
 
+    # w64-mingw32: Preset _WIN32_IE define
+    if (re.match('.+-w64-.+', mingw_prefix)):
+    	env.Append(CPPDEFINES = ['_WIN32_IE=0x0501'])
+
 def exists(env):
     return find(env)
Index: SConscript
===================================================================
--- Source/exehead/SConscript	(revision 6035)
+++ Source/exehead/SConscript	(working copy)
@@ -53,7 +53,7 @@
 
 env.Append(CPPDEFINES = ['EXEHEAD'])
 env.Append(CPPDEFINES = ['WIN32_LEAN_AND_MEAN'])
-env.Append(CPPDEFINES = ['_WIN32_IE=0x0500'])
+env.SetDefault(CPPDEFINES = ['_WIN32_IE=0x0501'])
 
 ### Some other settings
 
