xHarbour Reference Documentation > Function Reference |
Converts an array to a binary C structure.
HB_ArrayToStructure( <aMembers>, ; <aTypes> , ; [<nAlign>] ) --> cBinaryStructure
Constants for C-data types
Constant | C-data type |
---|---|
CTYPE_CHAR | char |
CTYPE_UNSIGNED_CHAR | unsigned char |
CTYPE_CHAR_PTR | char * |
CTYPE_UNSIGNED_CHAR_PTR | unsigned char* |
CTYPE_SHORT | short |
CTYPE_UNSIGNED_SHORT | unsigned short |
CTYPE_SHORT_PTR | short * |
CTYPE_UNSIGNED_SHORT_PTR | unsigned short * |
CTYPE_INT | int |
CTYPE_UNSIGNED_INT | unsigned int |
CTYPE_INT_PTR | int * |
CTYPE_UNSIGNED_INT_PTR | unsigned int * |
CTYPE_LONG | long |
CTYPE_UNSIGNED_LONG | unsigned long |
CTYPE_LONG_PTR | long * |
CTYPE_UNSIGNED_LONG_PTR | unsigned long * |
CTYPE_FLOAT | float |
CTYPE_FLOAT_PTR | float * |
CTYPE_DOUBLE | double |
CTYPE_DOUBLE_PTR | double * |
CTYPE_VOID_PTR | void * |
CTYPE_STRUCTURE | struct |
CTYPE_STRUCTURE_PTR | struct * |
The function returns a character string holding the values of structure members in binary form.
Function HB_ArrayToStructure() converts an array into a binary string representation of a C structure. The returned string contains the values of structure members in binary form and can be passed to external API functions via DllCall(). If the structure is an "out" parameter of the API function, it must be passed by reference and can be converted back to an array using HB_StructureToArray().
HB_ArrayToStructure() is appropriate for simple structures. It is recommended to declare a structure class using typedef struct when a structure is complex, e.g. when it is a nested structure.
See also: | C Structure class, HB_StructureToArray(), pragma pack(), (struct), typedef struct |
Category: | C Structure support , xHarbour extensions |
Header: | cstruct.ch |
Source: | vm\arrayshb.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example simulates the POINT structure which has only two members. // An array of two elements represents a point with an x and y coordinate. // The array is converted to a binary structure of 8 bytes. #include "Cstruct.ch" PROCEDURE Main LOCAL aMember := { 100, 200 } LOCAL aTypes := { CTYPE_LONG, CTYPE_LONG } LOCAL nAlign := 4 LOCAL cBinary cBinary := HB_ArrayToStructure( aMember, aTypes, nAlign ) ? Len( cBinary ) // result: 8 ? Bin2L( Left( cBinary, 4 ) ) // result: 100 ? Bin2L( Right( cBinary, 4 ) ) // result: 200 RETURN
http://www.xHarbour.com