WaitForSingleObject infinite loop

G

Guest

Hello, everyone. I noticed that there is another developer out there
(Just.in) that is or was experiencing almost the exact same issue that I am
currently facing. However, I did not see any responses to the question so I
am going to post my own.

I have a VBA app that calls the CreateProcessA and WaitForSingleObject API
functions. On my XP machine it works fine (the functions are used to
auto-ftp a set of files). Also, on a different W2k machine it works fine.
However, on the particular machine on which I need it to work (also W2k) it
does not. The app gets stuck in an infinite loop on the WaitForSingleObject
function and I am forced to use the Task Manager to kill the process. Here
is the code for your reference:

Public Sub ShellWait(Pathname As String, Optional WindowStyle As Long)
On Error GoTo Err_Handler

Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret As Long

' Initialize the STARTUPINFO structure:
With start
.cb = Len(start)
If Not IsMissing(WindowStyle) Then
.dwFlags = STARTF_USESHOWWINDOW
.wShowWindow = WindowStyle
End If
End With
' Start the shelled application:
ret& = CreateProcessA(0&, Pathname, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS,
0&, 0&, start, proc)
' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
ret& = CloseHandle(proc.hProcess)

Exit_Here:
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "E R R O R"
Resume Exit_Here

End Sub

Any ideas as to why it would not work on a particular machine?

Thanks in advance for any assistance you can provide.

cmack
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top