Question about Larry Rebich's ShellAndWait
Quote:
> > I have been trying to get the ShellAndWait routine written by Larry
Rebich
> > located here
> > http://www.buygold.net/tips.html
> > to open a jpg file within a program, but I have not been able to get it
to
> > work.
> > Passing the path of the jpg to CreateProcess returns the value of zero,
but
> > the same path works in ShellExecute.
> > Is there anyway to get CreateProcess to open a jpg file or am I missing
> > something, which is usually the case. :-)
> CreateProcess does just that. You'll need to pass the name of the
executable you
> want to start. As I recall, it also supports a command line, so if that
app
> supports passing a filename you'll be all set.
> --
> .NET: It's About Trust!
> http://vfred.mvps.org
Karl,
I have tried this without success, where sCommand contains the path to the
jpg file
and I am not using any of the log functions. You might have to full screen
your reader
to see the full lines.
Norm
Public Function ShellAndWait(tShellAndWait As udtShellAndWait) As Boolean
' 1998/10/07 Add optional log and times
' 1998/10/27 Add DoEvents to allow the process to be terminated. Move
tProcess to caller.
Dim lRtn As Long
Dim iFN As Integer
Dim lMilliseconds As Long
With tShellAndWait
.dStart = Now 'started now
.bTerminated = False 'set not terminated yet into
structure
.dTerminated = 0 'not terminated at this point
lMilliseconds = .lMilliseconds 'local variable
If lMilliseconds <= 0 Then 'zero or negative then use 1
second
lMilliseconds = mclMillisecondsDefault 'default
End If
If .bNoTerminate Then 'don't allow terminate
.lMilliseconds = INFINITE 'set to never return
End If
.bShellAndWaitRunning = True 'started
' Initialize the STARTUPINFO structure:
.tStart.cb = Len(.tStart)
' Start the shelled application: sCommand = Path to jpg file
lRtn = CreateProcessA("ShellExecute", .sCommand, 0&, 0&, 1&,
NORMAL_PRIORITY_CLASS, 0&, 0&, .tStart, .tProcess)
' Wait for the shelled application to finish:
Do
lRtn = WaitForSingleObject(.tProcess.hProcess, lMilliseconds)
'wait milliseconds
If lRtn <> WAIT_TIMEOUT Then
Exit Do
End If
DoEvents 'allow other processes
Loop While True
lRtn = CloseHandle(.tProcess.hProcess)
If lRtn <> 0 Then
ShellAndWait = True 'report success
End If
.bShellAndWaitRunning = False 'ended
On Error GoTo ShellAndWaitExit 'skip log if any error
.dFinish = Now
.dDiff = .dFinish - .dStart
If .bLogFile Then 'write the log
KillLogFileIfTooBig tShellAndWait 'can't let it get too
big
iFN = FreeFile 'get a file handle
Open .sLogFile For Append As iFN 'Add to an existing file
Print #iFN, Format$(.dStart, "general date"); ", "; 'started
Print #iFN, Format$(.dFinish, "general date"); ", ";
'finished
Print #iFN, Format$(.dDiff, "Hh.Nn.Ss"); " ";
'duration
Print #iFN, .sCommand 'command executed
Close #iFN
End If
End With
ShellAndWaitExit:
End Function