# Include <fcntl. h>
# Include <Io. h>
//-------------
// Function name: stdpipe
// Objective: to embed a window in winmain
//-------------
Int stdconsole ()
{
Allocconsole ();
Hin = getstdhandle (std_input_handle );
Hout = getstdhandle (std_output_handle );
Herr = getstdhandle (std_error_handle );
Setconsoletitle ("embedded cmd ");
File * HF = NULL;
Char Buf [2];
// Output
Int hcrt = 0;
Hcrt = (long) _ open_osfhandle (intptr_t) Hout, _ o_text );
HF = _ fdopen (hcrt, "W"); // indicates writable
Setvbuf (HF, Buf, _ ionbf, 1 );
* Stdout = * Hf;
// Input
Int hcirt = 0;
Hcirt = _ open_osfhandle (intptr_t) Hin, _ o_text );
File * hfin = NULL;
Hfin = _ fdopen (hcirt, "R ");
Setvbuf (hfin, Buf, _ ionbf, 1 );
* Stdin = * hfin;
// Error
Int hert = 0;
Hert = _ open_osfhandle (intptr_t) Herr, _ o_text );
File * hferr = NULL;
Hferr = _ fdopen (hert, "W ");
Setvbuf (hferr, Buf, _ ionbf, 1 );
* Stderr = * hferr;
Return 0;
}