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

Three Pointer Types

· 52CE 我爱测

MIDL supports three types of pointers to accommodate a wide range of applications.

MIDL supports three types of pointers to accommodate a wide range of applications. The three different levels are called reference, unique, and full pointers, and are indicated by the attributes [ref], [unique], and [ptr], respectively. The pointer classes described by these attributes are mutually exclusive. Pointer attributes can be applied to pointers in type definitions, function return types, function parameters, members of structures or unions, or array elements.

Embedded pointers are pointers that are members of structures or unions. They can also be elements of arrays. In the [in] direction, embedded [ref] pointers are assumed to be pointing to valid storage and must not be null. This situation is recursively applicable to any [ref] pointers they are pointing to. In the [in] direction, embedded [unique] and full pointers (pointers with the [ptr] attribute) may or may not be null.

Any pointer attribute placed on a parameter in the syntax of a function declaration affects only the rightmost pointer declarator for that parameter. To affect other pointer declarators, intermediate named types must be used.

Functions that return a pointer can have a pointer attribute as a function attribute. The [unique] and [ptr] attributes must be applied to function return types. Member declarations that are pointers can specify a pointer attribute as a field attribute. A pointer attribute can also be applied as a type attribute in typedef constructs.

When no pointer attribute is specified as a field or type attribute, pointer attributes are applied according to the rules for an unattributed pointer declaration as follows.

In DCE-compatibility mode, pointer attributes are determined in the defining IDL file. If there is a [pointer_default**]**attribute specified in the defining interface, that attribute is used. If no [pointer_default] attribute is present, all unattributed pointers are full pointers.

In Microsoft-extensions mode, pointer attributes can be determined by importing IDL files and are applied in the following order:

  1. An explicit pointer attribute applied at the use site.
  2. The [ref] attribute, when the unattributed pointer is a top-level pointer parameter.
  3. A [pointer_default] attribute specified in the defining interface.
  4. A [pointer_default] attribute specified in the base interface.
  5. The [unique] attribute.

The [pointer_default] interface attribute specifies the default pointer attributes to be applied to a pointer declarator in a type, parameter, or return type declaration when that declaration does not have an explicit pointer attribute applied to it. The [pointer_default] interface attribute does not apply to an unattributed top-level pointer of a parameter, which is assumed to be [ref].

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)

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

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