Exiting a PowerBuilder application with ExitCode

There are two ways of getting the exit code from your PowerBuilder application. The first is declaring an external function, as the source below:

SUBROUTINE ExitProcess(ulong uExitCode) LIBRARY "kernel32.dll"

Now, just call the function, passing the desired exit code:

ExitProcess(42)

The second is to use the LongParm attribute of Message object in the Close event of the application:

//Application's Close event
Message.LongParm = 42

The exit code will be stored in the %ERRORLEVEL% variable.

To test it out:

$ start /w rn_demos.exe

$ echo %ERRORLEVEL%
42
The following two tabs change content below.
Software Architect and Backend Developer (almost Fullstack), I usually work with C#, PowerShell, Python, Golang, bash and Unity (this one is more for a hobby). I'm always looking for something new to learn, adding new tools to my utility belt.
Posted in PowerBuilder and tagged , , , , , .