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 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 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , 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 #include #include #include 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/