delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/11/21/18:24:08

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Message-ID: <4744BDFB.8000402@factorcode.org>
Date: Wed, 21 Nov 2007 18:23:39 -0500
From: Slava Pestov <slava AT factorcode DOT org>
User-Agent: Thunderbird 2.0.0.9 (Windows/20071031)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Problem with win32 GUI application using console
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019