xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HB_SizeofCStructure()

Calculates the amount of memory required to store a C structure.

Syntax

HB_SizeofCStructure( <aTypes>, [<nAlign>] ) --> nBytes

Arguments

<aTypes>
The C-data types for each structure member must be specified as a one dimensional array of the same number of elements as there are structure members. #define constants must be used for <aTypes>. The following constants are available in the Cstruct.ch file:

Constants for C-data types
ConstantC-data type
CTYPE_CHARchar
CTYPE_UNSIGNED_CHARunsigned char
CTYPE_CHAR_PTRchar *
CTYPE_UNSIGNED_CHAR_PTRunsigned char*
CTYPE_SHORTshort
CTYPE_UNSIGNED_SHORTunsigned short
CTYPE_SHORT_PTRshort *
CTYPE_UNSIGNED_SHORT_PTRunsigned short *
CTYPE_INTint
CTYPE_UNSIGNED_INTunsigned int
CTYPE_INT_PTRint *
CTYPE_UNSIGNED_INT_PTRunsigned int *
CTYPE_LONGlong
CTYPE_UNSIGNED_LONGunsigned long
CTYPE_LONG_PTRlong *
CTYPE_UNSIGNED_LONG_PTRunsigned long *
CTYPE_FLOATfloat
CTYPE_FLOAT_PTRfloat *
CTYPE_DOUBLEdouble
CTYPE_DOUBLE_PTRdouble *
CTYPE_VOID_PTRvoid *
CTYPE_STRUCTUREstruct
CTYPE_STRUCTURE_PTRstruct *

<nAlign>
Optionally, the byte alignment for C-structure members can be specified. By default, the members are aligned at an eight byte boundary. Note that Windows API functions require a four byte alignment for structures.

Return

The function returns the memory requirement for a structure as a numeric value in bytes.

Description

Function HB_SizeOfCStructure() is used to calculate the size of a C structure in bytes. This depends on the number of bytes each C data type of structure members occupies in memory, and the byte alignment. The returned value is then used to create a character string like Replicate(Chr(0), nBytes). This character string can then be passed by reference to an API function via DllCall(). When DllCall() returns, the changed C structure string is decoded with function HB_StructureToArray().

An easier way of obtaining the size of a C structure is to declare a C structure class with typedef struct and call method :sizeOf() of a C structure object.

Info

See also:C Structure class, HB_ArrayToStructure(), HB_StructureToArray(), pragma pack()
Category: C Structure support , xHarbour extensions
Header:cstruct.ch
Source:vm\arrayshb.c
LIB:xhb.lib
DLL:xhbdll.dll


Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe