
VB5 and Shelling a DOS program...Used to use getmoduleusage but not for 32bit
Here's some code I picked up somewhere... (simple huh?)
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle
As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess
As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess
As Long, lpExitCode As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long)
As Long
Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400
Const INFINITE = &HFFFF
Const WAIT_FAILED = &HFFFFFFFF
Const PROCESS_ALL_ACCESS = &H1F0FFF
Function SyncShell(ByVal strProgName As String, Optional ByVal WaitDead As
Boolean) As Long
Dim cRead As Long
Dim iExit As Long
Dim hProg As Long
Dim idProg As Long
idProg = Shell(strProgName, vbNormalNoFocus)
' Get process handle
hProg = OpenProcess(PROCESS_ALL_ACCESS, False, idProg)
If WaitDead Then
' Stop dead until process terminates
Dim iResult As Long
iResult = WaitForSingleObject(hProg, INFINITE)
If iResult = WAIT_FAILED Then Err.Raise Err.LastDllError
' Get the return value
GetExitCodeProcess hProg, iExit
Else
' Get the return value
GetExitCodeProcess hProg, iExit
' Wait, but allow painting and other processing
Do While iExit = STILL_ACTIVE ' And Not TerminateApp
Sleep 1000
GetExitCodeProcess hProg, iExit
Loop
End If
CloseHandle hProg
SyncShell = iExit
End Function
Quote:
>Hi,
>Okay, in the old days, (16bit apps), I used to do the following for any
>DOS (yuck!) commands/programs that I need to shell to:
>batchfile = "whatever.exe"
>batchstat = Shell(batchfile, 1)
>Do
> x = DoEvents()
>loop While getmodulehandle(batchfile) > 0
>But, now when I look for the API getmodulehandle in 32bit form, there is
>none.
>Does someone have an example/idea how to do this via VB5?
>Thanks in advance...
>Geo...