[CONSRV]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 10 Mar 2013 15:37:22 +0000 (15:37 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 10 Mar 2013 15:37:22 +0000 (15:37 +0000)
- Fix console initialization / uninitialization and resources release when initialization fails.
- Remove unneeded DPRINTs.

svn path=/branches/ros-csrss/; revision=58462

dll/win32/kernel32/client/console/console.c
win32ss/user/consrv/console.c
win32ss/user/consrv/guiconsole.c
win32ss/user/consrv/handle.c

index 02624dd..1e5ad3c 100644 (file)
@@ -145,6 +145,7 @@ ConsoleControlDispatcher(IN LPVOID lpThreadParameter)
     ASSERT(ConsoleInitialized);
 
     RtlEnterCriticalSection(&ConsoleLock);
+
     nExitCode = 0;
     if ((nCode != CTRL_C_EVENT) || (NtCurrentPeb()->ProcessParameters->ConsoleFlags != 1))
     {
@@ -175,6 +176,7 @@ ConsoleControlDispatcher(IN LPVOID lpThreadParameter)
     }
 
     RtlLeaveCriticalSection(&ConsoleLock);
+
     ExitThread(nExitCode);
     return STATUS_SUCCESS;
 }
index 2964792..62939ef 100644 (file)
@@ -54,7 +54,7 @@ ConSrvConsoleCtrlEventTimeout(DWORD Event,
             return;
         }
 
-        DPRINT1("We succeeded at creating ProcessData->CtrlDispatcher remote thread, ProcessId = %x, Process = 0x%p\n", ProcessData->Process->ClientId.UniqueProcess, ProcessData->Process);
+        DPRINT("We succeeded at creating ProcessData->CtrlDispatcher remote thread, ProcessId = %x, Process = 0x%p\n", ProcessData->Process->ClientId.UniqueProcess, ProcessData->Process);
         WaitForSingleObject(Thread, Timeout);
         CloseHandle(Thread);
     }
@@ -513,14 +513,10 @@ CSR_API(SrvOpenConsole)
     PCONSOLE_OPENCONSOLE OpenConsoleRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.OpenConsoleRequest;
     PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrGetClientThread()->Process);
 
-    DPRINT("SrvOpenConsole\n");
-
     OpenConsoleRequest->ConsoleHandle = INVALID_HANDLE_VALUE;
 
     RtlEnterCriticalSection(&ProcessData->HandleTableLock);
 
-    DPRINT1("ProcessData = 0x%p ; ProcessData->Console = 0x%p\n", ProcessData, ProcessData->Console);
-
     if (ProcessData->Console)
     {
         DWORD DesiredAccess = OpenConsoleRequest->Access;
@@ -529,9 +525,7 @@ CSR_API(SrvOpenConsole)
         PCONSOLE Console = ProcessData->Console;
         Object_t *Object;
 
-        DPRINT1("SrvOpenConsole - Checkpoint 1\n");
         EnterCriticalSection(&Console->Lock);
-        DPRINT1("SrvOpenConsole - Checkpoint 2\n");
 
         if (OpenConsoleRequest->HandleType == HANDLE_OUTPUT)
         {
@@ -575,8 +569,6 @@ CSR_API(SrvAllocConsole)
     PCSR_PROCESS CsrProcess = CsrGetClientThread()->Process;
     PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrProcess);
 
-    DPRINT("SrvAllocConsole\n");
-
     if (ProcessData->Console != NULL)
     {
         DPRINT1("Process already has a console\n");
@@ -632,7 +624,6 @@ CSR_API(SrvAllocConsole)
 
     /* Set the Ctrl Dispatcher */
     ProcessData->CtrlDispatcher = AllocConsoleRequest->CtrlDispatcher;
-    DPRINT("CONSRV: CtrlDispatcher address: %x\n", ProcessData->CtrlDispatcher);
 
     return STATUS_SUCCESS;
 }
@@ -646,8 +637,6 @@ CSR_API(SrvAttachConsole)
     HANDLE ProcessId = ULongToHandle(AttachConsoleRequest->ProcessId);
     PCONSOLE_PROCESS_DATA SourceProcessData, TargetProcessData;
 
-    DPRINT("SrvAttachConsole\n");
-
     TargetProcessData = ConsoleGetPerProcessData(TargetProcess);
 
     if (TargetProcessData->Console != NULL)
@@ -674,19 +663,15 @@ CSR_API(SrvAttachConsole)
             return Status;
         }
 
