Re: How do you inherit DOS console in Win32 application?

From: Jim Carlock (anonymous_at_127.0.0.1)
Date: 03/18/04


Date: Thu, 18 Mar 2004 06:20:34 GMT


"e^ln(x)" <e^ln(x)@mîcôsÿêñ.com> wrote:
> How do you inherit and continue using the existing command-line
> console in a Win32 assembly console application?

I'm not sure if this will help at all but I'm going to suggest something
and it's based from coding in VB.6, so I'm nowhere near as qualified
as the other people in the message group but I know what I'm saying.

The following procedure call defines the way to start up an external
application. In this case, for any NT class OS (XP, 2K, NT3.1 on
up), the code below will call and bring up a command prompt
window. I'm not quite sure how to throw text into it though, as
if you're typing commands into the DOS prompt... but maybe
it'll give you some ideas.

Declare Function GetDesktopWindow Lib "user32.dll" () As Long
Declare Function ShellExecute Lib "shell32.dll" _
  Alias "ShellExecuteA" _
  (ByVal hWnd As Long, ByVal lpOperation As String, _
   ByVal lpFile As String, ByVal lpParameters As String, _
   ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

All Long variables are 32 bit (signed numbers in VB, but we're not
using it in arithmetic, so it's a pointer). The Strings are all ASCII
here, no Unicode.

The GetDeskTopWindow API retrieves a handle to the Desktop
Window.

If your app is calling the command prompt, the parameters will
appear as follows:

Const SW_NORMAL = &H1

Dim hWnd As Long, iDummy As Long, sCmd As String
Dim iSuccess As Long, sFile As String
sCmd = "cmd.exe"
sFile = vbNullString
iSuccess = ShellExecute(GetDesktopWindow, "open", sCmd, _
  sFile, vbNullString, SW_NORMAL)

Note: vbNullString is a string with an initial null value, ie Chr(0).

sCmd would be the name of the program you'd like to run. For
a 9x system, the name would be: sCmd = "command.com"

If you'd like the cmd.exe to be tied to your app, you'd pass an
hWnd of your app window instead of using GetDeskTopWindow.

HTH.

-- 
Jim Carlock
http://www.microcosmotalk.com/
Post replies to the newsgroup.
Borland C and MVC both do this automatically and hide the startup code from
the debugger.  Every Windoze console application inherits the DOS console
when invoked from the command line, but I can't figure out how to do it.
I've been through the Windoze SDK from one end to the other and have found
no
suggestions or example code.  Does anybody have any hints?
Alternatively, does anyone have c0nt.asm from the Borland CBuilder package?
That is alleged to be the startup code used by the compiler.
TIA.


Relevant Pages

  • Re: String from char[] with null termination.
    ... > When I run it from the command line, ... but not how different results can come from the same compiler. ... When you test the code from the command line, the console ... console view handles it by considering it the end of the string and not ...
    (comp.lang.java.programmer)
  • Event Messages arent being directed to the console port
    ... In addition, I can type an event message at the command line, and the Console Works application, then gets the string and alarms on it. ...
    (Tru64-UNIX-Managers)
  • Command line parameter question
    ... a console application as a command line? ... I'm aware of the String array on Main, but this parses the string to ... have to produce an application which accepts command line arguments ...
    (microsoft.public.dotnet.framework)
  • TIP #185: Null Handling
    ... nulls, and command modifications for manipulating them. ... Tcl deals with strings, the universal medium for representing data. ... is know and it is an empty string, but if a respondent forgets to give ...
    (comp.lang.tcl)
  • Re: Determine how Word was launched
    ... inspect the command line used to launch Word. ... Private Declare Function GetCommandLineA Lib "kernel32" As Long ... Public Function GetCommandLineAs String ... Dim lngCmdLinePtr As Long ...
    (microsoft.public.office.developer.vba)