diff --git a/build.sh b/build.sh
index 0840d62287cca69519f0fbcc8bcfe2470e36d2fb..1a6d73a95041a20da26cb91145b1ccbcd2390d20 100755
--- a/build.sh
+++ b/build.sh
@@ -514,7 +514,7 @@ set_mingw()
     export CC=`which ${TARGET_HOST}-gcc`
     export CXX=`which ${TARGET_HOST}-g++`
 
-    export CPPFLAGS="-D_WIN32_WINDOWS=0x0410 $CPPFLAGS"
+    export CPPFLAGS="-D_WIN32_WINDOWS=0x0410 -DMINGW_WIN32 $CPPFLAGS"
 }
 
 
@@ -651,9 +651,13 @@ build_boinc_mingw()
     prepare_boinc $TAG_GFXAPPS || failure
 
     echo "Patching BOINC..." | tee -a $LOGFILE
+    # patch: fix BOINC vs. MinGW issues
+    cd $ROOT/3rdparty/boinc/api || failure
+    patch boinc_api.h < $ROOT/patches/boinc.boinc_api.h.mingw.patch >> $LOGFILE 2>&1 || failure                     # patch sent upstream!
     cd $ROOT/3rdparty/boinc/lib || failure
-    # patch: fix a couple of BOINC vs. MinGW issues
-    patch boinc_win.h < $ROOT/patches/boinc.boinc_win.h.minggw.patch >> $LOGFILE 2>&1 || failure
+    patch diagnostics.cpp < $ROOT/patches/boinc.diagnostics.cpp.mingw.patch >> $LOGFILE 2>&1 || failure             # patch sent upstream!
+    patch diagnostics_win.cpp < $ROOT/patches/boinc.diagnostics_win.cpp.mingw.1.patch >> $LOGFILE 2>&1 || failure   # patch sent upstream!
+    patch diagnostics_win.cpp < $ROOT/patches/boinc.diagnostics_win.cpp.mingw.2.patch >> $LOGFILE 2>&1 || failure   # patch sent upstream!
     patch filesys.cpp < $ROOT/patches/boinc.filesys.cpp.mingw.patch >> $LOGFILE 2>&1 || failure
     echo "Building BOINC (this may take a while)..." | tee -a $LOGFILE
     cd $ROOT/3rdparty/boinc || failure
diff --git a/patches/boinc.Makefile.mingw.patch b/patches/boinc.Makefile.mingw.patch
index aeb4452fd50821d9aa55d3594bd9489e0f8716c1..1a03e8a88e699bb5369d7dadfc01bb54afd53121 100644
--- a/patches/boinc.Makefile.mingw.patch
+++ b/patches/boinc.Makefile.mingw.patch
@@ -14,7 +14,7 @@
  #
 -CXXFLAGS = $(CXXINCS) $(DEBUG) --include $(BOINCDIR)/version.h -DWIN32 -D_WIN32 -D_WIN32_WINDOWS=0x0501 -D_MT -DNDEBUG -D_WINDOWS  -DBOINC -DCLIENT -DNODB -D_CONSOLE -Wall -mtune=pentium-m   -fexceptions -march=i386 -O1
 -CFLAGS = $(INCS) $(DEBUG) --include $(BOINCDIR)/version.h -DWIN32 -D_WIN32 -D_WIN32_WINDOWS=0x0501 -D_MT -DNDEBUG -D_WINDOWS  -DBOINC -DCLIENT -DNODB -D_CONSOLE -Wall -mtune=pentium-m   -fexceptions -march=i386 -O1
-+CXXFLAGS = $(CXXINCS) $(DEBUG) --include $(BOINCDIR)/version.h -DWIN32 -D_WIN32 -D_WIN32_WINDOWS=0x0410 -D_MT -DNDEBUG -D_WINDOWS  -DBOINC -DCLIENT -DNODB -D_CONSOLE -Wall -mtune=pentium-m   -fexceptions -march=i386 -O1
++CXXFLAGS = $(CXXINCS) $(DEBUG) --include $(BOINCDIR)/version.h -DMINGW_WIN32 -DWIN32 -D_WIN32 -D_WIN32_WINDOWS=0x0410 -D_MT -DNDEBUG -D_WINDOWS  -DBOINC -DCLIENT -DNODB -D_CONSOLE -Wall -mtune=pentium-m   -fexceptions -march=i386 -O1
 +CFLAGS = $(INCS) $(DEBUG) --include $(BOINCDIR)/version.h -DWIN32 -D_WIN32 -D_WIN32_WINDOWS=0x0410 -D_MT -DNDEBUG -D_WINDOWS  -DBOINC -DCLIENT -DNODB -D_CONSOLE -Wall -mtune=pentium-m   -fexceptions -march=i386 -O1
  
  
