主题:调用EXE文件无法输出文
zhijinanqiu
[专家分:0] 发布于 2009-12-10 22:45:00
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 Long
Option 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 Sub
Public 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文件,但是最后不会生成输出文件,请问问题出在哪呀?
最后更新于:2009-12-11 14:46:00
回复列表 (共15个回复)
沙发
zhijinanqiu [专家分:0] 发布于 2009-12-11 11:16:00
大家帮忙解决一下吧!
板凳
tanchuhan [专家分:15140] 发布于 2009-12-11 12:30:00
你的"输出文件"是什么意思?
3 楼
zhijinanqiu [专家分:0] 发布于 2009-12-11 12:53:00
[quote]你的"输出文件"是什么意思?[/quote]
我可能没说清楚,就是我的exe文件只要双击就会自动在所在文件夹里产生一些输出文件,所以在我调用这个exe的时候本应该产生这些文件,但是结果是没有任何产生!
4 楼
tanchuhan [专家分:15140] 发布于 2009-12-11 13:04:00
[quote][quote]你的"输出文件"是什么意思?[/quote]
我可能没说清楚,就是我的exe文件只要双击就会自动在所在文件夹里产生一些输出文件,所以在我调用这个exe的时候本应该产生这些文件,但是结果是没有任何产生!
[/quote]
上传你的EXE,我试试.
5 楼
zhijinanqiu [专家分:0] 发布于 2009-12-11 13:07:00
[quote][quote][quote]你的"输出文件"是什么意思?[/quote]
我可能没说清楚,就是我的exe文件只要双击就会自动在所在文件夹里产生一些输出文件,所以在我调用这个exe的时候本应该产生这些文件,但是结果是没有任何产生!
[/quote]
上传你的EXE,我试试.[/quote]
我没有找到上传附件的地方[em15][em15]
6 楼
tanchuhan [专家分:15140] 发布于 2009-12-11 13:27:00
编辑你的主帖,里面有个上传功能的.
8 楼
tanchuhan [专家分:15140] 发布于 2009-12-11 15:30:00
[code=c]
Private Const PROCESS_QUERY_INFORMATION As Long = &H400
Private Const STATUS_PENDING As Long = &H103
Private Const STILL_ACTIVE As Long = STATUS_PENDING
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32.dll" (ByVal hProcess As Long, ByRef lpExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Function ShellEx(ByVal sFilePath As String, Optional ByVal wsWindowStyle As VbAppWinStyle = vbNormalFocus) As Long
Dim sDriver As String, sDir As String
sDriver = Left(sFilePath, 3)
sDir = Left(sFilePath, InStrRev(sFilePath, "\") - 1)
ChDrive sDriver '切换当前驱动器(盘)
ChDir sDir '切换当前目录
ShellEx = Shell(sFilePath, wsWindowStyle)
End Function
Private Sub RunProgramWaitExit(ByVal sFilePath As String)
Dim nExitCode As Long
Dim pid As Long, hProcess As Long
pid = ShellEx(sFilePath)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid)
nExitCode = STILL_ACTIVE
Do While nExitCode = STILL_ACTIVE
Call GetExitCodeProcess(hProcess, nExitCode)
DoEvents
Loop
Call CloseHandle(hProcess)
End Sub
Private Sub Command1_Click()
RunProgramWaitExit "C:\Users\Tam\Desktop\Console2\Debug\Console1.exe"
End Sub
[/code]
9 楼
zhijinanqiu [专家分:0] 发布于 2009-12-11 16:17:00
能用了,谢谢哦!
10 楼
zhijinanqiu [专家分:0] 发布于 2009-12-11 19:22:00
[quote]编辑你的主帖,里面有个上传功能的.[/quote]
再问问呀,我的EXE文件是FORTRAN产生的,我最后需要把这个EXE和VB一块打包,做一个应用程序出来,那么这个EXE文件的地址我应该怎么处理呢?
我来回复