<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>RE: [gambit-list] Calling from C on Windows</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>Hi Marc,</FONT>
</P>
<P><FONT SIZE=2>It works fine now. </FONT>
<BR><FONT SIZE=2>Thank you very much.</FONT>
</P>
<P><FONT SIZE=2>Regards,</FONT>
<BR><FONT SIZE=2>Dan.</FONT>
</P>
<BR>
<P><FONT SIZE=2>-----Original Message-----</FONT>
<BR><FONT SIZE=2>From: Marc Feeley [<A HREF="mailto:feeley@IRO.UMontreal.CA">mailto:feeley@IRO.UMontreal.CA</A>] </FONT>
<BR><FONT SIZE=2>Sent: Saturday, March 19, 2005 9:05 AM</FONT>
<BR><FONT SIZE=2>To: dhristodorescu@borderfree.com</FONT>
<BR><FONT SIZE=2>Cc: gambit-list@IRO.UMontreal.CA</FONT>
<BR><FONT SIZE=2>Subject: Re: [gambit-list] Calling from C on Windows</FONT>
</P>
<P><FONT SIZE=2>I fixed the bug. You need to change the USE_WIN32 section in</FONT>
<BR><FONT SIZE=2>___os_device_stream_open_predefined to this:</FONT>
</P>
<P><FONT SIZE=2> switch (___INT(index))</FONT>
<BR><FONT SIZE=2> {</FONT>
<BR><FONT SIZE=2> case -4:</FONT>
<BR><FONT SIZE=2> open_console:</FONT>
<BR><FONT SIZE=2> {</FONT>
<BR><FONT SIZE=2> ___device_tty *d;</FONT>
</P>
<P><FONT SIZE=2> if ((e = ___device_tty_setup_console</FONT>
<BR><FONT SIZE=2> (&d,</FONT>
<BR><FONT SIZE=2> io_mod.dgroup,</FONT>
<BR><FONT SIZE=2> direction))</FONT>
<BR><FONT SIZE=2> != ___FIX(___NO_ERR))</FONT>
<BR><FONT SIZE=2> return e;</FONT>
</P>
<P><FONT SIZE=2> dev = ___CAST(___device_stream*,d);</FONT>
</P>
<P><FONT SIZE=2> break;</FONT>
<BR><FONT SIZE=2> }</FONT>
</P>
<P><FONT SIZE=2> default:</FONT>
<BR><FONT SIZE=2> {</FONT>
<BR><FONT SIZE=2> switch (___INT(index))</FONT>
<BR><FONT SIZE=2> {</FONT>
<BR><FONT SIZE=2> default:</FONT>
<BR><FONT SIZE=2> case -1:</FONT>
<BR><FONT SIZE=2> h = GetStdHandle (STD_INPUT_HANDLE);</FONT>
<BR><FONT SIZE=2> break;</FONT>
<BR><FONT SIZE=2> case -2:</FONT>
<BR><FONT SIZE=2> h = GetStdHandle (STD_OUTPUT_HANDLE);</FONT>
<BR><FONT SIZE=2> break;</FONT>
<BR><FONT SIZE=2> case -3:</FONT>
<BR><FONT SIZE=2> h = GetStdHandle (STD_ERROR_HANDLE);</FONT>
<BR><FONT SIZE=2> break;</FONT>
<BR><FONT SIZE=2> }</FONT>
</P>
<P><FONT SIZE=2> if (h == INVALID_HANDLE_VALUE)</FONT>
<BR><FONT SIZE=2> return err_code_from_GetLastError ();</FONT>
</P>
<P><FONT SIZE=2> if (GetFileType (h) == FILE_TYPE_UNKNOWN)</FONT>
<BR><FONT SIZE=2> goto open_console;</FONT>
</P>
<P><FONT SIZE=2>...</FONT>
</P>
<P><FONT SIZE=2>The bug occurs on Windows when the Gambit runtime is being run as a</FONT>
<BR><FONT SIZE=2>windowed application (no problem in console applications). In a</FONT>
<BR><FONT SIZE=2>windowed application the GetStdHandle calls (which are meant to return</FONT>
<BR><FONT SIZE=2>the standard input/output/error) return a handle whose type is not</FONT>
<BR><FONT SIZE=2>recognized by Gambit (it is not a file, a pipe, a socket, a console,</FONT>
<BR><FONT SIZE=2>or a serial port). This caused the runtime to terminate. The fix</FONT>
<BR><FONT SIZE=2>adds a check for the handle type and associates a console window to</FONT>
<BR><FONT SIZE=2>stdin/out/err if their type is unknown. So for windowed applications</FONT>
<BR><FONT SIZE=2>any "standard I/O" from Scheme will go to a freshly created console</FONT>
<BR><FONT SIZE=2>(unless stdin/out/err were redirected).</FONT>
</P>
<P><FONT SIZE=2>Marc</FONT>
</P>
</BODY>
</HTML>