get_struct_field
| Definition: |
include cffi.e atom v = get_struct_field(integer id, atom pStruct, atom_string field) -- or -- string s = get_struct_string(integer id, atom pStruct, string field, integer len) |
| Description: |
get a named field from some previously allocated structure, which (ie pStruct) is most likely to be the result of
an earlier call to allocate_struct().
id: a result from define_struct(). pStruct: a result from allocate_struct(). field: a string name or, caveat emptor, a numeric index (the latter mainly for the benefit of c-structs). |
| pwa/p2js: | Not supported. |
| Comments: |
The get_struct_string() routine should (only) be used when the field is TCHAR[] or similar. Note that it is your responsibility to pass in the right length,
since cffi.e cannot check that for you, and likewise trim trailing zeroes (or ’\0’) or spaces where needed. There may also be cases where some
unknown C code replaces say "some long message" with "error 7\0g message", again that’s your problem not mine. Under set_unicode(1), the retrieved widestring is converted to utf8 before being returned. Also, a TCHAR[128] should still get a len of 128 (characters/16-bit unicode points), even though it will actually allocate/occupy 256 bytes. Lastly, since such fields are not supported by c-structs the option to specify an integer field index has deliberately been removed. You may need to use say peek_[w]string() or even get_struct_field() itself again, on some atom results, eg an lpszText. |
| Example: |
include cffi.e constant idMBP = define_struct(...) atom pMBP = allocate_struct(idMBP) .. <set contents of pMBP> atom pTitle = get_struct_field(idMBP,pMBP,"lpszText") ?peek_string(pTitle) |
| See Also: | allocate_struct, set_struct_field, peek_string |