From: Norm Cook on
"Steve" <stevegdula(a)yahoo.com> wrote in message
news:bac32b19-ac88-4234-956a-84f347ff5cb6(a)b23g2000yqn.googlegroups.com...
>I am creating a fairly straight forward VB6 interface which will
> utilize
> another external application's command line features. This is kind
> of
> the reverse use for command lines, as I am not creating them for use
> with my VB6 app, but want to send command line instructions to the
> external 3rd party app which has nice command line functionality for
> dealing with image formats.
>
> The only way I can think to accomplish this is by the following
> process:
> (1) Write the command line to a text file with a *.bat extension.
> (2) Shell Execute the batch file.
> (3) Handle the results of the command line operation.
> (4) Loop back to (1) as many times as necessary until complete.
>
> I'm thinking there has to be a more refined way to feed command line
> arguements to this application. Any insight?
>
> Thank you,
>
> ~Steve

Here's some code that does a shell & wait which I have
used for several years. Usage:
Call ExecCmd(CmdWithParams) ' e. g. "SomeApp.exe /b /a"

Private Const INFINITE = -1&
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
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
Private Type TFolder
TName As String
TDate As Date
End Type
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long)
As Long
Private Declare Function CreateProcessA Lib "kernel32" (ByVal
lpApplicationName As String, ByVal lpCommandLine As String, ByVal
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal
bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment
As Long, ByVal lpCurrentDirectory As String, lpStartupInfo As STARTUPINFO,
lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess
As Long, lpExitCode As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle
As Long, ByVal dwMilliseconds As Long) As Long

Public Function ExecCmd(ByVal CmdLine As String)
Dim Proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO
Dim Ret As Long
Start.cb = Len(Start)
Ret = CreateProcessA(vbNullString, CmdLine, 0&, 0&, 1&,
NORMAL_PRIORITY_CLASS, 0&, vbNullString, Start, Proc)
Ret = WaitForSingleObject(Proc.hProcess, INFINITE)
Call GetExitCodeProcess(Proc.hProcess, Ret)
Call CloseHandle(Proc.hThread)
Call CloseHandle(Proc.hProcess)
ExecCmd = Ret
End Function