printf to allocated console 
Author Message
 printf to allocated console

If I create a console app using "/subsystem:console" as
linker setting, I can use printf to output text to the
console.
However, if I use "/subsystem:windows" and then call
AllocConsole(), printf doesn't output text to the run-time
allocated console.
What's the solution?


Sun, 27 Feb 2005 14:30:49 GMT  
 printf to allocated console


Quote:
> If I create a console app using "/subsystem:console" as
> linker setting, I can use printf to output text to the
> console.
> However, if I use "/subsystem:windows" and then call
> AllocConsole(), printf doesn't output text to the run-time
> allocated console.
> What's the solution?

AllocConsole();

int hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT);

FILE * hf = _fdopen( hCrt, "w" );

*stdout = *hf;

setvbuf( stdout, NULL, _IONBF, 0 );

// Luc K



Sun, 27 Feb 2005 15:22:04 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Win32 and Console (printf??)

2. WOWTO: console stdout/printf and GUI-based MFC application

3. printf for console mode

4. WOWTO: console stdout/printf and GUI-based MFC application

5. printf vs message box in semi console app

6. replacing printf with my printf, then calling C lib's printf

7. (void)printf() vs. printf()

8. Re(2): Re(2): (void)printf() vs. printf()

9. Re(2): (void)printf() vs. printf()

10. Running Console process without console ?

11. Executing a console application without it opening a console

12. Starting a console application without the console window

 

 
Powered by phpBB® Forum Software