Skinnysite.net

... un modo di esprimersi.

Font Size

Cpanel

Homa Page di Daniele Franceschini

Chiamare in modo sincrono un eseguibile esterno

Valutazione attuale:  / 1
ScarsoOttimo 

'Inserire questo codice in un modulo di VB
Option Explicit
' RikShell - by Rik 8/5/98
' Come funzione Shell, il programma VB resta in attesa
' che il programma lanciato termini.

Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long

Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hprocess As Long, _
lpExitCode As Long) As Long

Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long

Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400

Function RikShell(exe As String, Optional WinStyle) As Integer
Dim ProcessID As Long
Dim hprocess As Long
Dim exitcode As Long
Dim parm As Integer

' Controllo il parametro opzionale finestra
Select Case VarType(WinStyle)
Case vbEmpty, vbNull, vbError
parm = vbNormalFocus
Case vbLong, vbInteger, vbSingle, vbDouble
parm = WinStyle
Case Else
parm = vbNormalFocus
End Select

' Prelevo l'ID del processo lanciato
ProcessID = Shell(exe, parm)

' Creo un Handle per quel processo
hprocess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessID)
Do
' Controllo ripetutamente che termini
Call GetExitCodeProcess(hprocess, exitcode)
' Lascio libero il sistema di processare le altre applicazioni
DoEvents
Loop While (exitcode = STILL_ACTIVE)

CloseHandle (hprocess)

End Function

 

Sei qui: Home Code Snippets Visual Basic 6 Chiamare in modo sincrono un eseguibile esterno