Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return value from VB6 exe Main?

I'm getting the impression this isn't possible, but here's what I've got so far.

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

I want it to look something like this:

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

The closest I've seen is Function Main() As Integer in Visual Studio 2005, but I'm using VB6.

like image 205
Joe M Avatar asked Jul 16 '12 20:07

Joe M


1 Answers

There's a possible solution here, by using a Win32 API call. In essense:

Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)

' Exit with ErrorLevel set to 9
ExitProcess 9

Note that this is the equivalent of End to the VB runtime so you must do any cleanup, closing of connections, files, devices, forms, etc before calling ExitProcess.

like image 94
Nick Shaw Avatar answered Nov 08 '22 04:11

Nick Shaw