Datatypes for external function arguments
When you declare an external function in PowerBuilder, the
datatypes of the arguments must correspond with the datatypes as
declared in the function’s source definition. This section
documents the correspondence between datatypes in external functions
and datatypes in PowerBuilder. It also includes information on byte
alignment when passing structures by value.
Use the tables to find out what PowerBuilder datatype to use
in an external function declaration. The PowerBuilder datatype you
select depends on the datatype in the source code for the function. The first column lists
datatypes in source code. The second column describes the datatype
so you know exactly what it is. The third column lists the PowerBuilder
datatype you should use in the external function declaration.
Boolean
BOOL and Boolean on
Windows are 16-bit, signed. Both are declared in PowerBuilder as boolean.
Pointers
|
Datatype in source code |
Size, sign, precision |
PowerBuilder datatype |
|---|---|---|
|
* (any pointer) |
32-bit pointer |
Long |
|
char * |
Array of bytes of variable length |
Blob |
Windows 32-bit FAR pointers, such as LPBYTE, LPDWORD, LPINT, LPLONG, LPVOID,
and LPWORD, are declared in PowerBuilder as long datatypes. HANDLE is
defined as 32 bits unsigned and is declared in PowerBuilder as an UnsignedLong.
Near-pointer datatypes (such as PSTR and NPSTR)
are not supported in PowerBuilder.
Characters and strings
|
Datatype in source code |
Size, sign, precision |
PowerBuilder datatype |
|---|---|---|
|
char |
8 bits, signed |
Char |
|
string |
32-bit pointer to a null-terminated array |
String |
The Windows 32-bit FAR pointer LPSTR is
declared in PowerBuilder as string.
Reference arguments
When you pass a string to an external function by reference,
all memory management is done in PowerBuilder. The string variable
must be long enough to hold the returned value. To ensure that this
is true, first declare the string variable, and then use the Space
function to fill the variable with blanks equal to the maximum number
of characters that you expect the function to return.
Fixed-point values
|
Datatype in source code |
Size, sign, precision |
PowerBuilder datatype |
|---|---|---|
|
byte |
8 bits, unsigned |
Byte |
|
short |
16 bits, signed |
Integer |
|
unsigned short |
16 bits, unsigned |
UnsignedInteger |
|
int |
32 bits, signed |
Long |
|
unsigned int |
32 bits, unsigned |
UnsignedLong |
|
long |
32 bits, signed |
Long |
|
unsigned long |
32 bits, unsigned |
UnsignedLong |
|
longlong |
64 bits, signed |
LongLong |
The Windows definition WORD is declared
in PowerBuilder as UnsignedInteger and the
Windows definition DWORD is declared as an UnsignedLong.
You cannot call external functions with return values or arguments
of type short.
Floating-point values
|
Datatype in source code |
Size, sign, precision |
PowerBuilder datatype |
|---|---|---|
|
float |
32 bits, single precision |
Real |
|
double |
64 bits, double precision |
Double |
PowerBuilder does not support 80-bit doubles on
Windows.
Date and time
The PowerBuilder datatypes Date, DateTime,
and Time are structures and have no direct
equivalent for external functions in C.
Passing structures by value
You can pass PowerBuilder structures to external C functions
if they have the same definitions and alignment as the structure’s
components. The DLL or shared
library must be compiled using byte alignment; no padding is added
to align fields within the structure.