我要在vb中调用外部的exe程序我用的是createprocess这个api:
dim siStartInfo as STARTUPINFO
dim piProcInfo as PROCESS_INFORMATION
createprocess(exefile,null,null,null,0,0,null,null,siStartInfo,piProcInfo)
但是编译不通过,说我的用户变量未定义。
dim siStartInfo as STARTUPINFO
dim piProcInfo as PROCESS_INFORMATION
createprocess(exefile,null,null,null,0,0,null,null,siStartInfo,piProcInfo)
但是编译不通过,说我的用户变量未定义。
SECURITY_ATTRIBUTES该为long
或exefile未定义
Private Sub Command1_Click()
Dim hProcess As Long
Dim TimeStart As Date Dim lppinfo As PROCESS_INFORMATION
Dim sinfo As Processes.STARTUPINFO
With Me.CommonDialog1
.Filter = "(Execute File)|*.exe"
.ShowOpen
If (.FileName <> "") Then
sinfo.cb = Len(sinfo)
sinfo.dwFlags = STARTF_USESHOWWINDOW
sinfo.wShowWindow = 1
TimeStart = Now
Debug.Print TimeStart
If (CreateProcessNullSECURITY(vbNullString, .FileName, 0, 0, False, NORMAL_PRIORITY_CLASS, 0, vbNullString, sinfo, lppinfo)) Then
hProcess = lppinfo.hProcess
WaitForSingleObject hProcess, INFINITE
Else
Debug.Print GetLastError
End If
Debug.Print DateDiff("s", TimeStart, Now)
End If End With
End Sub
标准模块
Public Declare Function CreateProcessNullSECURITY Lib "kernel32" Alias "CreateProcessA" _
(ByVal lpApplicationName As String, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As LongPublic Type PROCESS_INFORMATION
hProcess As Long
HThread As Long
dwProcessid As Long
dwThreadId As Long
End TypePublic Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End TypePublic Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type