-        DPRINT("We, process (ID) %lu;%lu\n", TargetProcess->ClientId.UniqueProcess, TargetProcess->ClientId.UniqueThread);
         ProcessId = ULongToHandle(ProcessInfo.InheritedFromUniqueProcessId);
-        DPRINT("Parent process ID = %lu\n", ProcessId);
     }
 
     /* Lock the source process via its PID */
     Status = CsrLockProcessByClientId(ProcessId, &SourceProcess);
-    DPRINT1("Lock process Id %lu - Status %lu\n", ProcessId, Status);
     if (!NT_SUCCESS(Status)) return Status;
 
     SourceProcessData = ConsoleGetPerProcessData(SourceProcess);
 
-    DPRINT1("SourceProcessData->Console = 0x%p\n", SourceProcessData->Console);
     if (SourceProcessData->Console == NULL)
     {
         Status = STATUS_INVALID_HANDLE;
@@ -733,7 +718,6 @@ CSR_API(SrvAttachConsole)
 
     /* Set the Ctrl Dispatcher */
     TargetProcessData->CtrlDispatcher = AttachConsoleRequest->CtrlDispatcher;
-    DPRINT("CONSRV: CtrlDispatcher address: %x\n", TargetProcessData->CtrlDispatcher);
 
     Status = STATUS_SUCCESS;
 
@@ -762,8 +746,6 @@ CSR_API(SrvSetConsoleMode)
     PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleModeRequest;
     Object_t* Object = NULL;
 
-    DPRINT("SrvSetConsoleMode\n");
-
     Status = ConSrvGetObject(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
                                 ConsoleModeRequest->ConsoleHandle,
                                 &Object, NULL, GENERIC_WRITE, TRUE, 0);
@@ -797,8 +779,6 @@ CSR_API(SrvGetConsoleMode)
     PCONSOLE_GETSETCONSOLEMODE ConsoleModeRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.ConsoleModeRequest;
     Object_t* Object = NULL;
 
-    DPRINT("SrvGetConsoleMode\n");
-
     Status = ConSrvGetObject(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
                                 ConsoleModeRequest->ConsoleHandle,
                                 &Object, NULL, GENERIC_READ, TRUE, 0);
@@ -834,8 +814,6 @@ CSR_API(SrvSetConsoleTitle)
     PCONSOLE Console;
     PWCHAR Buffer;
 
-    DPRINT("SrvSetConsoleTitle\n");
-
     if (!CsrValidateMessageBuffer(ApiMessage,
                                   (PVOID)&TitleRequest->Title,
                                   TitleRequest->Length,
@@ -887,8 +865,6 @@ CSR_API(SrvGetConsoleTitle)
     PCONSOLE Console;
     DWORD Length;
 
-    DPRINT("SrvGetConsoleTitle\n");
-
     if (!CsrValidateMessageBuffer(ApiMessage,
                                   (PVOID)&TitleRequest->Title,
                                   TitleRequest->Length,
@@ -960,8 +936,6 @@ CSR_API(SrvGetConsoleHardwareState)
     PCONSOLE_SCREEN_BUFFER Buff;
     PCONSOLE Console;
 
-    DPRINT("SrvGetConsoleHardwareState\n");
-
     Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
                                   HardwareStateRequest->OutputHandle,
                                   &Buff,
@@ -988,8 +962,6 @@ CSR_API(SrvSetConsoleHardwareState)
     PCONSOLE_SCREEN_BUFFER Buff;
     PCONSOLE Console;
 
-    DPRINT("SrvSetConsoleHardwareState\n");
-
     Status = ConSrvGetScreenBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
                                   HardwareStateRequest->OutputHandle,
                                   &Buff,
@@ -1016,8 +988,6 @@ CSR_API(SrvGetConsoleWindow)
     PCONSOLE_GETWINDOW GetWindowRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.GetWindowRequest;
     PCONSOLE Console;
 
-    DPRINT("SrvGetConsoleWindow\n");
-
     Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
     if (!NT_SUCCESS(Status)) return Status;
 
@@ -1033,8 +1003,6 @@ CSR_API(SrvSetConsoleIcon)
     PCONSOLE_SETICON SetIconRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetIconRequest;
     PCONSOLE Console;
 
-    DPRINT("SrvSetConsoleIcon\n");
-
     Status = ConSrvGetConsole(ConsoleGetPerProcessData(CsrGetClientThread()->Process), &Console, TRUE);
     if (!NT_SUCCESS(Status)) return Status;
 
@@ -1103,8 +1071,6 @@ CSR_API(SrvGetConsoleProcessList)
     PLIST_ENTRY current_entry;
     ULONG nItems = 0;
 
-    DPRINT("SrvGetConsoleProcessList\n");
-
     if (!CsrValidateMessageBuffer(ApiMessage,
                                   (PVOID)&GetProcessListRequest->pProcessIds,
                                   GetProcessListRequest->nMaxIds,
index 2e10532..b80465a 100644 (file)
@@ -206,7 +206,7 @@ GuiDrawRegion(PCONSOLE Console, SMALL_RECT* Region);
 static NTSTATUS WINAPI
 GuiResizeBuffer(PCONSOLE Console, PCONSOLE_SCREEN_BUFFER ScreenBuffer, COORD Size);
 VOID FASTCALL
-GuiConsoleInitScrollbar(PGUI_CONSOLE_DATA GuiData);
+GuiConsoleResizeWindow(PGUI_CONSOLE_DATA GuiData);
 
 
 static LRESULT
@@ -482,10 +482,14 @@ GuiApplyUserSettings(PGUI_CONSOLE_DATA GuiData,
             SizeChanged = TRUE;
     }
 
+    GuiData->GuiInfo.AutoPosition = pConInfo->ci.u.GuiInfo.AutoPosition;
+    GuiData->GuiInfo.WindowOrigin = pConInfo->ci.u.GuiInfo.WindowOrigin;
+
     if (SizeChanged)
     {
+        /* Resize the window to the user's values */
         GuiData->WindowSizeLock = TRUE;
-        GuiConsoleInitScrollbar(GuiData);
+        GuiConsoleResizeWindow(GuiData);
         GuiData->WindowSizeLock = FALSE;
     }
 
@@ -514,15 +518,17 @@ GuiGetGuiData(HWND hWnd)
 
 VOID
 FASTCALL
-GuiConsoleInitScrollbar(PGUI_CONSOLE_DATA GuiData)
+GuiConsoleResizeWindow(PGUI_CONSOLE_DATA GuiData)
 {
     PCONSOLE Console = GuiData->Console;
     SCROLLINFO sInfo;
 
-    DWORD Width = Console->Size.X * GuiData->CharWidth + 2 * (GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXEDGE));
-    DWORD Height = Console->Size.Y * GuiData->CharHeight + 2 * (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYEDGE)) + GetSystemMetrics(SM_CYCAPTION);
+    DWORD Width  = Console->Size.X * GuiData->CharWidth  +
+                       2 * (GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXEDGE));
+    DWORD Height = Console->Size.Y * GuiData->CharHeight +
+                       2 * (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYEDGE)) + GetSystemMetrics(SM_CYCAPTION);
 
-    /* set scrollbar sizes */
+    /* Set scrollbar sizes */
     sInfo.cbSize = sizeof(SCROLLINFO);
     sInfo.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
     sInfo.nMin = 0;
@@ -548,14 +554,19 @@ GuiConsoleInitScrollbar(PGUI_CONSOLE_DATA GuiData)
         SetScrollInfo(GuiData->hWindow, SB_HORZ, &sInfo, TRUE);
         Height += GetSystemMetrics(SM_CYHSCROLL);
         ShowScrollBar(GuiData->hWindow, SB_HORZ, TRUE);
-
     }
     else
     {
         ShowScrollBar(GuiData->hWindow, SB_HORZ, FALSE);
     }
 
-    SetWindowPos(GuiData->hWindow, NULL, 0, 0, Width, Height,
+    /* Resize and reposition the window  */
+    SetWindowPos(GuiData->hWindow,
+                 NULL,
+                 (GuiData->GuiInfo.AutoPosition ? 0 : GuiData->GuiInfo.WindowOrigin.x),
+                 (GuiData->GuiInfo.AutoPosition ? 0 : GuiData->GuiInfo.WindowOrigin.y),
+                 Width,
+                 Height,
                  SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
 }
 
@@ -563,21 +574,21 @@ static BOOL
 GuiConsoleHandleNcCreate(HWND hWnd, LPCREATESTRUCTW Create)
 {
     PGUI_CONSOLE_DATA GuiData = (PGUI_CONSOLE_DATA)Create->lpCreateParams;
-    PCONSOLE Console = GuiData->Console;
+    PCONSOLE Console;
     HDC Dc;
     HFONT OldFont;
     TEXTMETRICW Metrics;
     SIZE CharSize;
 
-    GuiData->hWindow = hWnd;
-
     if (NULL == GuiData)
     {
-        DPRINT1("GuiConsoleNcCreate: RtlAllocateHeap failed\n");
+        DPRINT1("GuiConsoleNcCreate: No GUI data\n");
         return FALSE;
     }
 
-    InitializeCriticalSection(&GuiData->Lock);
+    Console = GuiData->Console;
+
+    GuiData->hWindow = hWnd;
 
     GuiData->Font = CreateFontW(LOWORD(GuiData->GuiInfo.FontSize),
                                 0, // HIWORD(GuiData->GuiInfo.FontSize),
@@ -593,11 +604,12 @@ GuiConsoleHandleNcCreate(HWND hWnd, LPCREATESTRUCTW Create)
                                 NONANTIALIASED_QUALITY,
                                 FIXED_PITCH | GuiData->GuiInfo.FontFamily /* FF_DONTCARE */,
                                 GuiData->GuiInfo.FaceName);
+
     if (NULL == GuiData->Font)
     {
         DPRINT1("GuiConsoleNcCreate: CreateFont failed\n");
-        DeleteCriticalSection(&GuiData->Lock);
-        RtlFreeHeap(ConSrvHeap, 0, GuiData);
+        GuiData->hWindow = NULL;
+        SetEvent(GuiData->hGuiInitEvent);
         return FALSE;
     }
     Dc = GetDC(GuiData->hWindow);
@@ -605,8 +617,8 @@ GuiConsoleHandleNcCreate(HWND hWnd, LPCREATESTRUCTW Create)
     {
         DPRINT1("GuiConsoleNcCreate: GetDC failed\n");
         DeleteObject(GuiData->Font);
-        DeleteCriticalSection(&GuiData->Lock);
-        RtlFreeHeap(ConSrvHeap, 0, GuiData);
+        GuiData->hWindow = NULL;
+        SetEvent(GuiData->hGuiInitEvent);
         return FALSE;
     }
     OldFont = SelectObject(Dc, GuiData->Font);
@@ -615,8 +627,8 @@ GuiConsoleHandleNcCreate(HWND hWnd, LPCREATESTRUCTW Create)
         DPRINT1("GuiConsoleNcCreate: SelectObject failed\n");
         ReleaseDC(GuiData->hWindow, Dc);
         DeleteObject(GuiData->Font);
-        DeleteCriticalSection(&GuiData->Lock);
-        RtlFreeHeap(ConSrvHeap, 0, GuiData);
+        GuiData->hWindow = NULL;
+        SetEvent(GuiData->hGuiInitEvent);
         return FALSE;
     }
     if (!GetTextMetricsW(Dc, &Metrics))
@@ -625,11 +637,11 @@ GuiConsoleHandleNcCreate(HWND hWnd, LPCREATESTRUCTW Create)
         SelectObject(Dc, OldFont);
         ReleaseDC(GuiData->hWindow, Dc);
         DeleteObject(GuiData->Font);
-        DeleteCriticalSection(&GuiData->Lock);
-        RtlFreeHeap(ConSrvHeap, 0, GuiData);
+        GuiData->hWindow = NULL;
+        SetEvent(GuiData->hGuiInitEvent);
         return FALSE;
     }
-    GuiData->CharWidth = Metrics.tmMaxCharWidth;
+    GuiData->CharWidth  = Metrics.tmMaxCharWidth;
     GuiData->CharHeight = Metrics.tmHeight + Metrics.tmExternalLeading;
 
     /* Measure real char width more precisely if possible. */
@@ -645,14 +657,14 @@ GuiConsoleHandleNcCreate(HWND hWnd, LPCREATESTRUCTW Create)
     Console->ActiveBuffer->ForceCursorOff = FALSE;
     ////////////////////////////////////////////////////////////////////////////
 
-    DPRINT("Console %p GuiData %p\n", Console, GuiData);
     SetWindowLongPtrW(GuiData->hWindow, GWLP_USERDATA, (DWORD_PTR)GuiData);
 
     SetTimer(GuiData->hWindow, CONGUI_UPDATE_TIMER, CONGUI_UPDATE_TIME, NULL);
     GuiConsoleCreateSysMenu(GuiData->hWindow);
 
+    /* Resize the window to the user's values */
     GuiData->WindowSizeLock = TRUE;
-    GuiConsoleInitScrollbar(GuiData);
+    GuiConsoleResizeWindow(GuiData);
     GuiData->WindowSizeLock = FALSE;
 
     SetEvent(GuiData->hGuiInitEvent);
@@ -1041,16 +1053,13 @@ GuiConsoleHandleClose(PGUI_CONSOLE_DATA GuiData)
 }
 
 static VOID
-GuiConsoleHandleNcDestroy(PGUI_CONSOLE_DATA GuiData, HWND hWnd)
+GuiConsoleHandleNcDestroy(PGUI_CONSOLE_DATA GuiData)
 {
-    PCONSOLE Console = GuiData->Console;
-
-    KillTimer(hWnd, 1);
-    Console->TermIFace.Data = NULL;
-    DeleteCriticalSection(&GuiData->Lock);
-    GetSystemMenu(hWnd, TRUE);
+    KillTimer(GuiData->hWindow, CONGUI_UPDATE_TIMER);
+    GetSystemMenu(GuiData->hWindow, TRUE);
 
-    RtlFreeHeap(ConSrvHeap, 0, GuiData);
+    SetWindowLongPtrW(GuiData->hWindow, GWLP_USERDATA, (DWORD_PTR)NULL);
+    GuiData->hWindow = NULL;
 }
 
 static COORD
@@ -1269,7 +1278,8 @@ GuiConsoleResize(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM lParam)
 {
     PCONSOLE Console = GuiData->Console;
 
-    if ((GuiData->WindowSizeLock == FALSE) && (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED || wParam == SIZE_MINIMIZED))
+    if ((GuiData->WindowSizeLock == FALSE) &&
+        (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED || wParam == SIZE_MINIMIZED))
     {
         PCONSOLE_SCREEN_BUFFER Buff = Console->ActiveBuffer;
         DWORD windx, windy, charx, chary;
@@ -1308,7 +1318,7 @@ GuiConsoleResize(PGUI_CONSOLE_DATA GuiData, WPARAM wParam, LPARAM lParam)
             Console->Size.Y = (chary <= Buff->ScreenBufferSize.Y) ? chary : Buff->ScreenBufferSize.Y;
         }
 
-        GuiConsoleInitScrollbar(GuiData);
+        GuiConsoleResizeWindow(GuiData);
 
         // Adjust the start of the visible area if we are attempting to show nonexistent areas
         if((Buff->ScreenBufferSize.X - Buff->ShowX) < Console->Size.X) Buff->ShowX = Buff->ScreenBufferSize.X - Console->Size.X;
@@ -1489,7 +1499,7 @@ GuiConsoleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
             break;
 
         case WM_NCDESTROY:
-            GuiConsoleHandleNcDestroy(GuiData, hWnd);
+            GuiConsoleHandleNcDestroy(GuiData);
             break;
 
         case WM_PAINT:
@@ -1642,18 +1652,21 @@ GuiConsoleNotifyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
                 TranslateMessage(&Msg);
                 DispatchMessageW(&Msg);
             }
-            DestroyWindow(GuiData->hWindow);
-            GuiData->hWindow = NULL;
 
-            WindowCount = GetWindowLongW(hWnd, GWL_USERDATA);
-            WindowCount--;
-            SetWindowLongW(hWnd, GWL_USERDATA, WindowCount);
-            if (0 == WindowCount)
+            if (GuiData->hWindow != NULL) /* && DestroyWindow(GuiData->hWindow) */
             {
-                NotifyWnd = NULL;
-                DestroyWindow(hWnd);
-                DPRINT1("CONSRV: Going to quit the Gui Thread!!\n");
-                PostQuitMessage(0);
+                DestroyWindow(GuiData->hWindow);
+
+                WindowCount = GetWindowLongW(hWnd, GWL_USERDATA);
+                WindowCount--;
+                SetWindowLongW(hWnd, GWL_USERDATA, WindowCount);
+                if (0 == WindowCount)
+                {
+                    NotifyWnd = NULL;
+                    DestroyWindow(hWnd);
+                    DPRINT1("CONSRV: Going to quit the Gui Thread!!\n");
+                    PostQuitMessage(0);
+                }
             }
 
             return 0;
@@ -1843,6 +1856,10 @@ GuiCleanupConsole(PCONSOLE Console)
         DPRINT1("Destroy hIconSm\n");
         DestroyIcon(GuiData->hIconSm);
     }
+
+    Console->TermIFace.Data = NULL;
+    DeleteCriticalSection(&GuiData->Lock);
+    RtlFreeHeap(ConSrvHeap, 0, GuiData);
 }
 
 static VOID WINAPI
