Results 1 to 26 of 26

Thread: [RESOLVED] How do I 'wait' for ShellExecute to finish

Hybrid View

  1. #1

    Thread Starter
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: How do I 'wait' for ShellExecute to finish

    woohoo, working code at last:-
    declarations Code:
    1. Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
    2. Private Const SYNCHRONIZE = &H100000
    3. Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    4. Private Declare Function OpenProcess Lib "kernel32" (ByVal dwAccess As Long, ByVal fInherit As Integer, ByVal hObject As Long) As Long

    event code Code:
    1. Private Sub picSheetInner_DblClick()
    2.     Dim strExecutable As String
    3.     Dim lngPID As Long
    4.     Dim lngReturn As Long
    5.     Dim strSend As String
    6. On Error GoTo errHandler
    7.     strExecutable = Space$(256)
    8.     Call FindExecutable(Mid$(mstrImagePath, InStrRev(mstrImagePath, "\") + 1), Left$(mstrImagePath, InStrRev(mstrImagePath, "\") - 1), strExecutable)
    9.     strExecutable = Left$(strExecutable, InStr(strExecutable, vbNull) - 1)
    10.     strSend = strExecutable & " """ & mstrImagePath & """"
    11.     Let lngPID = Shell(strSend)
    12.     Let lngPID = OpenProcess(SYNCHRONIZE, False, lngPID)
    13.     Do
    14.         Let lngReturn = WaitForSingleObject(lngPID, 0)
    15.         DoEvents
    16.     Loop While lngReturn <> 0
    17.     Exit Sub
    18. errHandler:
    19.     Call hmferErrors.faimErrors(Err, "picSheetInner_DblClick", "frmPaper2", , gstrUserName, , App.EXEName)
    20.     End
    21. End Sub

    Thanks to all for your help, particularly Rhino, DNA and Ellis.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  2. #2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width