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 2 |
FUNCTION int SimpleFunc(REF string lastname, & 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 2 3 |
FUNCTION int SimpleFunc(REF string lastname, & REF my_str pbstr) LIBRARY "simple.dll" & 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.
Windows API calls
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.
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 2 3 4 |
FUNCTION longptr FindWindowW(ulong classname, & string windowname) LIBRARY "User32.dll" FUNCTION boolean CloseHandle(longptr w_handle) & LIBRARY "Kernel32.dll" |
The following statement declares a function that draws a pie chart
based on the coordinates received:
|
1 2 3 |
FUNCTION boolean Pie(longptr hwnd,long x1,long y1, & long x2,long y2,long x3,long y3,long x4, & long y4) LIBRARY "Gdi32.dll" |
The following statement declares an external C function named
IsZoomed:
|
1 2 |
FUNCTION boolean IsZoomed(longptr handle) & 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 at http://msdn.microsoft.com/en-us/library/ms674884(VS.85).aspx.