Kbase P53214: How to read from and write to a C structure from Progress 4GL ?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  15/03/2011 |
|
Status: Verified
GOAL:
How to read from and write to a C structure from Progress 4GL ?
GOAL:
How to get data from a DLL procedure if it returns a STRUCT ?
GOAL:
How to pass a C STRUCT to an API call ?
FACT(s) (Environment):
Progress 9.1x
OpenEdge 10.x
All Supported Operating Systems
FIX:
In the Progress 4GL it's possible to use Shared Libraries (UNIX) or DLLs (Windows) directly.
However, a number of the routines contained in these external libraries passes C structures as parameters and there is currently nothing in the 4GL that maps to these structures directly. This does not mean these routines cannot be used, but it requires a more elaborate approach:
- In the external procedure definition in the 4GL procedure, define the parameter used to pass the structure as a MEMPTR.
- Based on the structure definition, calculate at which offset each element of the structure begins by determining the number of bytes each element uses. Note that a C STRUCT contains only the values, there's no additional overhead such as separators. The number of bytes an element uses will depend on the data type and/or array length.
- If you are receiving the C structure from the API, write the 4GL logic required to unmarshall the data from the MEMPTR by using the GET-<datatype>() functions to read the elements directly from the memory and store the values in 4GL variables and/or records.
- If you are sending the C structure to the API, write the 4GL logic required to marshall the data to the MEMPTR using the PUT-<datatype>() functions to place the data at the correct offset.
- As with any MEMPTR operations, take care to allocate and deallocate memory correctly using SET-SIZE(). Be careful not to interfere with memory that the API itself may allocate.