RedirectIOToConsole

torhu no at spam.invalid
Wed May 28 11:29:18 PDT 2008


steve wrote:
> why does this code snippet refuse to work under D : http://www.halcyon.com/~ast/dload/guicon.htm ?
> 
> lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
> hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
> fp = _fdopen( hConHandle, "w" );
> 
> the last line wont give a result but null ? is there something to note when translating this to D ?
> 
> Thanks for any hints!

Thanks for the handy link.  The type long in D is 64 bits, so it won't 
be correct on a 32-bit system.  GetStdHandle's return type is HANDLE, so 
it's better to use that instead.

Something like this:

HANDLE lStdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
fp = _fdopen( hConHandle, "w" );

If that doesn't help, you need to post some more context, and maybe try 
to figure out on which line the error is.

Also make sure that GetStdHandle is declared with extern (Windows).  I'm 
not sure about _open_osfhandle, but msdn.com seems to say to it's extern 
(C).


More information about the Digitalmars-d-learn mailing list