Definition: |
include cffi.e object x = define_struct(string struct_str, integer machine=machine_bits(), integer add=1) |
Description: | parse a C struct definition into sizes/offsets etc. |
Comments: |
The struct_str parameter is text copied from a C header file - note that without a "typedef", nothing gets stored permanantly. The machine parameter can be set to 32 or 64, for testing purposes. The add parameter is set to 0 for testing (override/ignore "typedef") If add is 1 and struct_str contains "typedef", the return value is a small integer id that can be used in calls to allocate_struct(), set_struct_field(), get_struct_field(), get_field_details() and get_struct_size(). Otherwise the full details of the structure are returned, which you can display, use to write a little help file, or perhaps even directly use the sizes and offsets etc. Typically this is only useful for testing/diagnostic purposes, see the dropdown below for more info. |
Example 1: |
include cffi.e constant tMBP=""" typedef struct { UINT cbSize; HWND hwndOwner; HINSTANCE hInstance; LPCTSTR lpszText; LPCTSTR lpszCaption; DWORD dwStyle; LPCTSTR lpszIcon; DWORD_PTR dwContextHelpId; MSGBOXCALLBACK lpfnMsgBoxCallback; DWORD dwLanguageId; } MSGBOXPARAMS, *PMSGBOXPARAMS; """ constant integer idMBP = define_struct(tMBP) |
Example 2: |
include cffi.e constant tRECT = """ typedef struct _RECT { LONG left; LONG top; LONG right; LONG bottom; } RECT, *PRECT;""", tPS = """ typedef struct tagPAINTSTRUCT { HDC hdc; BOOL fErase; RECT rcPaint; BOOL fRestore; BOOL fIncUpdate; BYTE rgbReserved[32]; } PAINTSTRUCT, *PPAINTSTRUCT;""", idRECT = define_struct(tRECT) idPS = define_struct(tPS) Structures can be nested - tPS can use "RECT", but only after tRECT has been processed. Note there is no "rcPaint", instead we have "rcPaint.left" etc. |
See Also: | allocate_struct, set_struct_field, get_struct_field, get_field_details, set_unicode |
