Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Combining Array Attributes

Field attributes can be supplied in various combinations as long as the stub can use the information to determine the size of the array and the number of bytes to transmit to the server. The relationships between the attributes are defined using the following formulas:

size_is = max_is + 1;
length_is = last_is - first_is + 1;

The values associated with the attributes must obey several common-sense rules based on those formulas. These rules are:

  • Do not specify a [first_is] index value smaller than zero or a [last_is] value greater than [max_is].
  • Do not specify a negative size for an array. Define the first and last elements so that they result in a length value of zero or greater. Define the [max_is] value so that the size is zero or greater. If MIDL was invoked with the /error bounds_check option, then the stub raises an exception when the size is less than zero, or the transmitted length is less than zero.
  • Do not use the [length_is] and [last_is] attributes at the same time, nor the [size_is] and [last_is] attributes at the same time.

Because of the close relationship in C between arrays and pointers, MIDL also lets you declare arrays in parameter lists using pointer notation. MIDL treats a parameter that is a pointer to a type as an array of that type if the parameter has any of the attributes commonly associated with arrays.

/* IDL file */
[ 
  uuid(ba209999-0c6c-11d2-97cf-00c04f8eea45)
  version(6.0) 
]
interface arraytest
{
  void fArray6([in] short sSize, 
               [in, out, size_is(sSize)] char * p1);
  void fArray7([in] short sSize, 
               [in, out, size_is(sSize)] char achArray[]);
}

In the preceding example, the array and pointer parameters in the functions fArray6 and fArray7 are equivalent.

 

 

Community Additions

ADD
Show:
© 2015 Microsoft