@@ -2149,6 +2166,8 @@ GuiInitConsole(PCONSOLE Console,
     GuiData->Console = Console;
     GuiData->hWindow = NULL;
 
+    InitializeCriticalSection(&GuiData->Lock);
+
     /* Set up the GUI data */
     wcsncpy(GuiData->GuiInfo.FaceName, ConsoleInfo->u.GuiInfo.FaceName, LF_FACESIZE);
     GuiData->GuiInfo.FontFamily     = ConsoleInfo->u.GuiInfo.FontFamily;
@@ -2195,15 +2214,23 @@ GuiInitConsole(PCONSOLE Console,
      */
     GuiData->hGuiInitEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
 
-    /* Create the GUI console */
+    /* Create the terminal window */
     PostMessageW(NotifyWnd, PM_CREATE_CONSOLE, GuiData->GuiInfo.ShowWindow, (LPARAM)GuiData);
 
     /* Wait until initialization has finished */
     WaitForSingleObject(GuiData->hGuiInitEvent, INFINITE);
-    DPRINT1("Received event Console %p GuiData %p X %d Y %d\n", Console, GuiData, Console->Size.X, Console->Size.Y);
     CloseHandle(GuiData->hGuiInitEvent);
     GuiData->hGuiInitEvent = NULL;
 
+    /* Check whether we really succeeded in initializing the terminal window */
+    if (GuiData->hWindow == NULL)
+    {
+        DPRINT1("GuiInitConsole - We failed at creating a new terminal window\n");
+        // ConioCleanupConsole(Console);
+        GuiCleanupConsole(Console);
+        return STATUS_UNSUCCESSFUL;
+    }
+
     return STATUS_SUCCESS;
 }
 
index 9c1536c..e2d2521 100644 (file)
@@ -598,14 +598,8 @@ ConSrvNewProcess(PCSR_PROCESS SourceProcess,
 
     PCONSOLE_PROCESS_DATA SourceProcessData, TargetProcessData;
 
-    DPRINT1("ConSrvNewProcess\n");
-    DPRINT1("SourceProcess = 0x%p ; TargetProcess = 0x%p\n", SourceProcess, TargetProcess);
-
     /* An empty target process is invalid */
-    if (!TargetProcess)
-        return STATUS_INVALID_PARAMETER;
-
-    DPRINT1("ConSrvNewProcess - OK\n");
+    if (!TargetProcess) return STATUS_INVALID_PARAMETER;
 
     TargetProcessData = ConsoleGetPerProcessData(TargetProcess);
 
@@ -624,8 +618,7 @@ ConSrvNewProcess(PCSR_PROCESS SourceProcess,
     RtlInitializeCriticalSection(&TargetProcessData->HandleTableLock);
 
     /* Do nothing if the source process is NULL */
-    if (!SourceProcess)
-        return STATUS_SUCCESS;
+    if (!SourceProcess) return STATUS_SUCCESS;
 
     SourceProcessData = ConsoleGetPerProcessData(SourceProcess);
 
@@ -644,10 +637,6 @@ ConSrvNewProcess(PCSR_PROCESS SourceProcess,
         /* Temporary save the parent's console */
         TargetProcessData->ParentConsole = SourceProcessData->Console;
     }
-    else
-    {
-        DPRINT1("ConSrvNewProcess - We don't inherit a handle table : SourceProcessData->Console = 0x%p ; TargetProcess->Flags = %lu\n", SourceProcessData->Console, TargetProcess->Flags);
-    }
 
     return STATUS_SUCCESS;
 }
@@ -666,8 +655,6 @@ ConSrvConnect(IN PCSR_PROCESS CsrProcess,
     PCONSOLE_CONNECTION_INFO ConnectInfo = (PCONSOLE_CONNECTION_INFO)ConnectionInfo;
     PCONSOLE_PROCESS_DATA ProcessData = ConsoleGetPerProcessData(CsrProcess);
 
-    DPRINT1("ConSrvConnect\n");
-
     if ( ConnectionInfo       == NULL ||
          ConnectionInfoLength == NULL ||
         *ConnectionInfoLength != sizeof(CONSOLE_CONNECTION_INFO) )
@@ -743,7 +730,6 @@ ConSrvConnect(IN PCSR_PROCESS CsrProcess,
 
     /* Set the Ctrl Dispatcher */
     ProcessData->CtrlDispatcher = ConnectInfo->CtrlDispatcher;
-    DPRINT("CONSRV: CtrlDispatcher address: %x\n", ProcessData->CtrlDispatcher);
 
     return STATUS_SUCCESS;
 }