This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem with win32 GUI application using console


Hi everybody,

I'm building a native Win32 GUI application which should be able to display a console on demand for debugging purposes. I found that my program was crashing when compiled with Cygwin, however it worked fine with Visual Studio.

Here is the output of gcc --version:

gcc (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I narrowed the problem down to a short test case. Here goes:

-------------------------

/* Compile with -mno-cygwin -mwindows */

#include <windows.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>

int APIENTRY WinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPTSTR lpCmdLine,
	int nCmdShow)
{
	if(!AllocConsole())
		exit(1);
	HANDLE h = GetStdHandle((intptr_t)STD_OUTPUT_HANDLE);
	if(h == INVALID_HANDLE_VALUE)
		exit(2);
	int fd = _open_osfhandle(h,_O_TEXT);
	if(fd == -1)
		exit(3);
	FILE *fp = _fdopen(fd,"w");
	if(!fp)
		exit(4);
	fprintf(fp,"Hello world\n");
	fflush(fp);
	exit(0);
}

-------------------------

Let me know if you need any additional information.

Cheers

Slava

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]