diff --git a/reactos/dll/win32/kernel32/misc/console.c b/reactos/dll/win32/kernel32/misc/console.c index 13961ad6631..e535e77f4d4 100644 --- a/reactos/dll/win32/kernel32/misc/console.c +++ b/reactos/dll/win32/kernel32/misc/console.c @@ -39,6 +39,7 @@ BOOL WINAPI DefaultConsoleCtrlHandler(DWORD Event) { + DPRINT1("Default handler called: %lx\n", Event); switch(Event) { case CTRL_C_EVENT: @@ -75,7 +76,8 @@ ConsoleControlDispatcher(DWORD CodeAndFlag) DWORD nCode = CodeAndFlag & MAXLONG; UINT i; EXCEPTION_RECORD erException; - + + DPRINT1("Console Dispatcher Active: %lx %lx\n", CodeAndFlag, nCode); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); switch(nCode) @@ -152,6 +154,7 @@ ConsoleControlDispatcher(DWORD CodeAndFlag) (CodeAndFlag & MINLONG) && ((nCode == CTRL_LOGOFF_EVENT) || (nCode == CTRL_SHUTDOWN_EVENT))) { + DPRINT1("Skipping system/service apps\n"); break; } @@ -172,7 +175,6 @@ ConsoleControlDispatcher(DWORD CodeAndFlag) } RtlLeaveCriticalSection(&ConsoleLock); - ExitThread(nExitCode); } diff --git a/reactos/dll/win32/kernel32/misc/dllmain.c b/reactos/dll/win32/kernel32/misc/dllmain.c index 7d08667205b..a828f72ef5a 100644 --- a/reactos/dll/win32/kernel32/misc/dllmain.c +++ b/reactos/dll/win32/kernel32/misc/dllmain.c @@ -128,6 +128,7 @@ BasepInitConsole(VOID) CSR_API_MESSAGE Request; ULONG CsrRequest; NTSTATUS Status; + BOOLEAN NotConsole = FALSE; PRTL_USER_PROCESS_PARAMETERS Parameters = NtCurrentPeb()->ProcessParameters; WCHAR lpTest[MAX_PATH]; @@ -143,39 +144,41 @@ BasepInitConsole(VOID) { DPRINT("Image is not a console application\n"); Parameters->ConsoleHandle = NULL; - return TRUE; - } - - /* Assume one is needed */ - Request.Data.AllocConsoleRequest.ConsoleNeeded = TRUE; - - /* Handle the special flags given to us by BasepInitializeEnvironment */ - if (Parameters->ConsoleHandle == HANDLE_DETACHED_PROCESS) - { - /* No console to create */ - DPRINT("No console to create\n"); - Parameters->ConsoleHandle = NULL; Request.Data.AllocConsoleRequest.ConsoleNeeded = FALSE; } - else if (Parameters->ConsoleHandle == HANDLE_CREATE_NEW_CONSOLE) - { - /* We'll get the real one soon */ - DPRINT("Creating new console\n"); - Parameters->ConsoleHandle = NULL; - } - else if (Parameters->ConsoleHandle == HANDLE_CREATE_NO_WINDOW) - { - /* We'll get the real one soon */ - DPRINT1("NOT SUPPORTED: HANDLE_CREATE_NO_WINDOW\n"); - Parameters->ConsoleHandle = NULL; - } else { - if (Parameters->ConsoleHandle == INVALID_HANDLE_VALUE) + /* Assume one is needed */ + Request.Data.AllocConsoleRequest.ConsoleNeeded = TRUE; + + /* Handle the special flags given to us by BasepInitializeEnvironment */ + if (Parameters->ConsoleHandle == HANDLE_DETACHED_PROCESS) { - Parameters->ConsoleHandle = 0; + /* No console to create */ + DPRINT("No console to create\n"); + Parameters->ConsoleHandle = NULL; + Request.Data.AllocConsoleRequest.ConsoleNeeded = FALSE; + } + else if (Parameters->ConsoleHandle == HANDLE_CREATE_NEW_CONSOLE) + { + /* We'll get the real one soon */ + DPRINT("Creating new console\n"); + Parameters->ConsoleHandle = NULL; + } + else if (Parameters->ConsoleHandle == HANDLE_CREATE_NO_WINDOW) + { + /* We'll get the real one soon */ + DPRINT1("NOT SUPPORTED: HANDLE_CREATE_NO_WINDOW\n"); + Parameters->ConsoleHandle = NULL; + } + else + { + if (Parameters->ConsoleHandle == INVALID_HANDLE_VALUE) + { + Parameters->ConsoleHandle = 0; + } + DPRINT("Using existing console: %x\n", Parameters->ConsoleHandle); } - DPRINT("Using existing console: %x\n", Parameters->ConsoleHandle); } /* Initialize Console Ctrl Handler */ @@ -185,7 +188,7 @@ BasepInitConsole(VOID) NrCtrlHandlers = 1; CtrlHandlers = InitialHandler; CtrlHandlers[0] = DefaultConsoleCtrlHandler; - + /* Now use the proper console handle */ Request.Data.AllocConsoleRequest.Console = Parameters->ConsoleHandle; @@ -194,9 +197,6 @@ BasepInitConsole(VOID) * but we don't have one yet, so we will instead simply send a create * console message to the Base Server. When we finally have a Console * Server, this code should be changed to send connection data instead. - * - * Also note that this connection should be made for any console app, even - * in the case above where -we- return. */ CsrRequest = MAKE_CSR_API(ALLOC_CONSOLE, CSR_CONSOLE); Request.Data.AllocConsoleRequest.CtrlDispatcher = ConsoleControlDispatcher; @@ -210,6 +210,8 @@ BasepInitConsole(VOID) /* We're lying here, so at least the process can load... */ return TRUE; } + + if (NotConsole) return TRUE; /* We got the handles, let's set them */ if ((Parameters->ConsoleHandle = Request.Data.AllocConsoleRequest.Console))