root/trunk/orca/win32/win32console.c

Revision 108, 1.6 kB (checked in by krobillard, 3 years ago)

Orca-GL should now build on Windows.

Line 
1#include <windows.h>
2#include <stdio.h>
3#include <fcntl.h>
4#include <io.h>
5
6#ifdef __cplusplus
7#include <iostream>
8#include <fstream>
9using namespace std;
10#endif
11
12
13// maximum mumber of lines the output console should have
14#define MAX_CONSOLE_LINES   500
15
16
17void redirectIOToConsole()
18{
19    int hConHandle;
20    long lStdHandle;
21    CONSOLE_SCREEN_BUFFER_INFO coninfo;
22    FILE* fp;
23
24    // allocate a console for this app
25    AllocConsole();
26
27    // set the screen buffer to be big enough to let us scroll text
28    GetConsoleScreenBufferInfo( GetStdHandle(STD_OUTPUT_HANDLE), &coninfo );
29
30    coninfo.dwSize.Y = MAX_CONSOLE_LINES;
31    SetConsoleScreenBufferSize( GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize );
32
33    // redirect unbuffered STDOUT to the console
34    lStdHandle = (long) GetStdHandle(STD_OUTPUT_HANDLE);
35    hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
36    fp = _fdopen( hConHandle, "w" );
37    *stdout = *fp;
38    setvbuf( stdout, NULL, _IONBF, 0 );
39
40    // redirect unbuffered STDIN to the console
41    lStdHandle = (long) GetStdHandle(STD_INPUT_HANDLE);
42    hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
43    fp = _fdopen( hConHandle, "r" );
44    *stdin = *fp;
45    setvbuf( stdin, NULL, _IONBF, 0 );
46
47    // redirect unbuffered STDERR to the console
48    lStdHandle = (long) GetStdHandle(STD_ERROR_HANDLE);
49    hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
50    fp = _fdopen( hConHandle, "w" );
51    *stderr = *fp;
52    setvbuf( stderr, NULL, _IONBF, 0 );
53
54#ifdef __cplusplus
55    // make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog
56    // point to console as well
57    ios::sync_with_stdio();
58#endif
59}
60
61
62/*EOF*/
Note: See TracBrowser for help on using the browser.