summaryrefslogtreecommitdiffstats
path: root/chrome/app
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/app')
-rw-r--r--chrome/app/chrome_dll_main.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/chrome/app/chrome_dll_main.cc b/chrome/app/chrome_dll_main.cc
index c08e109..7100464e 100644
--- a/chrome/app/chrome_dll_main.cc
+++ b/chrome/app/chrome_dll_main.cc
@@ -13,8 +13,11 @@
#include <algorithm>
#include <atlbase.h>
#include <atlapp.h>
+#include <fcntl.h>
+#include <io.h>
#include <malloc.h>
#include <new.h>
+#include <process.h>
#elif defined(OS_POSIX)
#include <locale.h>
#include <signal.h>
@@ -319,6 +322,19 @@ void RegisterInvalidParamHandler() {
#endif
}
+#if defined(OS_WIN)
+void SetupStdHandle(DWORD name, int target_fd, FILE* target_fp) {
+ HANDLE handle = GetStdHandle(name);
+ if (handle && handle != INVALID_HANDLE_VALUE) {
+ int fd = _open_osfhandle(reinterpret_cast<intptr_t>(handle), _O_TEXT);
+ if (fd != -1) {
+ _dup2(fd, target_fd);
+ target_fp->_file = target_fd;
+ }
+ }
+}
+#endif
+
void SetupCRT(const CommandLine& parsed_command_line) {
#if defined(OS_WIN)
#ifdef _CRTDBG_MAP_ALLOC
@@ -341,6 +357,12 @@ void SetupCRT(const CommandLine& parsed_command_line) {
HeapSetInformation(crt_heap, HeapCompatibilityInformation,
&enable_lfh, sizeof(enable_lfh));
}
+
+ // Attach to an existing console if one exists, and connect up the CRT
+ // handles for stdout/stderr.
+ AttachConsole(ATTACH_PARENT_PROCESS);
+ SetupStdHandle(STD_OUTPUT_HANDLE, 1, stdout);
+ SetupStdHandle(STD_ERROR_HANDLE, 2, stderr);
#endif
}