From feaad5f26780e5ea143af6da2e000e7058336b36 Mon Sep 17 00:00:00 2001
From: Eduardo DAVILA <davila@creatis.insa-lyon.fr>
Date: Tue, 17 Jul 2018 13:36:54 +0200
Subject: [PATCH] #3203 BBTK Feature New Normal vtk7itk4wx3-mingw64

---
 kernel/appli/bbi/CMakeLists.txt      |  6 +++++-
 kernel/appli/bbi/bbi.cxx             |  7 ++++++-
 kernel/cmake/BBTKFindLibraries.cmake | 10 +++++++++-
 kernel/src/bbtkSystem.h              |  6 ++++--
 kernel/src/bbtkUtilities.cxx         | 11 ++++++++++-
 5 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/kernel/appli/bbi/CMakeLists.txt b/kernel/appli/bbi/CMakeLists.txt
index a8a2ddb..0422e38 100644
--- a/kernel/appli/bbi/CMakeLists.txt
+++ b/kernel/appli/bbi/CMakeLists.txt
@@ -37,7 +37,11 @@ SET(SOURCES
 
 IF(BBTK_USE_WXWIDGETS AND WIN32)
   ADD_EXECUTABLE(bbi WIN32 ${SOURCES})  
-  SET_TARGET_PROPERTIES(bbi PROPERTIES LINK_FLAGS /subsystem:console )
+  IF(MINGW)
+	SET_TARGET_PROPERTIES(bbi PROPERTIES LINK_FLAGS -mconsole )
+  ELSE(MINGW)
+	SET_TARGET_PROPERTIES(bbi PROPERTIES LINK_FLAGS /subsystem:console )
+  ENDIF(MINGW)
 ELSE(BBTK_USE_WXWIDGETS AND WIN32)
   ADD_EXECUTABLE(bbi MACOSX_BUNDLE ${SOURCES})  
 ENDIF(BBTK_USE_WXWIDGETS AND WIN32)
diff --git a/kernel/appli/bbi/bbi.cxx b/kernel/appli/bbi/bbi.cxx
index c594a08..3f60890 100644
--- a/kernel/appli/bbi/bbi.cxx
+++ b/kernel/appli/bbi/bbi.cxx
@@ -301,9 +301,14 @@ int main(int argc, char* argv[])
 //Borrame
 //FILE *ff; ff = fopen ("/tmp/wt.log","a+"); fprintf(ff,"EED main C\n"); fclose(ff);
 
-    return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
+	// EED 2018-07-16
+	char buffer[1500];
+	wcstombs(buffer , ::GetCommandLine() , 1500 );
+    return WinMain(::GetModuleHandle(NULL), NULL, buffer , SW_SHOWNORMAL);
+//    return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
 }
 
+
 #else 
 //==========================================================================
 // OTHER ( Linux... )
diff --git a/kernel/cmake/BBTKFindLibraries.cmake b/kernel/cmake/BBTKFindLibraries.cmake
index a57a707..4ae316b 100644
--- a/kernel/cmake/BBTKFindLibraries.cmake
+++ b/kernel/cmake/BBTKFindLibraries.cmake
@@ -96,7 +96,7 @@ MESSAGE(STATUS "")
 IF(BBTK_USE_WXWIDGETS)
   SET(BBTK_LINK_LIBRARIES
     ${BBTK_LINK_LIBRARIES}
-    ${WXWIDGETS_LIBRARIES} 
+    ${WXWIDGETS_LIBRARIES}
     )
 ENDIF(BBTK_USE_WXWIDGETS)
 #-----------------------------------------------------------------------------
@@ -138,6 +138,14 @@ IF(UNIX)
 ENDIF(UNIX)
 #-----------------------------------------------------------------------------
 
+# mingw 
+IF(MINGW)
+  SET(BBTK_LINK_LIBRARIES
+    ${BBTK_LINK_LIBRARIES}
+    dl) 
+ENDIF(MINGW)
+
+
 #-----------------------------------------------------------------------------
 MESSAGE(STATUS "")
 MESSAGE(STATUS "=======================================")
diff --git a/kernel/src/bbtkSystem.h b/kernel/src/bbtkSystem.h
index 558af50..ecd6099 100644
--- a/kernel/src/bbtkSystem.h
+++ b/kernel/src/bbtkSystem.h
@@ -109,8 +109,10 @@
 
 
 #if defined(_WIN32) 
-  // IF NOT DEF THEN INTERNAL COMPILER ERROR WITH BOOST 1.37 ON VISUAL C++ 
-  #define BOOST_SP_NO_SP_CONVERTIBLE
+	#ifdef _MSC_VER
+	  // IF NOT DEF THEN INTERNAL COMPILER ERROR WITH BOOST 1.37 ON VISUAL C++ 
+	  #define BOOST_SP_NO_SP_CONVERTIBLE
+	#endif
 #endif
 
 #if defined(_WIN32) 
diff --git a/kernel/src/bbtkUtilities.cxx b/kernel/src/bbtkUtilities.cxx
index 7e85dc7..a7285fe 100644
--- a/kernel/src/bbtkUtilities.cxx
+++ b/kernel/src/bbtkUtilities.cxx
@@ -39,6 +39,11 @@
 #include "bbtkUtilities.h"
 #include "bbtkMessageManager.h"
 
+//EED 2018-07-16
+#if defined(_WIN32) 
+	#include <shlwapi.h>
+#endif
+
 #if defined(MACOSX) // assume this is OSX 
 # include <sys/param.h>
 # include <mach-o/dyld.h> // _NSGetExecutablePath : must add -framework CoreFoundation to link line 
@@ -633,7 +638,11 @@ namespace bbtk
 #endif /* LINUX */
     
 #ifdef WIN32
-    long result = GetModuleFileName(NULL, pname, pathsize);
+//2018-07-06 mingw64
+    wchar_t pname2[512];
+	mbstowcs(pname2,pname,strlen(pname)+1);
+    long result = GetModuleFileName(NULL, pname2, pathsize);
+//    long result = GetModuleFileName(NULL, pname, pathsize);
     if (result > 0)
       {
 	/* fix up the dir slashes... */
-- 
2.49.0