大网数据广告活动
网络与域名解析

Combining Array Attributes

· 52CE 我爱测

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.

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.

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。