set_struct_field
Definition: |
include cffi.e set_struct_field(integer id, atom pStruct, atom_string field, v) |
Description: |
set a named field in a structure previously allocated by allocate_struct().
id: a result from define_struct(). pStruct: a result from allocate_struct(). field: a string name or, caveat emptor, a numeric index. v: the value to be set. |
pwa/p2js: | Not supported. |
Comments: |
The parameter v should be an atom except for TCHAR[128] and similar fields. You may need to use
allocate_[w]string(),
allocate_struct(), or allocate() to set lpsz and other
pointer members, and call free() once the memory is no longer needed.
Note that it is your responsibility to pass short-enough strings in v, since cffi.e cannot check that for you, and only when the target field is TCHAR[] or similar, and likewise add trailing zeroes (or ’\0’) or spaces where needed. Under set_unicode(1) a string in v is assumed to be utf8 and is converted to utf16. Additional steps may be required to ensure any surrogate pairs that introduces do not make it exceed the available space. |
Example: |
include cffi.e constant idMBP = define_struct(...) atom pMBP = allocate_struct(idMBP) .. atom pTitle = allocate_string("title") atom pCaption = allocate_string("caption") set_struct_field(idMBP,pMBP,"lpszText",pTitle) set_struct_field(idMBP,pMBP,"lpszCaption",pCaption) set_struct_field(idMBP,pMBP,"dwStyle",MB_OK) .. free(pCaption) free(pTitle) |
See Also: | allocate_struct, allocate_string, allocate, free |