Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Running a GUI app in CONSOLE mode, alternatives to AttachConsole() and .com file

251 views
Skip to first unread message

Pieter

unread,
Mar 16, 2004, 11:09:06 PM3/16/04
to
I have a GUI windows app, that I want to make behave like a console app.
When my app receives certain commandline arguments I want it to print output
in the context of the console from where it was spawned. E.g. certain
commandline arguments must print the usage to the console screen.

I know of two choices:
1) Use AttachConsole(), but AttachConsole() is only available on XP+
See:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/attachconsole.asp
2) Create a .com binary that will spawn the .exe binary.
See: http://msdn.microsoft.com/msdnmag/issues/04/02/CQA/default.aspx

Are there any alternatives?
(AttachConsole() like behavior on Win98+ systems would be a big win).


Regards

Pieter


Tim Roberts

unread,
Mar 17, 2004, 3:16:14 AM3/17/04
to
"Pieter" <msn...@insanegenius.com> wrote:
>
>I have a GUI windows app, that I want to make behave like a console app.
>When my app receives certain commandline arguments I want it to print output
>in the context of the console from where it was spawned. E.g. certain
>commandline arguments must print the usage to the console screen.

You could just make it a console app. Console apps can register windows
and have message loops. Of course, that means the command line won't
return until the program ends.

>I know of two choices:
>1) Use AttachConsole(), but AttachConsole() is only available on XP+

>...


>2) Create a .com binary that will spawn the .exe binary.

>...


>
>Are there any alternatives?
>(AttachConsole() like behavior on Win98+ systems would be a big win).

I don't believe so. All of the Microsoft tools that print a usage string
do so in a MessageBox.
--
- Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc

qfel

unread,
Mar 17, 2004, 8:04:15 AM3/17/04
to
If executable doesn't use console subsystem it doesn't inherit parent's console.
If executable uses console subsystem it's forced to have one, so it looks funny
if you create normal window..


Rhett Gong [MSFT]

unread,
Mar 19, 2004, 1:46:38 AM3/19/04
to
Hi Pieter,
They have some differences in the EXEheader which contains a field called 'Subsystem'. The 'Subsystem' field determines both the subsystem the application is to
run under and the type of interface it requires. If it is a GUI app, Subsystem is IMAGE_SUBSYSTEM_WINDOWS_GUI. If it is a console app the Subsystem is
IMAGE_SUBSYSTEM_WINDOWS_CUI 3.

VisualStudio has two binaries: devenv.com and devenv.exe. Devenv.com is a Console app. Devenv.exe is a GUI app. This has been illustrated in the msdn mag
article: http://msdn.microsoft.com/msdnmag/issues/04/02/CQA/default.aspx

There is a great blog on this subject from Junfeng Zhang's blog. I believe you may have interest in it. Here is the link:
http://blogs.msdn.com/junfeng/archive/2004/02/06/68531.aspx

Best regards,
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.

Pieter

unread,
Mar 19, 2004, 3:53:30 PM3/19/04
to
Thank you,
anybody with ideas on a Win98 AttachConsole(), I am still interested.

Pieter

"Rhett Gong [MSFT]" <v-ra...@online.microsoft.com> wrote in message
news:E0%23Dx3XD...@cpmsftngxa06.phx.gbl...

0 new messages