|
From: Norm on 26 Jun 2008 16:49 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. :-) Thanks, Norm
From: Karl E. Peterson on 26 Jun 2008 17:06 Norm wrote: > 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
From: Norm on 26 Jun 2008 18:07 "Karl E. Peterson" <karl(a)mvps.org> wrote in message news:eTo5IC91IHA.3860(a)TK2MSFTNGP05.phx.gbl... > Norm wrote: > > 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
From: Karl E. Peterson on 26 Jun 2008 18:16 Norm wrote: > "Karl E. Peterson" <karl(a)mvps.org> wrote ... >> Norm wrote: >> > 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. > > 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. Ah, well, ShellExecute isn't an executable. It's an API, just like CreateProcess. ShellExecute Function () http://msdn.microsoft.com/en-us/library/bb762153(VS.85).aspx In order to use CreateProcess, you'll have to tell it which process to create. The utility of ShellExecute is that it does the registry lookup for you to find the associated application for your datafile. -- ..NET: It's About Trust! http://vfred.mvps.org
From: Norm on 26 Jun 2008 19:11
Boy talk about feeling like a dummy. :-) I guess it takes a while for this to sink in. Using IExplore.exe works just fine. Thanks, Norm |