kernel32: Moved initialisation of the console handles to DllMain.
diff --git a/dlls/kernel/kernel_main.c b/dlls/kernel/kernel_main.c
index dea83b2..f6eeba9 100644
--- a/dlls/kernel/kernel_main.c
+++ b/dlls/kernel/kernel_main.c
@@ -97,6 +97,7 @@
 static BOOL process_attach(void)
 {
     SYSTEM_INFO si;
+    RTL_USER_PROCESS_PARAMETERS *params = NtCurrentTeb()->Peb->ProcessParameters;
 
     /* FIXME: should probably be done in ntdll */
     GetSystemInfo( &si );
@@ -108,6 +109,25 @@
     /* Setup computer name */
     COMPUTERNAME_Init();
 
+    /* convert value from server:
+     * + 0 => INVALID_HANDLE_VALUE
+     * + console handle needs to be mapped
+     */
+    if (!params->hStdInput)
+        params->hStdInput = INVALID_HANDLE_VALUE;
+    else if (VerifyConsoleIoHandle(console_handle_map(params->hStdInput)))
+        params->hStdInput = console_handle_map(params->hStdInput);
+
+    if (!params->hStdOutput)
+        params->hStdOutput = INVALID_HANDLE_VALUE;
+    else if (VerifyConsoleIoHandle(console_handle_map(params->hStdOutput)))
+        params->hStdOutput = console_handle_map(params->hStdOutput);
+
+    if (!params->hStdError)
+        params->hStdError = INVALID_HANDLE_VALUE;
+    else if (VerifyConsoleIoHandle(console_handle_map(params->hStdError)))
+        params->hStdError = console_handle_map(params->hStdError);
+
     /* copy process information from ntdll */
     ENV_CopyStartupInformation();
 
@@ -127,7 +147,7 @@
     /* finish the process initialisation for console bits, if needed */
     __wine_set_signal_handler(SIGINT, CONSOLE_HandleCtrlC);
 
-    if (NtCurrentTeb()->Peb->ProcessParameters->ConsoleHandle == (HANDLE)1)  /* FIXME */
+    if (params->ConsoleHandle == (HANDLE)1)  /* FIXME */
     {
         HMODULE mod = GetModuleHandleA(0);
         if (RtlImageNtHeader(mod)->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)