Exiting a PowerBuilder application with ExitCode

Exiting a PowerBuilder application with ExitCode

Overview

Welcome to the world of PowerBuilder, where simplicity meets efficiency! Today, we’re diving into a handy guide on manipulating exit codes within your applications. Whether you’re seasoned in the realm of development or a curious newcomer, this post promises a straightforward journey through utilizing external functions and the ingenious LongParm attribute. So, let’s roll up our sleeves and decode the secrets to customizing your application’s exit process with a sprinkle of coding magic and a touch of practicality.

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:

<pre class="theme:shell-default lang:default decode:true">$ start /w rn_demos.exe

$ echo %ERRORLEVEL%
42