Make Your VB App Wait Tip
Derek E. Brown sends in this tip that should be very useful in a number of situations that can arise. The tip involves making a VB app
wait for the completion of some other process outside VB. While Derek has a specific purpose in mind for this one, it should be fairly easy to modify
for a number of different situations.
I found this to be an extremely useful piece of code for running an application from within VB and having the VB app wait until the outside
process is complete. I have a program that has to wait until an uploaded zip file is unzipped before continued processing can take place. The code below
involves a few API's, and though it's rather long and involved, I have yet to get an error using it.
'**************************************
'Windows API/Global Declarations for :Un'zipper
'**************************************
Private Const ZIPSIG = &H4034B50
Private Const ziputil = "c:\Program Files\PKUnzip\Pkzip25.exe"
Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = &HFFFFFFFF
'API's to monitor the status of Pkzip
Private Declare Function OpenProcess Lib "kernel32" (ByVal DesiredAccess As Long, _ ByVal bInheritHandle As Long, ByVal ProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle
As Long, _ ByVal Milliseconds As Long) As Long Private Declare Function CloseHandle Lib
"kernel32" (ByVal hObject As Long) As Long
Private Type ZFHeader
Signature As Long
End Type
***********************************
Private Sub sb_WaitForTemination(RetVl As Integer)
On Error Goto ErrorHandler:
Dim phnd&
phnd = OpenProcess(SYNCHRONIZE, 0, RetVl)
If phnd <> 0 Then
Call WaitForSingleObject(phnd, INFINITE)
Call CloseHandle(phnd)
End If
Exit Sub
ErrorHandler:
Err.Source = "sb_WaitForTermination in class Unzip in UnZipper"
'Do Error Stuff Here
Resume Next
End Sub