tags:

views:

427

answers:

3

When creating a process in VB6 (related to this question:), I'm using the following struct:

Private Type STARTUPINFO
      cb As Long
      lpReserved As String
      lpDesktop As String
      lpTitle As String
      dwX As Long
      dwY As Long
      dwXSize As Long
      dwYSize As Long
      dwXCountChars As Long
      dwYCountChars As Long
      dwFillAttribute As Long
      dwFlags As Long
      wShowWindow As Integer
      cbReserved2 As Integer
      lpReserved2 As Long
      hStdInput As Long
      hStdOutput As Long
      hStdError As Long
   End Type

Before I start my process, what needs to happen to STARTUPINFO.hStdOutput in order for my VB6 app to read the output of my hosted process?

Thanks!!

+2  A: 

Microsoft gives here an example on how to do it.

MicSim
Excellent, thanks! I also found this example (which is similar): http://www.visualbasic.happycodings.com/Graphics_Games_Programming/code3.html
Pwninstein
A: 

See AttachConsole(ATTACH_PARENT_PROCESS)

Matt Davison
+3  A: 

Following up this other question by the OP, I post an alternative method to execute a command and get hold of stdout:

' References: "Windows Script Host Shell Object Model" '

Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" ( _
  ByVal dwMilliseconds As Long)

Function ExecuteCommand(cmd As String, ExpectedResult as Long) As String
  Dim shell As New IWshRuntimeLibrary.WshShell
  Dim exec As IWshRuntimeLibrary.WshExec

  Set exec = shell.Exec(cmd)
  While exec.Status = 0
     Sleep 100
  Wend

  If exec.ExitCode = ExpectedResult Then
    ExecuteCommand = exec.StdOut.ReadAll
  Else
    ExecuteCommand = vbNullString     ' or whatever '
  End
End Function
Tomalak
Excellent, Thanks!!
Pwninstein
This works perfectly! Thanks! Is there a way to hide the window (in this case, a console window) during the child process' execution?
Pwninstein
I'm afraid not. For some reason, only the "shell.Run" method can hide the window. But there you won't get hold of stdout. If ignoring the window is not an option for you, you are back at the Win32 API call method again.
Tomalak
I think I solved this issue: I'm going to build my .NET application (the child process) as a Windows Application (instead of a Console Application). This way, no UI is shown.
Pwninstein
That's one way you could do it. :-) You could also try to expose the .NET application to COM and use it directly.
Tomalak