extern BOOL WINAPI DefaultConsoleCtrlHandler(DWORD Event);
extern __declspec(noreturn) VOID CALLBACK ConsoleControlDispatcher(DWORD CodeAndFlag);
-
-extern BOOL FASTCALL NlsInit();
-extern VOID FASTCALL NlsUninit();
+extern PHANDLER_ROUTINE InitialHandler[1];
+extern PHANDLER_ROUTINE* CtrlHandlers;
+extern ULONG NrCtrlHandlers;
+extern ULONG NrAllocatedHandlers;
+extern BOOL FASTCALL NlsInit(VOID);
+extern VOID FASTCALL NlsUninit(VOID);
BOOLEAN InWindows = FALSE;
HANDLE
CSR_API_MESSAGE Request;
ULONG CsrRequest;
NTSTATUS Status;
+ BOOLEAN NotConsole = FALSE;
PRTL_USER_PROCESS_PARAMETERS Parameters = NtCurrentPeb()->ProcessParameters;
+ LPCWSTR ExeName;
WCHAR lpTest[MAX_PATH];
GetModuleFileNameW(NULL, lpTest, MAX_PATH);
{
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;
+ Request.Data.AllocConsoleRequest.Visible = 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)
{
- Parameters->ConsoleHandle = 0;
+ /* We'll get the real one soon */
+ DPRINT("Creating new invisible console\n");
+ Parameters->ConsoleHandle = NULL;
+ Request.Data.AllocConsoleRequest.Visible = FALSE;
+ }
+ 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 */
+ /* Initialize Console Ctrl Handler and input EXE name */
ConsoleInitialized = TRUE;
RtlInitializeCriticalSection(&ConsoleLock);
- SetConsoleCtrlHandler(DefaultConsoleCtrlHandler, TRUE);
-
+ NrAllocatedHandlers = 1;
+ NrCtrlHandlers = 1;
+ CtrlHandlers = InitialHandler;
+ CtrlHandlers[0] = DefaultConsoleCtrlHandler;
+
+ ExeName = wcsrchr(Parameters->ImagePathName.Buffer, L'\\');
+ if (ExeName)
+ SetConsoleInputExeNameW(ExeName + 1);
+
/* Now use the proper console handle */
Request.Data.AllocConsoleRequest.Console = Parameters->ConsoleHandle;
* 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;
/* 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))
wcscpy(SystemDirectory.Buffer, WindowsDirectory.Buffer);
wcscat(SystemDirectory.Buffer, L"\\System32");
+ /* Initialize command line */
+ InitCommandLines();
+
/* Open object base directory */
Status = OpenBaseDirectory(&hBaseDir);
if (!NT_SUCCESS(Status))
}
#undef InterlockedIncrement
+#undef InterlockedDecrement
+#undef InterlockedExchange
+#undef InterlockedExchangeAdd
+#undef InterlockedCompareExchange
+
LONG
WINAPI
InterlockedIncrement(IN OUT LONG volatile *lpAddend)
return _InterlockedIncrement(lpAddend);
}
-#undef InterlockedDecrement
LONG
WINAPI
InterlockedDecrement(IN OUT LONG volatile *lpAddend)
return _InterlockedDecrement(lpAddend);
}
-#undef InterlockedExchange
LONG
WINAPI
InterlockedExchange(IN OUT LONG volatile *Target,
return _InterlockedExchange(Target, Value);
}
-#undef InterlockedExchangeAdd
LONG
WINAPI
InterlockedExchangeAdd(IN OUT LONG volatile *Addend,
return _InterlockedExchangeAdd(Addend, Value);
}
-#undef InterlockedCompareExchange
LONG
WINAPI
InterlockedCompareExchange(IN OUT LONG volatile *Destination,