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