Chris@404: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
Chris@404: 
Chris@404: /*
Chris@404:     Sonic Visualiser
Chris@404:     An audio file viewer and annotation editor.
Chris@404:     Centre for Digital Music, Queen Mary, University of London.
Chris@404:     This file copyright 2006 Chris Cannam.
Chris@404:     
Chris@404:     This program is free software; you can redistribute it and/or
Chris@404:     modify it under the terms of the GNU General Public License as
Chris@404:     published by the Free Software Foundation; either version 2 of the
Chris@404:     License, or (at your option) any later version.  See the file
Chris@404:     COPYING included with this distribution for more information.
Chris@404: */
Chris@404: 
Chris@404: #include <iostream>
Chris@404: 
Chris@658: #include <qglobal.h>
Chris@658: 
Chris@404: #ifdef Q_WS_WIN32
Chris@404: 
Chris@404: #include <fcntl.h>
Chris@658: 
Chris@658: // required for SetDllDirectory
Chris@658: #define _WIN32_WINNT 0x0502
Chris@404: #include <windows.h>
Chris@404: 
Chris@404: // Set default file open mode to binary
Chris@404: //#undef _fmode
Chris@404: //int _fmode = _O_BINARY;
Chris@404: 
Chris@404: void redirectStderr()
Chris@404: {
Chris@658: #ifdef NO_PROBABLY_NOT
Chris@404:     HANDLE stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
Chris@404:     if (!stderrHandle) return;
Chris@404: 
Chris@404:     AllocConsole();
Chris@404: 
Chris@404:     CONSOLE_SCREEN_BUFFER_INFO info;
Chris@404:     GetConsoleScreenBufferInfo(stderrHandle, &info);
Chris@404:     info.dwSize.Y = 1000;
Chris@404:     SetConsoleScreenBufferSize(stderrHandle, info.dwSize);
Chris@404: 
Chris@404:     int h = _open_osfhandle((long)stderrHandle, _O_TEXT);
Chris@404:     if (h) {
Chris@404:         FILE *fd = _fdopen(h, "w");
Chris@404:         if (fd) {
Chris@404:             *stderr = *fd;
Chris@404:             setvbuf(stderr, NULL, _IONBF, 0);
Chris@404:         }
Chris@404:     }
Chris@658: #endif
Chris@404: }
Chris@404: 
Chris@404: #endif
Chris@404: 
Chris@404: extern void svSystemSpecificInitialisation()
Chris@404: {
Chris@404: #ifdef Q_WS_WIN32
Chris@404:     redirectStderr();
Chris@658: 
Chris@658:     // Remove the CWD from the DLL search path, just in case
Chris@658:     SetDllDirectory(L"");
Chris@658:     putenv("PATH=");
Chris@404: #else
Chris@404: #endif
Chris@404: }
Chris@404: 
Chris@404: 
Chris@404: