Return value from VB6 exe Main?

I get the impression that this is impossible, but here's what I have 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.

+4
source share
1 answer

A solution is possible here , using a call to the Win32 API. In fact:

 Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long) ' Exit with ErrorLevel set to 9 ExitProcess 9 

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

+8
source

All Articles