[KERNEL32]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Tue, 9 Sep 2014 21:24:44 +0000 (21:24 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Tue, 9 Sep 2014 21:24:44 +0000 (21:24 +0000)
- Remove unneeded old commented code chunks.
- ConDllInitialize can set the current console locale for new threads,...
- ... and it can do its own cleaning.

svn path=/branches/condrv_restructure/; revision=64098

dll/win32/kernel32/client/console/console.c
dll/win32/kernel32/client/console/history.c
dll/win32/kernel32/client/console/init.c
dll/win32/kernel32/client/console/readwrite.c
dll/win32/kernel32/client/console/vista.c
dll/win32/kernel32/client/dllmain.c
dll/win32/kernel32/include/console.h

index fc79d88..ee630cb 100644 (file)
@@ -3,8 +3,8 @@
  * PROJECT:         ReactOS system libraries
  * FILE:            dll/win32/kernel32/client/console/console.c
  * PURPOSE:         Win32 server console functions
- * PROGRAMMERS:     James Tabor
- *                  <jimtabor@adsl-64-217-116-74.dsl.hstntx.swbell.net>
+ * PROGRAMMERS:     James Tabor <jimtabor@adsl-64-217-116-74.dsl.hstntx.swbell.net>
+ *                  Hermes Belusca-Maito (hermes.belusca@sfr.fr)
  */
 
 /* INCLUDES *******************************************************************/
@@ -1316,6 +1316,7 @@ AllocConsole(VOID)
         /* Initialize Console Ctrl Handling */
         InitializeCtrlHandling();
 
+        /* Sets the current console locale for this thread */
         SetTEBLangID(lcid);
     }
 
@@ -2578,6 +2579,7 @@ AttachConsole(DWORD dwProcessId)
         /* Initialize Console Ctrl Handling */
         InitializeCtrlHandling();
 
+        /* Sets the current console locale for this thread */
         SetTEBLangID(lcid);
     }
 
index 2fc5024..fdc5826 100644 (file)
@@ -25,30 +25,6 @@ IntStringSize(LPCVOID String,
     ULONG Size = (Unicode ? wcslen(String) : strlen(String)) * sizeof(WCHAR);
     return (Size + 3) & ~3;
 }
-
-
-/* Copy a string to a capture buffer */
-static VOID
-IntCaptureMessageString(PCSR_CAPTURE_BUFFER CaptureBuffer,
-                        LPCVOID String,
-                        BOOL Unicode,
-                        PUNICODE_STRING RequestString)
-{
-    ULONG Size;
-    if (Unicode)
-    {
-        Size = wcslen(String) * sizeof(WCHAR);
-        CsrCaptureMessageBuffer(CaptureBuffer, (PVOID)String, Size, (PVOID *)&RequestString->Buffer);
-    }
-    else
-    {
-        Size = strlen(String);
-        CsrAllocateMessagePointer(CaptureBuffer, Size * sizeof(WCHAR), (PVOID *)&RequestString->Buffer);
-        Size = MultiByteToWideChar(CP_ACP, 0, String, Size, RequestString->Buffer, Size * sizeof(WCHAR))
-               * sizeof(WCHAR);
-    }
-    RequestString->Length = RequestString->MaximumLength = (USHORT)Size;
-}
 #endif
 
 static VOID
@@ -80,8 +56,6 @@ IntExpungeConsoleCommandHistory(LPCVOID lpExeName, BOOLEAN bUnicode)
         return;
     }
 
-    // IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
-    //                         &ExpungeCommandHistoryRequest->ExeName);
     CsrCaptureMessageBuffer(CaptureBuffer,
                             (PVOID)lpExeName,
                             ExpungeCommandHistoryRequest->ExeLength,
@@ -131,14 +105,11 @@ IntGetConsoleCommandHistory(LPVOID lpHistory, DWORD cbHistory, LPCVOID lpExeName
         return 0;
     }
 
-    // IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
-    //                         &GetCommandHistoryRequest->ExeName);
     CsrCaptureMessageBuffer(CaptureBuffer,
                             (PVOID)lpExeName,
                             GetCommandHistoryRequest->ExeLength,
                             (PVOID)&GetCommandHistoryRequest->ExeName);
 
-    // CsrAllocateMessagePointer(CaptureBuffer, HistoryLength,
     CsrAllocateMessagePointer(CaptureBuffer, GetCommandHistoryRequest->HistoryLength,
                               (PVOID*)&GetCommandHistoryRequest->History);
 
@@ -192,8 +163,6 @@ IntGetConsoleCommandHistoryLength(LPCVOID lpExeName, BOOL bUnicode)
         return 0;
     }
 
