[gambit-list] Gambit on Windows with no console window

Marc Feeley feeley at iro.umontreal.ca
Thu Apr 12 16:44:19 EDT 2012


On 2012-04-11, at 6:46 PM, REPLeffect wrote:

> On Tue, Apr 10, 2012 at 5:37 PM, Marc Feeley <feeley at iro.umontreal.ca> wrote:
>> 
>> On 2012-04-10, at 3:13 PM, REPLeffect wrote:
>> 
>>> I had already been running my app with -:d-, but somehow missed -:d0
>>> -- that almost gives me what I want (by suppressing the error
>>> messages).  However, I have some messages in my app that are being
>>> sent to stdout, and even with -:d0, the console is still being shown
>>> by these.  Of course, the AllocConsole call is the culprit.
>> 
>> Can you explain this a bit more.  I don't understand why the output would go to the console if you write to stdout.  Can you verify that this is the case?  Note that the pp procedure defaults to writing to the REPL port.
>> 
> 
> I am actually using println (not pp) in the messages that are causing
> the console to open.
> 
> I was able to reproduce the problem by modifying Mikael's MessageBox
> example.  This version opens the message box, then once the message
> box is closed, it prints to stdout once each second for 10 seconds:
> 
> (c-declare "#include <windows.h>")
> (define message-box (c-lambda (UTF-8-string) void
> "MessageBox(0,___arg1,\"Dbg\",0);"))
> (message-box "Hi!")
> (let loop ((count 0))
>  (println "test stdout")
>  (thread-sleep! 1)
>  (if (< count 10)
>    (loop (+ count 1))))
> 
> I saved that as test.scm, and compiled it under MinGW like this:
> 
> gsc -link test.scm
> 
> g++ -c -I"C:/Gambit-C/include" -I"C:/Gambit-C/lib"
>   -D___SINGLE_HOST -D_WINDOWS test_.c test.c
> 
> g++ -mthreads -Wl,-subsystem,windows -o test.exe test.o
>   test_.o -LC:/Gambit-C/lib -lgambc -L. -lkernel32
>   -luser32 -lgdi32 -lmingw32 -lws2_32
> 
> When I run test.exe, the message box appears, then I click 'OK' and
> the console appears, displaying the line "test stdout" 10 times (once
> per second).

To simplify the build steps I built your test program 2 ways, as a "console" application and a "windows" application:

1) gsc -exe test.scm

2) gsc -exe -ld-options "-Wl,-subsystem,windows" test.scm

When I do

   ./test > out

the dialog is shown and the output "test stdout" goes to the file "out" in both cases.

When I have no redirection of stdout, i.e.:

   ./test

then after the dialog is dismissed, the "console" version outputs "test stdout" to the console from which the program was started, and the "windows" version opens a new console for writing the output.

I believe the difference in this case is due to the way Windows assigns a "console" to a program when it is started (i.e. whether it is a "console" application or a "windows" application).  If I recall correctly, "windows" applications aren't assigned a console when they are started and they don't have a default stdin/stdout.

My question is this: is it important that your application be a "windows" application?  What are the benefits over a "console" application.

In any case, since you are not interested in the output to the current output port, this difference can be eliminated by assigning a dummy port to the current output port.

Marc




More information about the Gambit-list mailing list