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

Multidimensional Arrays

· 52CE 我爱测

Array attributes can also be used with multidimensional arrays.

Array attributes can also be used with multidimensional arrays. However, be careful to ensure that every dimension of the array has a corresponding attribute. For example:

/* IDL file */
[ 
  uuid(ba209999-0c6c-11d2-97cf-00c04f8eea45),
  version(2.0)
]
interface multiarray
{
  void arr2d( [in] short        d1size,
              [in] short        d2len,
              [in, size_is( d1size, ), length_is ( , d2len) ] long array2d[*][30] ) ;
}

The preceding array is a conformant array (of size d1size ) of 30 element arrays (with d2len elements shipped for each). The comma in the parentheses of the [size_is] attribute specifies that value in d1size is applied to the first dimension of the array. Likewise, the command in the parentheses of the [length_is] attribute indicates that the value in d2len is applied to the second dimension of the array.

The MIDL 2.0 compiler provides two methods for marshaling parameters: mixed-mode (/Os) and fully-interpreted (/Oif or /Oicf). By default, the MIDL compiler compiles interfaces in mixed mode. You do not need to explicitly specify the /Os switch to get mixed-mode marshaling.

The fully-interpreted method marshals data completely offline. This reduces the size of the stub code considerably, but it also results in decreased performance. In mixed-mode marshaling, the stubs marshals some parameters online. While this results in a larger stub size, it also offers increased performance.

Caution:
Exercise caution when compiling IDL files in this mode. Using multidimensional arrays in mixed mode can result in parameters that are not marshaled correctly. The /Oicf command line switch is recommended when your interface defines parameters that are multidimensional arrays.

The [string] attribute can also be used with multidimensional arrays. The attribute applies to the least significant dimension, such as a conformant array of strings. You can also use multidimensional pointer attributes. For example:

/* IDL file */
[ 
  uuid(ba209999-0c6c-11d2-97cf-00c04f8eea45),
  version(2.0)
]
interface multiarray
{
  void arr2d([in] short  d1len,
             [in] short  d2len,
             [in] size_is(d1len, d2len) ] long  ** ptr2d) ;
}

In the preceding example, the variable ptr2d is a pointer to a d1len-sized block of pointers, each of which points to d2len pointers to long.

Multidimensional arrays are not equivalent to arrays of pointers. A multidimensional array is a single, large block of data in memory. An array of pointers only contains a block of pointers in the array. The data that the pointers point to can be anywhere in memory. Also, ANSI C syntax allows only the most significant (leftmost) array dimension to be unspecified in a multidimensional array. Therefore, the following is a valid statement:

long a1[] [20]

Compare this to the following invalid statement:

long a1[20] []

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)

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

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