Sample declarations
Suppose you have created a C dynamic library, SIMPLE.DLL,
that contains a function called SimpleFunc that
accepts two parameters: a character string and a structure. The
following statement declares the function in PowerBuilder, passing
the arguments by reference:
1 |
FUNCTION int SimpleFunc(REF string lastname, & <br>   REF my_str pbstr) LIBRARY "simple.dll" |
By default, PowerBuilder handles string arguments and return
values as if they have Unicode encoding. If SimpleFunc passes ANSI
strings as arguments, you must use this syntax to declare it:
1 |
FUNCTION int SimpleFunc(REF string lastname, & <br>   REF my_str pbstr) LIBRARY "simple.dll" &<br>   ALIAS FOR "SimpleFunc;ansi" |
Declaring Windows API functions
The Windows API includes over a thousand functions that you
can call from PowerBuilder. The following examples show sample declarations
for functions in the 32-bit Windows API libraries KERNEL32.DLL, GDI32.DLL,
and USER32.DLL.
Some 32-bit function names end with A (for ANSI) or W (for
wide). Use wide function names in PowerBuilder.
For a complete list of Windows API functions,
see the Microsoft Windows SDK documentation. For examples of PowerBuilder
declaration syntax and scripts, search for Windows API calls in
the Technical Documents section of the Sybase Web site
.
The following statements declare a function that gets the
handle of any window that is called by name, and a function that
releases the open object handle:
1 |
FUNCTION ulong FindWindowW(ulong classname, & |
1 |
string windowname) LIBRARY "User32.dll" |
1 |
FUNCTION boolean CloseHandle(ulong w_handle) & |
1 |
LIBRARY "Kernel32.dll" |
The following statement declares a function that draws a pie
chart based on the coordinates received:
1 |
FUNCTION boolean Pie(ulong hwnd,long x1,long y1, & |
1 |
long x2,long y2,long x3,long y3,long x4, & |
1 |
long y4) LIBRARY "Gdi32.dll" |
The following statement declares an external C function named IsZoomed:
1 |
FUNCTION boolean IsZoomed(Ulong handle) & |
1 |
LIBRARY "User32.DLL" |
A script that uses IsZoomed is included
as an example in “Using utility functions
to manage information”.
For more information about these functions,
see the Microsoft documentation in the MSDN Library
.