Fix exit trouble with scilex and wscilax -nw under Windows 53/12553/2
Antoine ELIAS [Mon, 16 Sep 2013 12:59:03 +0000 (14:59 +0200)]
Change-Id: I5bf6ddfbac5d83fc4af031a422612c267e72d69d

scilab/modules/core/src/cpp/InitScilab.cpp
scilab/modules/core/src/cpp/scilab.cpp
scilab/modules/windows_tools/src/c/WScilex/WScilex.vcxproj

index 3ea728a..1a57ea7 100644 (file)
@@ -56,6 +56,11 @@ extern "C"
 #ifdef _MSC_VER
 #include "InitializeWindows_tools.h"
 #include "TerminateWindows_tools.h"
+#include "WndThread.h"
+#include "console.h"
+#include "InnosetupMutex.h"
+#include "MutexClosingScilab.h"
+
 #else
 #include "signal_mgmt.h"
 #include "initConsoleMode.h"
@@ -180,11 +185,34 @@ int StartScilabEngine(ScilabEngineInfo* _pSEI)
     {
         /* Initialize console: lines... */
         InitializeConsole();
+
+#ifdef _MSC_VER
+        //get current console window and hide it
+        CreateScilabHiddenWndThread();
+        CreateScilabConsole(0);
+        //create a thread for innosetup to allow reinstall during scilab running
+        createInnosetupMutex();
+#endif
     }
     else
     {
 #ifndef _MSC_VER
         initConsoleMode(RAW);
+#else
+        if (getScilabMode() != SCILAB_NWNI)
+        {
+            CreateScilabHiddenWndThread();
+        }
+
+        if ( (getScilabMode() == SCILAB_NWNI) || (getScilabMode() == SCILAB_NW) )
+        {
+            SaveConsoleColors();
+            if (getScilabMode() == SCILAB_NW)
+            {
+                RenameConsole();
+                UpdateConsoleColors();
+            }
+        }
 #endif
     }
 
@@ -262,6 +290,14 @@ int ExecExternalCommand(ScilabEngineInfo* _pSEI)
 
 void StopScilabEngine(ScilabEngineInfo* _pSEI)
 {
+#ifdef _MSC_VER
+    /* bug 3672 */
+    /* Create a Mutex (closing scilab)
+     * used by files association
+     */
+    createMutexClosingScilab();
+#endif
+
     clearScilabPreferences();
 
     //execute scilab.quit
@@ -317,7 +353,12 @@ void StopScilabEngine(ScilabEngineInfo* _pSEI)
 #endif
     }
 
-
+#ifdef _MSC_VER
+    /* close mutex (closing scilab)
+     * used by files association
+     */
+    terminateMutexClosingScilab();
+#endif
 }
 
 static Parser::ControlStatus processCommand(ScilabEngineInfo* _pSEI)
index 86d5a90..9115628 100644 (file)
@@ -192,11 +192,11 @@ static void TermPrintf(char *text)
 /*
 ** -*- MAIN -*-
 */
-#if defined(_WIN32) && !defined(WITHOUT_GUI)
-int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow)
-#else
+//#if defined(_WIN32) && !defined(WITHOUT_GUI)
+//int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow)
+//#else
 int main(int argc, char *argv[])
-#endif
+//#endif
 {
     int iRet = 0;
     ScilabEngineInfo* pSEI = InitScilabEngineInfo();
@@ -209,24 +209,24 @@ int main(int argc, char *argv[])
     setScilabMode(SCILAB_STD);
 #endif
 
-#if defined(_WIN32) && !defined(WITHOUT_GUI)
-    {
-        LPSTR my_argv[256];
-        int nArgs = 0;
-        LPWSTR *szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
-        if (szArglist)
-        {
-            for (int i = 0; i < nArgs; i++)
-            {
-                my_argv[i] = wide_string_to_UTF8(szArglist[i]);
-            }
-            LocalFree(szArglist);
-        }
-        get_option(nArgs, my_argv, pSEI);
-    }
-#else
+    //#if defined(_WIN32) && !defined(WITHOUT_GUI)
+    //    {
+    //        LPSTR my_argv[256];
+    //        int nArgs = 0;
+    //        LPWSTR *szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
+    //        if (szArglist)
+    //        {
+    //            for (int i = 0; i < nArgs; i++)
+    //            {
+    //                my_argv[i] = wide_string_to_UTF8(szArglist[i]);
+    //            }
+    //            LocalFree(szArglist);
+    //        }
+    //        get_option(nArgs, my_argv, pSEI);
+    //    }
+    //#else
     get_option(argc, argv, pSEI);
-#endif
+    //#endif
 
     // if WITHOUT_GUI is defined
     // force Terminal IO -> Terminal IO + StartScilabEngine
index 56eb449..b60d05e 100644 (file)
@@ -89,7 +89,7 @@
       <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <ProgramDatabaseFile>$(IntDir)WScilex.pdb</ProgramDatabaseFile>
-      <SubSystem>Windows</SubSystem>
+      <SubSystem>Console</SubSystem>
       <TargetMachine>MachineX86</TargetMachine>
       <CLRUnmanagedCodeCheck>true</CLRUnmanagedCodeCheck>
       <RandomizedBaseAddress>false</RandomizedBaseAddress>
       <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <ProgramDatabaseFile>$(OutDir)WScilex.pdb</ProgramDatabaseFile>
-      <SubSystem>Windows</SubSystem>
+      <SubSystem>Console</SubSystem>
       <TargetMachine>MachineX64</TargetMachine>
       <CLRUnmanagedCodeCheck>true</CLRUnmanagedCodeCheck>
       <RandomizedBaseAddress>false</RandomizedBaseAddress>
       <OutputFile>$(SolutionDir)bin\$(ProjectName).exe</OutputFile>
       <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
       <GenerateDebugInformation>false</GenerateDebugInformation>
-      <SubSystem>Windows</SubSystem>
+      <SubSystem>Console</SubSystem>
       <OptimizeReferences>true</OptimizeReferences>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <TargetMachine>MachineX86</TargetMachine>
       <OutputFile>$(SolutionDir)bin\$(ProjectName).exe</OutputFile>
       <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
       <GenerateDebugInformation>false</GenerateDebugInformation>
-      <SubSystem>Windows</SubSystem>
+      <SubSystem>Console</SubSystem>
       <OptimizeReferences>true</OptimizeReferences>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <TargetMachine>MachineX64</TargetMachine>