请问VB程序中如何实现程序退出码?

welon 2003-11-29 02:19:04
VB程序中退出码(ExitCode)如何实现啊?
...全文
201 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
jacklee19822001 2003-12-01
  • 打赏
  • 举报
回复
一般0就可以了吧
reayi 2003-11-30
  • 打赏
  • 举报
回复
模块中声明:
Public Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long

窗体代码:
Private Sub Command1_Click()

' TerminateProcess -1, 1125 'also can
ExitProcess 1234

End Sub

测试程序:

模块声明:
Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, uExitCode As Long) As Long

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


Public Declare Function CloseHandle Lib "kernel32" (ByVal hProcess As Long) As Long

窗体代码:
Const PROCESS_QUERY_INFORMATION = &H400
Const PROCESS_TERMINATE = &H1
Dim ret As Long
Dim h As Long
Dim pid As Long

Private Sub Command1_Click()



If h Then
GetExitCodeProcess h, ret
MsgBox ret

Else
MsgBox "fail"
End If

End Sub



Private Sub Form_Load()
pid = 1448

h = OpenProcess(PROCESS_QUERY_INFORMATION + PROCESS_TERMINATE, 0, pid)
End Sub

Private Sub Form_Unload(Cancel As Integer)
If h Then CloseHandle h
End Sub


welon 2003-11-30
  • 打赏
  • 举报
回复
楼上的达人,给个具体代码吧????
rainstormmaster 2003-11-29
  • 打赏
  • 举报
回复
//楼上的,我指的是要在VB6里面实现,可不是C哦,看了怕怕

呵呵,vb的在上面我最初的回复里给了
welon 2003-11-29
  • 打赏
  • 举报
回复
楼上的,我指的是要在VB6里面实现,可不是C哦,看了怕怕
reayi 2003-11-29
  • 打赏
  • 举报
回复
VOID ExitProcess(

UINT uExitCode // exit code for all threads
);
rainstormmaster 2003-11-29
  • 打赏
  • 举报
回复
那就先shell,再OpenProcess,参考:
http://www.zjol.com.cn/vbbible/software/program/vb/ccw/htmapi77.htm
welon 2003-11-29
  • 打赏
  • 举报
回复
楼上的程序好像是取得某个程序的返回值吧,但我是想把我的程序返回一个值给调用它的程序或操作系统。
rainstormmaster 2003-11-29
  • 打赏
  • 举报
回复
用api函数:GetExitCodeProcess
声明:
Declare Function GetExitCodeProcess Lib "kernel32" Alias "GetExitCodeProcess" (ByVal hProcess As Long, lpExitCode As Long) As Long
返回值:
Long,非零表示成功,零表示失败。会设置GetLastError
参数:
hProcess ------- Long,想获取退出代码的一个进程的句柄
lpExitCode ----- Long,用于装载进程退出代码的一个长整数变量。如进程尚未中止,则设为常数STILL_ACTIVE

例程:

Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Sub Form_Load()
ExitProcess GetExitCodeProcess(GetCurrentProcess, 0)
End Sub
welon 2003-11-29
  • 打赏
  • 举报
回复
就是想C里面的exit(0),这括号里的值就是退出码吧,就是指向系统返回一个值,我想知道在VB里如何实现
hcj2002 2003-11-29
  • 打赏
  • 举报
回复
退出码(ExitCode)??

1,485

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