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:

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:

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.

NoteWindows 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. 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:

FUNCTION ulong FindWindowW(ulong classname, &
		string windowname) LIBRARY "User32.dll"
FUNCTION boolean CloseHandle(ulong w_handle) &
		LIBRARY "Kernel32.dll"

The following statement declares a function that draws a pie chart based on the coordinates received:

FUNCTION boolean Pie(ulong 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:

FUNCTION boolean IsZoomed(Ulong 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.