Expand/Shrink

cffi

Parse C struct and function definitions, and use them.

Note: Much of this functionality is now wrapped by c-struct, which you may find slightly easier to use, however that will not play nice with any embedded TCHAR[] or similar fields.

Eliminates most of the byte-counting needed when interfacing to C routines. The motivation behind this was that while I had many of the windows API structures laboriously translated to offsets for 32-bit from many years ago, they would all have otherwise needed re-doing for 64-bit.

I must stress that any savings are limited to converting C header (.h) files, or more accurately fragments copied verbatim from said, which would otherwise have to be done line-by-line manually. There is no new fancy slick syntax to help with the code that follows, or anything remotely like that. Although it knows the names, offsets and sizes of fields, that does not mean that you no longer have to fill them in! These routines are not intended to eliminate the basic understanding of how things need to be done, but there is less chance of being out-by-2 or whatever on the 4th field and therefore all the rest.

The library is deliberately written to crash on the first hiccup rather than return a meaningful error message, on the basis that there is not much point trying to continue if any of your structs or functions are wrong, and in the vast majority of cases they are all statically declared.

None of these routines are supported by pwa/p2js.

define_struct parse a C structure definition
allocate_struct allocate memory for a structure previously defined using define_struct().
set_struct_field set a named field in a structure previously allocated by allocate_struct().
get_struct_field get a named field from a structure previously allocated by allocate_struct().
get_field_details get the low level details of a named field in a structure previously defined by define_struct().
get_struct_size get the total size of a structure previously defined by define_struct().
set_unicode set flags controlling the unicode-related behaviour of the cffi library routines.
define_cffi_func parse a C function definition and obtain a routine id.
define_cffi_proc parse a C void function definition and obtain a routine id.