Subject: Re: win/winMain.c -- main() and WinMain() are mutually exclusive - DN [1]
Scott Redman <scott.redman@bigfoot.com> - 13 Nov 1999 - comp.lang.tcl
You've stumbled across my double-secret Console-wish code...
On Windows, you can write a Windows app with -subsystem:console
that has a main(), which calls WinMain(). I've done this
before, and it's especially useful knowledge when porting to
Unix with MainWin.
The code is intended to be used to build a Console-based
version of wish that doesn't use the "Tk Console", but
rather the Win32 console. It solves a number of issues,
but has the annoying side-effect of creating an extra
Win32 Console window for Wish when it's launched from
the Start menu or from a window shortcut.
When you build with -subsystem:windows, Windows will disconnect
your application from stdin/stdout/stderr if they are a Win32
console. Rather annoying, but if it's a File handle (or pretty
much anything else), Windows won't disconnect. This means
that (starting with Tcl/Tk 8.1) you can pipe stdout from wish
into a file.
I've considered the possibility of having to versions of
wish installed, one built with -subsystem:windows as it
normally is, but called "wish-win.exe". Shortcuts will
hide the name, and file associations will use it.
Then, install a version built with -subsystem:console
and call it "wish.exe". It works beautifully when you
run "wish" from a console. If anyone thinks this is a
good idea, send email to the WinTcl mailing list
(wintcl@scriptics.com).
-- Scott
David Gravereaux wrote:
>
> I was just nosing around the code and noticed something in the comments of
> main():
>
> * main --
> *
> * Main entry point from the console.
>
> I don't think that's correct. An executable can only have one entry-point. Is
> main() here to be used with an alternate link step (aka -subsystem:console) ??
>
> The only thing different between main() and WinMain() is setting a flag for
> whether the console widget should be started or not later in Tk_Init(). It
> might be a nice feature to have the tclsh style console when cranked-up from the
> command prompt. It could break scripts though (??)
>
> Just for the fun of it, I was trying methods to discover if a WinMain can detect
> if it was started from the console, but no luck trapping it.
>
> STARTUPINFO si;
> HANDLE StdOut;
>
> si.cb = sizeof(STARTUPINFO);
> GetStartupInfo(&si);
> StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
>
> if (si.hStdOutput != StdOut) {
> // inherited handle isn't the default
> }
>
> That didn't work in a WinMain. Nor did this:
>
> CONSOLE_SCREEN_BUFFER_INFO csbi; /* used to get cursor position */
>
> GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
> if (csbi.dwCursorPosition.X | csbi.dwCursorPosition.Y) {
> // non-zero cursor position
> }
>
> Anyone know of any tricks to see if a -subsystem:windows app was started from an
> interactive console prompt?
>
> --
> * David Gravereaux *
> Tomahawk Software Group
Last modified
1999-11-17
1999-11-17
(195.108.246.50)
Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated
