
calling external .exe program from VB
Quote:
> Hi,
> I'm writing an application which generates txt file which is an input file
> for an external exe program. This external program (command line win32
> application) then writes it's results into another txt file which my
> application reads.
> The problem is, I want my application to wait for external program to finish
> before trying to read in results.
> Please help. Thanx, Igor
> PS
> I tried using Shell function but in this case my program starts external
> app. and moves on before this program gives any output.
Try this code, just put in bas and you can call it just as you would
of called the shell fucn...
Const STILL_ACTIVE = &H103
Const PROC_QUERY_INFO = &H400
Declare Function SmOpenProcess Lib "kernel32" Alias "OpenProcess"
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal
dwProcessId As Long) As Long
Declare Function SmGetExitCodeProcess Lib "kernel32" Alias
"GetExitCodeProcess" (ByVal hProcess As Long, lpExitCode As Long) As
Long
Declare Function SmCloseHandle Lib "kernel32" Alias "CloseHandle"
(ByVal hObject As Long) As Long
Private lngDummy As Long
Global objMainSettings As clsMainSettings
Sub ShellModal(ByVal PathName As String, Optional ByVal WindowStyle As
Variant)
Dim lngProcessId As Long
Dim lnghProcess As Long
Dim lngExitCode As Long
lngProcessId = Shell(PathName, WindowStyle)
lnghProcess = SmOpenProcess(PROC_QUERY_INFO, False,
lngProcessId)
Do
SmGetExitCodeProcess lnghProcess, lngExitCode
lngDummy = DoEvents
Loop While lngExitCode = STILL_ACTIVE
SmCloseHandle lnghProcess
End Sub