Re: Get parent's console?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Vincent Fatica (abuse_at_localhost.com)
Date: 01/25/05


Date: 25 Jan 2005 16:53:10 -0500

On Tue, 25 Jan 2005 18:05:53 -0000, "James Brown"
<remove_james_dot_brown7_at_virgin_dot_net> wrote:

>I struggled with AttachConsole under XP, the problem seemed to be
>that the C-runtime stdio handles weren't set correctly, so things like
>printf / fgets just didn't work properly.

After AttachConsole(), set up whatever crt std handles and file descriptors
you will use like this (shown for stdout):

   /* AttachConsole(...); */
   int hCrt;
   FILE *hf;
   hCrt = _open_osfhandle(
             (long) GetStdHandle(STD_OUTPUT_HANDLE),
             _O_TEXT
          );
   hf = _fdopen( hCrt, "w" );
   *stdout = *hf;
   i = setvbuf( stdout, NULL, _IONBF, 0 );

-- 
 - Vince


Relevant Pages

  • Re: fgets question
    ... documentation didn't say if fgets put \0 after a string literal. ... If fgets runs out of room it will stop one short ... printf strlen); ... One more character than what was typed printf reported. ...
    (comp.lang.c)
  • Re: fgets question
    ... documentation didn't say if fgets put \0 after a string literal. ... If fgets runs out of room it will stop one short ... printf strlen); ... One more character than what was typed printf reported. ...
    (comp.lang.c)
  • Re: How do I print a 0 in the beginning?
    ... int main ... I have tried using %06d, %.5i, %.5d in the printf statement. ... the thing was i couldn't use functions like fgets() or sscanf. ... Only allowed to use scanf() and printf. ...
    (comp.lang.c)
  • Re: Console output from MFC dialog based app
    ... In console application we achieve this using functions like printf(), ... Under XP you can use AttachConsole like ... extension and a GUI one with a .exe extension. ...
    (microsoft.public.vc.mfc)
  • Re: Console output from MFC dialog based app
    ... In console application we achieve this using functions like printf(), ... Under XP you can use AttachConsole like ... extension and a GUI one with a .exe extension. ...
    (microsoft.public.vc.mfc)