-    // IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
-    //                         &GetCommandHistoryLengthRequest->ExeName);
     CsrCaptureMessageBuffer(CaptureBuffer,
                             (PVOID)lpExeName,
                             GetCommandHistoryLengthRequest->ExeLength,
@@ -248,8 +217,6 @@ IntSetConsoleNumberOfCommands(DWORD dwNumCommands,
         return FALSE;
     }
 
-    // IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode,
-    //                         &SetHistoryNumberCommandsRequest->ExeName);
     CsrCaptureMessageBuffer(CaptureBuffer,
                             (PVOID)lpExeName,
                             SetHistoryNumberCommandsRequest->ExeLength,
index 1d550b9..5134028 100644 (file)
@@ -26,7 +26,7 @@ BOOLEAN ConsoleInitialized = FALSE;
 
 extern HANDLE InputWaitHandle;
 
-static HMODULE ConsoleLibrary = NULL;
+static HMODULE ConsoleApplet = NULL;
 static BOOL AlreadyDisplayingProps = FALSE;
 
 static const PWSTR DefaultConsoleTitle = L"ReactOS Console";
@@ -60,14 +60,14 @@ PropDialogHandler(IN LPVOID lpThreadParameter)
     AlreadyDisplayingProps = TRUE;
 
     /* Load the Control Applet if needed */
-    if (ConsoleLibrary == NULL)
+    if (ConsoleApplet == NULL)
     {
         WCHAR szBuffer[MAX_PATH];
 
         GetSystemDirectoryW(szBuffer, MAX_PATH);
         wcscat(szBuffer, L"\\console.dll");
-        ConsoleLibrary = LoadLibraryW(szBuffer);
-        if (ConsoleLibrary == NULL)
+        ConsoleApplet = LoadLibraryW(szBuffer);
+        if (ConsoleApplet == NULL)
         {
             DPRINT1("Failed to load console.dll\n");
             Status = STATUS_UNSUCCESSFUL;
@@ -76,7 +76,7 @@ PropDialogHandler(IN LPVOID lpThreadParameter)
     }
 
     /* Load its main function */
-    CPLFunc = (APPLET_PROC)GetProcAddress(ConsoleLibrary, "CPlApplet");
+    CPLFunc = (APPLET_PROC)GetProcAddress(ConsoleApplet, "CPlApplet");
     if (CPLFunc == NULL)
     {
         DPRINT1("Error: Console.dll misses CPlApplet export\n");
@@ -261,7 +261,7 @@ SetUpHandles(IN PCONSOLE_START_INFO ConsoleStartInfo)
     /* We got the handles, let's set them */
     Parameters->ConsoleHandle = ConsoleStartInfo->ConsoleHandle;
 
-    if (!(ConsoleStartInfo->dwStartupFlags & STARTF_USESTDHANDLES))
+    if ((ConsoleStartInfo->dwStartupFlags & STARTF_USESTDHANDLES) == 0)
     {
         Parameters->StandardInput  = ConsoleStartInfo->InputHandle;
         Parameters->StandardOutput = ConsoleStartInfo->OutputHandle;
@@ -345,11 +345,24 @@ ConDllInitialize(IN ULONG Reason,
 
     if (Reason != DLL_PROCESS_ATTACH)
     {
-        if (Reason != DLL_THREAD_ATTACH || !IsConsoleApp())
-            return TRUE;
+        if ((Reason == DLL_THREAD_ATTACH) && IsConsoleApp())
+        {
+            /* Sets the current console locale for the new thread */
+            SetTEBLangID(lcid);
+        }
+        else if (Reason == DLL_PROCESS_DETACH)
+        {
+            /* Free our resources */
+            if (ConsoleInitialized == TRUE)
+            {
+                if (ConsoleApplet) FreeLibrary(ConsoleApplet);
+
+                ConsoleInitialized = FALSE;
+                RtlDeleteCriticalSection(&ConsoleLock);
+            }
+        }
 
-        // Reason == DLL_THREAD_ATTACH and IsConsoleApp;
-        goto Exit;
+        return TRUE;
     }
 
     DPRINT("ConDllInitialize for: %wZ\n"
@@ -509,7 +522,8 @@ ConDllInitialize(IN ULONG Reason,
             SetUpHandles(&ConnectInfo.ConsoleStartInfo);
 
         InputWaitHandle = ConnectInfo.ConsoleStartInfo.InputWaitHandle;
-Exit:
+
+        /* Sets the current console locale for this thread */
         SetTEBLangID(lcid);
     }
 
@@ -522,19 +536,4 @@ Exit:
     return TRUE;
 }
 
-
-VOID
-WINAPI
-BasepUninitConsole(VOID)
-{
-    /* Delete our critical section if we were initialized */
-    if (ConsoleInitialized == TRUE)
-    {
-        if (ConsoleLibrary) FreeLibrary(ConsoleLibrary);
-
-        ConsoleInitialized = FALSE;
-        RtlDeleteCriticalSection(&ConsoleLock);
-    }
-}
-
 /* EOF */
index 39d0727..e231b41 100644 (file)
@@ -163,7 +163,7 @@ IntReadConsole(IN HANDLE hConsoleInput,
     }
     _SEH2_END;
 
-    /* Check for sanity */
+    /* FIXME: Check for sanity */
 /*
     if (!NT_SUCCESS(Status) && pInputControl)
     {
@@ -1167,9 +1167,7 @@ IntFillConsoleOutputCode(IN HANDLE hConsoleOutput,
  * Read functions *
  ******************/
 
-/*--------------------------------------------------------------
- *    ReadConsoleW
- *
+/*
  * @implemented
  */
 BOOL
@@ -1189,9 +1187,7 @@ ReadConsoleW(IN HANDLE hConsoleInput,
 }
 
 
-/*--------------------------------------------------------------
- *    ReadConsoleA
- *
+/*
  * @implemented
  */
 BOOL
@@ -1211,9 +1207,7 @@ ReadConsoleA(IN HANDLE hConsoleInput,
 }
 
 
-/*--------------------------------------------------------------
- *     PeekConsoleInputW
- *
+/*
  * @implemented
  */
 BOOL
@@ -1232,9 +1226,7 @@ PeekConsoleInputW(IN HANDLE hConsoleInput,
 }
 
 
-/*--------------------------------------------------------------
- *     PeekConsoleInputA
- *
+/*
  * @implemented
  */
 BOOL
@@ -1253,9 +1245,7 @@ PeekConsoleInputA(IN HANDLE hConsoleInput,
 }
 
 
-/*--------------------------------------------------------------
- *     ReadConsoleInputW
- *
+/*
  * @implemented
  */
 BOOL
@@ -1274,9 +1264,7 @@ ReadConsoleInputW(IN HANDLE hConsoleInput,
 }
 
 
-/*--------------------------------------------------------------
- *     ReadConsoleInputA
- *
+/*
  * @implemented
  */
 BOOL
@@ -1295,9 +1283,7 @@ ReadConsoleInputA(IN HANDLE hConsoleInput,
 }
 
 
-/*--------------------------------------------------------------
- *     ReadConsoleInputExW
- *
+/*
  * @implemented
  */
 BOOL
@@ -1317,9 +1303,7 @@ ReadConsoleInputExW(IN HANDLE hConsoleInput,
 }
 
 
-/*--------------------------------------------------------------
- *     ReadConsoleInputExA
- *
+/*
  * @implemented
  */
 BOOL
@@ -1339,9 +1323,7 @@ ReadConsoleInputExA(IN HANDLE hConsoleInput,
 }
 
 
-/*--------------------------------------------------------------
- *     ReadConsoleOutputW
- *
+/*
  * @implemented
  */
 BOOL
@@ -1361,9 +1343,7 @@ ReadConsoleOutputW(IN HANDLE hConsoleOutput,
 }
 
 
-/*--------------------------------------------------------------
- *     ReadConsoleOutputA
- *
+/*
  * @implemented
  */
 BOOL
@@ -1383,9 +1363,7 @@ ReadConsoleOutputA(IN HANDLE hConsoleOutput,
 }
 
 
-/*--------------------------------------------------------------
- *      ReadConsoleOutputCharacterW
- *
+/*
  * @implemented
  */
 BOOL
@@ -1405,9 +1383,7 @@ ReadConsoleOutputCharacterW(IN HANDLE hConsoleOutput,
 }
 
 
-/*--------------------------------------------------------------
- *     ReadConsoleOutputCharacterA
- *
+/*
  * @implemented
  */
 BOOL
@@ -1427,9 +1403,7 @@ ReadConsoleOutputCharacterA(IN HANDLE hConsoleOutput,
 }
 
 
-/*--------------------------------------------------------------
- *     ReadConsoleOutputAttribute
- *
+/*
  * @implemented
  */
 BOOL
@@ -1453,9 +1427,7 @@ ReadConsoleOutputAttribute(IN HANDLE hConsoleOutput,
  * Write functions *
  *******************/
 
-/*--------------------------------------------------------------
- *    WriteConsoleW
- *
+/*
  * @implemented
  */
 BOOL
@@ -1475,9 +1447,7 @@ WriteConsoleW(IN HANDLE hConsoleOutput,
 }
 
 
-/*--------------------------------------------------------------
- *    WriteConsoleA
- *
+/*
  * @implemented
  */
 BOOL
@@ -1497,9 +1467,7 @@ WriteConsoleA(IN HANDLE hConsoleOutput,
 }
 
 
-/*--------------------------------------------------------------
- *     WriteConsoleInputW
- *
+/*
  * @implemented
  */
 BOOL
@@ -1518,9 +1486,7 @@ WriteConsoleInputW(IN HANDLE hConsoleInput,
 }
 
 
-/*--------------------------------------------------------------
- *     WriteConsoleInputA
- *
+/*
  * @implemented
  */
 BOOL
@@ -1539,9 +1505,7 @@ WriteConsoleInputA(IN HANDLE hConsoleInput,
 }
 
 
-/*--------------------------------------------------------------
- *     WriteConsoleInputVDMW
- *
+/*
  * @implemented
  */
 BOOL
@@ -1560,9 +1524,7 @@ WriteConsoleInputVDMW(IN HANDLE hConsoleInput,
 }
 
 
-/*--------------------------------------------------------------
- *     WriteConsoleInputVDMA
- *
+/*
  * @implemented
  */
 BOOL
@@ -1581,9 +1543,7 @@ WriteConsoleInputVDMA(IN HANDLE hConsoleInput,
 }
 
 
-/*--------------------------------------------------------------
- *     WriteConsoleOutputW
- *
+/*
  * @implemented
  */
 BOOL
@@ -1603,9 +1563,7 @@ WriteConsoleOutputW(IN HANDLE hConsoleOutput,
 }
 
 
-/*--------------------------------------------------------------
- *     WriteConsoleOutputA
- *
+/*
  * @implemented
  */
 BOOL
@@ -1625,9 +1583,7 @@ WriteConsoleOutputA(IN HANDLE hConsoleOutput,
 }
 
 
-/*--------------------------------------------------------------
- *     WriteConsoleOutputCharacterW
- *
+/*
  * @implemented
  */
 BOOL
@@ -1647,9 +1603,7 @@ WriteConsoleOutputCharacterW(IN HANDLE hConsoleOutput,
 }
 
 
-/*--------------------------------------------------------------
- *     WriteConsoleOutputCharacterA
- *
+/*
  * @implemented
  */
 BOOL
@@ -1669,9 +1623,7 @@ WriteConsoleOutputCharacterA(IN HANDLE hConsoleOutput,
 }
 
 
-/*--------------------------------------------------------------
- *     WriteConsoleOutputAttribute
- *
+/*
  * @implemented
  */
 BOOL
@@ -1691,9 +1643,7 @@ WriteConsoleOutputAttribute(IN HANDLE hConsoleOutput,
 }
 
 
-/*--------------------------------------------------------------
- *    FillConsoleOutputCharacterW
- *
+/*
  * @implemented
  */
 BOOL
@@ -1715,9 +1665,7 @@ FillConsoleOutputCharacterW(IN HANDLE hConsoleOutput,
 }
 
 
-/*--------------------------------------------------------------
- *    FillConsoleOutputCharacterA
- *
+/*
  * @implemented
  */
 BOOL
@@ -1739,9 +1687,7 @@ FillConsoleOutputCharacterA(IN HANDLE hConsoleOutput,
 }
 
 
-/*--------------------------------------------------------------
- *     FillConsoleOutputAttribute
- *
+/*
  * @implemented
  */
 BOOL
index bd2721e..ca691dd 100644 (file)
@@ -18,9 +18,7 @@
 
 #if _WIN32_WINNT >= 0x600
 
-/*--------------------------------------------------------------
- *  GetConsoleHistoryInfo
- *
+/*
  * @implemented
  */
 BOOL
@@ -55,9 +53,7 @@ GetConsoleHistoryInfo(PCONSOLE_HISTORY_INFO lpConsoleHistoryInfo)
 }
 
 
-/*--------------------------------------------------------------
- *  SetConsoleHistoryInfo
- *
+/*
  * @implemented
  */
 BOOL
@@ -92,9 +88,7 @@ SetConsoleHistoryInfo(IN PCONSOLE_HISTORY_INFO lpConsoleHistoryInfo)
 }
 
 
-/*--------------------------------------------------------------
- *  GetConsoleOriginalTitleW
- *
+/*
  * @unimplemented
  */
 DWORD
@@ -108,9 +102,7 @@ GetConsoleOriginalTitleW(OUT LPWSTR lpConsoleTitle,
 }
 
 
-/*--------------------------------------------------------------
- *  GetConsoleOriginalTitleA
- *
+/*
  * @unimplemented
  */
 DWORD
@@ -124,9 +116,7 @@ GetConsoleOriginalTitleA(OUT LPSTR lpConsoleTitle,
 }
 
 
-/*--------------------------------------------------------------
- *  GetConsoleScreenBufferInfoEx
- *
+/*
  * @unimplemented
  */
 BOOL
@@ -140,9 +130,7 @@ GetConsoleScreenBufferInfoEx(IN HANDLE hConsoleOutput,
 }
 
 
-/*--------------------------------------------------------------
- *  SetConsoleScreenBufferInfoEx
- *
+/*
  * @unimplemented
  */
 BOOL
@@ -156,9 +144,7 @@ SetConsoleScreenBufferInfoEx(IN HANDLE hConsoleOutput,
 }
 
 
-/*--------------------------------------------------------------
- *  GetCurrentConsoleFontEx
- *
+/*
  * @unimplemented
  */
 BOOL
index 09aa3c0..26c24cf 100644 (file)
@@ -219,18 +219,24 @@ DllMain(HANDLE hDll,
         {
             if (DllInitialized == TRUE)
             {
+                /* Uninitialize console support */
+                ConDllInitialize(dwReason, NULL);
+
                 /* Insert more dll detach stuff here! */
                 NlsUninit();
 
-                /* Uninitialize console support */
-                BasepUninitConsole();
-
                 /* Delete DLL critical section */
                 RtlDeleteCriticalSection(&BaseDllDirectoryLock);
             }
             break;
         }
 
+        case DLL_THREAD_ATTACH:
+        {
+            /* ConDllInitialize sets the current console locale for the new thread */
+            return ConDllInitialize(dwReason, NULL);
+        }
+
         default:
             break;
     }
index d21fec0..79e1d9a 100644 (file)
@@ -26,10 +26,6 @@ WINAPI
 ConDllInitialize(IN ULONG Reason,
                  IN PWSTR SessionDir);
 
-VOID
-WINAPI
-BasepUninitConsole(VOID);
-
 VOID
 InitializeCtrlHandling(VOID);