You can specify the valid bounds of the array using the max_is attribute.
/* IDL file */
[ uuid(20B309B1-015C-101A-B308-02608C4C9B53),
version(5.0)
]
interface arraytest
{
void fArray5([in] short sMax,
[in, out, max_is(sMax)] char achArray[]);
}
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 are:
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(20B309B1-015C-101A-B308-02608C4C9B53)
version(6.0)
]
interface arraytest
{
void fArray6([in, out, size_is(sSize)] char * p1,
[in] short sSize);
void fArray7([in, out, size_is(sSize)] char achArray[],
[in] short sSize);
}
In the preceding example, the array and pointer parameters in the functions fArray6 and fArray7 are equivalent.