diff --git a/patches/boinc.boinc_api.h.mingw.patch b/patches/boinc.boinc_api.h.mingw.patch
new file mode 100644
index 0000000000000000000000000000000000000000..937a778f9037297c916fac0fd4f1c55de8934118
--- /dev/null
+++ b/patches/boinc.boinc_api.h.mingw.patch
@@ -0,0 +1,13 @@
+--- boinc_api.h
++++ boinc_api.h	2009-11-06 16:30:39.000000000 +0100
+@@ -22,6 +22,10 @@
+ #include <Carbon/Carbon.h>
+ #endif
+ 
++#ifdef _WIN32
++#include "boinc_win.h"
++#endif
++
+ // ANSI C API BEGINS HERE
+ // Do not put implementation stuff here
+ 
diff --git a/patches/boinc.boinc_win.h.minggw.patch b/patches/boinc.boinc_win.h.minggw.patch
deleted file mode 100644
index af8517b8c9edcb72572f8264a14640b2ab230a87..0000000000000000000000000000000000000000
--- a/patches/boinc.boinc_win.h.minggw.patch
+++ /dev/null
@@ -1,44 +0,0 @@
---- boinc_win.h
-+++ boinc_win.h	2008-06-03 17:35:38.000000000 +0200
-@@ -73,6 +73,10 @@
- #include <userenv.h>
- #include <aclapi.h>
- 
-+#if defined(__MINGW32__)
-+#include <stdint.h>
-+#endif
-+
- #if !defined(__CYGWIN32__) || defined(USE_WINSOCK)
- 
- /* If we're not running under CYGWIN use windows networking */
-@@ -108,7 +108,7 @@
- 
- #include <commctrl.h>
- #include <raserror.h>
--#include <dbghelp.h>
-+#include <imagehlp.h>
- #include <tlhelp32.h>
- 
- #include <io.h>
-@@ -141,7 +141,7 @@
- // C headers
- #include <sys/stat.h>
- #include <sys/types.h>
--#include <fcntl.h>
-+// #include <fcntl.h>
- #include <malloc.h>
- 
- #if !defined(__MINGW32__) && !defined(__CYGWIN32__)
-@@ -236,9 +236,9 @@
- #endif
- void __cdecl _fpreset (void);
- void __cdecl fpreset (void);
--#define SetClassLongPtr SetClassLong
--#define GCLP_HICON GCL_HICON
--#define GCLP_HICONSM GCL_HICONSM
-+// #define SetClassLongPtr SetClassLong
-+// #define GCLP_HICON GCL_HICON
-+// #define GCLP_HICONSM GCL_HICONSM
- #ifdef __cplusplus
- }
- #endif
diff --git a/patches/boinc.diagnostics.cpp.mingw.patch b/patches/boinc.diagnostics.cpp.mingw.patch
new file mode 100644
index 0000000000000000000000000000000000000000..d5a184325b440d0c6865d44d8a60ee33c2f51062
--- /dev/null
+++ b/patches/boinc.diagnostics.cpp.mingw.patch
@@ -0,0 +1,11 @@
+--- diagnostics.cpp
++++ diagnostics.cpp	2009-11-06 14:35:59.000000000 +0100
+@@ -22,7 +22,7 @@
+ #include "boinc_win.h"
+ #endif
+ 
+-#ifdef _MSC_VER
++#if defined(_MSC_VER) || defined(__MINGW32__)
+ #define snprintf    _snprintf
+ #define strdate     _strdate
+ #define strtime     _strtime
diff --git a/patches/boinc.diagnostics_win.cpp.mingw.1.patch b/patches/boinc.diagnostics_win.cpp.mingw.1.patch
new file mode 100644
index 0000000000000000000000000000000000000000..19fd87a710f7fee0716136b49a31fe78ac6f090a
--- /dev/null
+++ b/patches/boinc.diagnostics_win.cpp.mingw.1.patch
@@ -0,0 +1,11 @@
+--- diagnostics_win.cpp
++++ diagnostics_win.cpp	2009-11-06 15:10:47.000000000 +0100
+@@ -22,7 +22,7 @@
+ #include "boinc_win.h"
+ #endif
+ 
+-#ifdef _MSC_VER
++#if defined(_MSC_VER) || defined(__MINGW32__)
+ #define snprintf    _snprintf
+ #define strdate     _strdate
+ #define strtime     _strtime
diff --git a/patches/boinc.diagnostics_win.cpp.mingw.2.patch b/patches/boinc.diagnostics_win.cpp.mingw.2.patch
new file mode 100644
index 0000000000000000000000000000000000000000..eb7e92cf0a9c8427396d8b2a73da61743a881e88
--- /dev/null
+++ b/patches/boinc.diagnostics_win.cpp.mingw.2.patch
@@ -0,0 +1,19 @@
+--- diagnostics_win.cpp
++++ diagnostics_win.cpp	2009-11-06 15:00:28.000000000 +0100
+@@ -2069,9 +2069,15 @@
+ //   library this function will write whatever trace information it can and
+ //   then throw a breakpoint exception to dump all the rest of the useful
+ //   information.
++#ifdef MINGW_WIN32
++void boinc_catch_signal_invalid_parameter(
++    const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line)
++#else
+ void boinc_catch_signal_invalid_parameter(
+     const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line,	uintptr_t /* pReserved */
+-) {
++)
++#endif
++{
+ 	fprintf(
+ 		stderr,
+         "ERROR: Invalid parameter detected in function %s. File: %s Line: %d\n",