Microsoft Access modSystem

From database24
Revision as of 13:32, 20 July 2010 by Dec (talk | contribs) (→‎= waitForShell)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

waitForShell

Declaration

Private Declare Function CloseHandle Lib "kernel32" ( _
    ByVal hObject As Long _
    ) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" ( _
    ByVal hProcess As Long, _
    ExitCode As Long _
    ) As Long
Private Declare Function OpenProcess Lib "kernel32" ( _
    ByVal DesiredAccess As Long, _
    ByVal InheritHandle As Long, _
    ByVal ProcessId As Long _
    ) As Long

Code

Public Function waitForShell( _
    strExecute As String, _
    Optional lngWindowStyle As VbAppWinStyle = vbMinimizedFocus _
    ) As Long

    Dim lngTaskId As Long
    Dim lngHProcess As Long
    Dim lngExitCode As Long

    Const STILL_ACTIVE = &H103
    Const PROCESS_QUERY_INFORMATION = &H400

    lngTaskId = Shell(strExecute, lngWindowStyle)
    lngHProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, lngTaskId)
    Do
        DoEvents
        GetExitCodeProcess lngHProcess, lngExitCode
    Loop While lngExitCode = STILL_ACTIVE
    CloseHandle lngHProcess
    waitForShell = lngExitCode
End Function