Joe*_*e M 4 vb6 program-entry-point
我得到的印象是这是不可能的,但这是我到目前为止所得到的.
Sub Main()
On Error GoTo ErrorHandler
If Command$ = "" Then
LogAction "Begin document lockdown"
LockdownDocs
LogAction "Lockdown complete"
Else
LogAction "Begin document enabling"
EnableDocs
LogAction "Documents have be enabled"
End If
Exit Sub
ErrorHandler:
LogAction "DocLock Error " & Err.Number & "::" & Err.Description
End Sub
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像这样:
Function Main() As Boolean
On Error GoTo ErrorHandler
If Command$ = "" Then
LogAction "Begin document lockdown"
LockdownDocs
LogAction "Lockdown complete"
Else
LogAction "Begin document enabling"
EnableDocs
LogAction "Documents have be enabled"
End If
Return True
Exit Function
ErrorHandler:
LogAction "Error " & Err.Number & "::" & Err.Description
Return False
End Function
Run Code Online (Sandbox Code Playgroud)
我见过的最接近的是Function Main() As IntegerVisual Studio 2005,但我使用的是VB6.
有一个可能的解决方案在这里,通过使用Win32 API调用.在本质上:
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
' Exit with ErrorLevel set to 9
ExitProcess 9
Run Code Online (Sandbox Code Playgroud)
请注意,这相当于EndVB运行时,因此您必须在调用之前进行任何清理,关闭连接,文件,设备,表单等ExitProcess.