Platform SDK: TAPI |
Applications are responsible for allocating memory for this information; TAPI and the service provider simply fill in the data. If the operation is asynchronous, then the information is not available until the asynchronous reply message indicates success.
All data structures used to pass information between the application and the TAPI are flattened. This means that data structures do not contain pointers to substructures that contain variably sized components of information. Instead, data structures that are used to pass variable amounts of information back to the application have the following metastructure:
DWORD dwTotalSize; DWORD dwNeededSize; DWORD dwUsedSize; <fixed size fields> DWORD dw<VarSizeField1>Size; DWORD dw<VarSizeField1>Offset; <fixed size fields> DWORD dw<VarSizeField2>Size; DWORD dw<VarSizeField2>Offset; <common extensions> <var sized field1> <var sized field2>
The dwTotalSize member is the size, in bytes, allocated to this data structure. It marks the end of the data structure and is set by the application before it invokes the function that uses this data structure. The function does not read or write beyond this size. An application must set the dwTotalSize member to indicate the total number of bytes allocated for TAPI to return the contents of the structure.
TAPI fills in the dwNeededSize member. It indicates how many bytes are needed to return all the information requested. The existence of variably sized fields often makes it impossible for the application to estimate the data structure size it needs to allocate. This field simply returns the number of bytes actually needed for the information. This number could be smaller than, equal to, or larger than dwTotalSize, and it includes space for the dwTotalSize member itself. If larger, the returned structure is only partially filled. If the fields the application is interested in are available in the partial structure, nothing else must be done. Otherwise, the application should allocate a structure at least the size of dwNeededSize and invoke the function again. Usually, enough space is available this time to return all the information, although it is possible the size could have increased again.
TAPI fills in the dwUsedSize member if it returns information to the application to indicate the actual size in bytes of the portion of the data structure that contains useful information. If, for example, a structure that was allocated was too small and the truncated field is a variably sized field, dwNeededSize is larger than dwTotalSize, and the truncated field is left empty. The dwUsedSize member could therefore be smaller than dwTotalSize. Partial field values are not returned.
Following this header is the fixed part of the data structure. It contains regular fields and size/offset pairs that describe the actual variably sized fields. The offset field contains the offset in bytes of the variably sized field from the beginning of the record. The size field contains the size in bytes of the variably sized field. If a variably sized field is empty, then the size field is zero and the offset is set to zero. Variably sized fields that would be truncated if the total structure size is insufficient are left empty. That is, their size field is set to zero and the offset is set to zero. The variably sized fields follow the fixed fields.
If the service provider is responsible for filling in a variable member, TAPI initializes the corresponding size and offset members to zero. If the service provider fills in the variable member, it must set the corresponding size and offset members to appropriate values, including dwUsedSize and dwNeededSize if it sets variable members. The service provider must not truncate a variable member to make it fit into the available space.
The service provider must start variable members immediately after the fixed members of the structure, and leave any extra space at the end of the allocated memory so that TAPI can use it for the variable-length members for which it is responsible. It can place the variable members in any order, but the members must be contiguous.