Powerbuilder

I have written a few routines which visitors are free to use as they want (However please do not publish on other websites - please link to this page). They are described below and can be downloaded from this page.

All routines were developed using Powerbuilder 5.0 and tested on Windows 95, 98 and NT version 4 operating systems. However, there should not be any problem calling these routines with later versions of Powerbuilder, other development environments and later versions of operating system.

Please contact me if you have any comments, questions or suggestions relating to these routines.

Run DLL Back to Top

This is a self-contained Windows DLL which contains a single function called Run which can be accessed from within a standard Powerbuilder application via either a local or global external function call. e.g.

Powerbuilder external function declaration:
FUNCTION long Run(string command, long winstate) &
LIBRARY "run.dll"

Instantiation:
Integer li_retval
li_retval = Run("notepad c:\autoexec.bat", 0) // 0 = Hidden

Purpose

Similar to Powerbuilder's own Run function, this function provides greater flexibility over the window state of the initiated program. Additional window states include Hidden, Shown but without being activated and Minimised but not activated. The definitive list of window states is shown below:

WindowState Parameter Window State
0 Hidden
1 Normal
2 Minimised
3 Maximised
4 Shown but not as active window
7 Shown Minimised but not as active window

Return Value

Returns 1 when the specified command has been initiated successfully. Returns -1 if it is unable to run the specified command.

Click here to download run.dll

RunWait DLL Back to Top

Similiar to the enhanced Run DLL described above, this DLL contains a single function called RunWait which, when called, waits until the specified command completes before passing back its return value. e.g.

Powerbuilder external function declaration:
FUNCTION long RunWait(string command, long winstate) &
LIBRARY "runwait.dll"

Instantiation:
Integer li_retval
li_retval = RunWait("c:\backup.bat", 1) // 1 = Normal

Return Value

Returns the return value from the specified command. Returns -1 if it is unable to run the specified command.

Click here to download runwait.dll

Notes Back to Top

If you get a "Bad runtime function reference" error at the point of calling either the Run or RunWait function, the most likley cause is that Powerbuilder has failed to locate the run.dll or runwait.dll file respectively.

Please ensure that the appropiate DLL file is located either in the same directory as your application, or in a directory mentioned in your PC's PATH environment variable.

Please contact me if you continue to experience difficulties.

Visitor comments
Posted by joevend, Fri 9 Jan 2009 5:51 pm
Updated External Function Declaration for PowerBuilder 11.5 and may also be required for PowerBuilder 10.0 & 11.0 users:

public function ulong RunWait (string command, long winstate) library "RunWait.dll" alias for "RunWait;ansi"

And as well, When using the call make sure you define your return variable as a ULong not a integer.
Only by using this declaration format was the RUNWAIT.DLL able to function for me under PowerBuilder 11.5

Thanks
Joseph Vendra
Posted by joevend, Fri 9 Jan 2009 5:54 pm
Alternative Solution:

RunWait hidden command execution can be achieved by using another method which does not require a dll but may not work as well. P.S. This was written by another developer im posting for sharing purposes only.

OleObject wsh

CONSTANT integer MAXIMIZED = 3
CONSTANT integer MINIMIZED = 2
CONSTANT integer NORMAL = 1
CONSTANT integer HIDE = 0
CONSTANT boolean WAIT = TRUE
CONSTANT boolean NOWAIT = FALSE

wsh = CREATE OleObject
li_rc = wsh.ConnectToNewObject( "WScript.Shell" )
li_rc = wsh.Run(LS_EXE_WGET_CMD ,HIDE, TRUE)
You need to log in/register to post a comment.