Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongOption Explicit
Private Sub Command1_Click()
Dim ProcessId As Long
ProcessId = Shell("E:\Console2\Debug\Console1.exe", 1)'启动FORTRAN 计算程序,并隐藏DOS 窗口
Do While StillRun(ProcessId)
'调用StillRun 函数监视外部程序Console1. exe 的运行状态
DoEvents
Loop
End SubPublic Function StillRun(ByVal ProcessId) As Boolean'定义一个判断外壳程序运行状态的函数
Dim HProgram As Long'ProgramID 是Shell 函数的返回值(即外部程序的进程号)HProgram = OpenProcess(0, False, ProcessId)
'返回被测程序的句柄hProgram
If Not HProgram = 0 Then '外部程序还在运行
StillRun = True
Else '外部程序运行结束
StillRun = False
End If
CloseHandle (HProgram)
End Function
我用这个程序调用一个EXE文件,但是最后不会生成输出文件,请问问题出在哪呀?
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongOption Explicit
Private Sub Command1_Click()
Dim ProcessId As Long
ProcessId = Shell("E:\Console2\Debug\Console1.exe", 1)'启动FORTRAN 计算程序,并隐藏DOS 窗口
Do While StillRun(ProcessId)
'调用StillRun 函数监视外部程序Console1. exe 的运行状态
DoEvents
Loop
End SubPublic Function StillRun(ByVal ProcessId) As Boolean'定义一个判断外壳程序运行状态的函数
Dim HProgram As Long'ProgramID 是Shell 函数的返回值(即外部程序的进程号)HProgram = OpenProcess(0, False, ProcessId)
'返回被测程序的句柄hProgram
If Not HProgram = 0 Then '外部程序还在运行
StillRun = True
Else '外部程序运行结束
StillRun = False
End If
CloseHandle (HProgram)
End Function
我用这个程序调用一个EXE文件,但是最后不会生成输出文件,请问问题出在哪呀?
那个exe里有没有?
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Const SYNCHRONIZE = &H100000
Private Const INFINITE = &HFFFF下面是我调用ODBC的代码,参考
Private Function RunODBCDataSource() As Boolean
Dim lngProcID As Long
Dim lngHwnd As Long
Dim lngReturn As Long lngProcID = Shell("rundll32.exe shell32.dll,Control_RunDLL odbccp32.cpl", vbNormalFocus)
AppActivate lngProcID
' SendKeys "%d" 'alt+d, add ODBC
' SendKeys "i" 'i, move to informix,
' SendKeys "~" 'return key
'was going to focus on client and default its value to 819, cannot do it as error when empty database name
'in connection tab after given dummy data source name
If lngProcID <> 0 Then
lngHwnd = OpenProcess(SYNCHRONIZE, 0, lngProcID)
DoEvents
If lngHwnd <> 0 Then
lngReturn = WaitForSingleObject(lngHwnd, INFINITE)
CloseHandle lngHwnd
End If
RunODBCDataSource = True
Else
MsgBox "Unable to run " & ODBCADM & ".", vbCritical + vbOKOnly, "Error"
End If
End Function