[Ecls-list] Patch to prevent crash on Windows GUI applications

Dan Hristodorescu dhristodorescu at borderfree.com
Sun Aug 28 08:55:37 UTC 2005


Hi,

I'm working on a plugin for a Windows application and I noticed there is
a problem when creating a GUI application because the stdin, stdout and
stderr streams are invalid and ECL tries to use them.
Based on what I've seen done in GambitC to solve this problem I propose
this patch to the file src/c/file.d after the variable initialization in
init_file():

void
init_file(void)
{
	cl_object standard_input;
	cl_object standard_output;
	cl_object error_output;
	cl_object standard;
	cl_object x;
//----- this is the new code -----------------
#if defined(_MSC_VER) || defined(mingw32)
  HANDLE h = GetStdHandle (STD_OUTPUT_HANDLE);
  if (GetFileType (h) == FILE_TYPE_UNKNOWN)
  {
    AllocConsole();
    freopen("CONOUT$", "a", stdout);
    freopen("CONIN$", "r", stdin);
  }
#endif
//--------------------------------------------
.....

Basically in GUI mode the handles to stdout, stdin and stderr are of an
invalid type. The code will then create a console and redirect input and
output to the newly created console allowing user interaction (like
debugging). The stderr by default is sent to stdout in console.
Any console version of a program won't be affected by this patch and it
would work like before.

Thanks,
Dan Hristodorescu.





More information about the ecl-devel mailing list